当前位置: 首页>>代码示例>>Java>>正文


Java WebAttributes类代码示例

本文整理汇总了Java中org.springframework.security.web.WebAttributes的典型用法代码示例。如果您正苦于以下问题:Java WebAttributes类的具体用法?Java WebAttributes怎么用?Java WebAttributes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


WebAttributes类属于org.springframework.security.web包,在下文中一共展示了WebAttributes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onAuthenticationFailure

import org.springframework.security.web.WebAttributes; //导入依赖的package包/类
@Override
public void onAuthenticationFailure(final HttpServletRequest request,
                                    final HttpServletResponse response, final AuthenticationException exception)
        throws IOException, ServletException {

    setDefaultFailureUrl("/signin?error");
    super.onAuthenticationFailure(request, response, exception);

    String errorMessage = webUI.getMessage(GENERIC_AUTHENTICATION_ERROR_KEY);

    User user = userService.getUserByUsername(request.getParameter(USERNAME));
    if (user != null) {

        String notYetApprovedMessage = webUI.getMessage(NOT_YET_USER_VERIFIED_ERROR_KEY,
                user.getUsername(), user.getEmail());

        if (exception.getMessage().equalsIgnoreCase((USER_IS_DISABLED))) {
            if (user.getUserData().getApprovedDatetime() == null) errorMessage = notYetApprovedMessage;
        }
    }
    request.getSession().setAttribute(WebAttributes.AUTHENTICATION_EXCEPTION, errorMessage);
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:23,代码来源:CustomAuthenticationFailureHandler.java

示例2: onAuthenticationFailure

import org.springframework.security.web.WebAttributes; //导入依赖的package包/类
/**
 * Configures custom messages upon Spring Security authentication errors.
 *
 *  @author Ant Kaynak - Github/Exercon
 * */

@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
    setDefaultFailureUrl("/login?error");
    super.onAuthenticationFailure(request, response, exception);
    String errorMessage = "Invalid username and/or password!";

    if (exception.getMessage().equalsIgnoreCase("User is disabled")) {
        errorMessage = "User account is disabled! Check user e-mail to activate the account.";
    } else if (exception.getMessage().equalsIgnoreCase("User account has expired")) {
        errorMessage = "User account has expired. Please contact our support team.";
    }else if (exception.getMessage().equalsIgnoreCase("User account is locked")){
        errorMessage = "User account is banned. Please contact our support team.";
    }
    request.getSession().setAttribute(WebAttributes.AUTHENTICATION_EXCEPTION, errorMessage);
}
 
开发者ID:Exercon,项目名称:AntiSocial-Platform,代码行数:22,代码来源:CustomAuthenticationFailureHandler.java

示例3: onConfigure

import org.springframework.security.web.WebAttributes; //导入依赖的package包/类
@Override
protected void onConfigure() {
    super.onConfigure();

    ServletWebRequest req = (ServletWebRequest) RequestCycle.get().getRequest();
    HttpServletRequest httpReq = req.getContainerRequest();
    HttpSession httpSession = httpReq.getSession();

    Exception ex = (Exception) httpSession.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
    if (ex == null) {
        return;
    }

    String key = ex.getMessage() != null ? ex.getMessage() : "web.security.provider.unavailable";
    error(getString(key));

    httpSession.removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);

    clearBreadcrumbs();
}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:21,代码来源:PageLogin.java

示例4: onAuthenticationFailure

import org.springframework.security.web.WebAttributes; //导入依赖的package包/类
@Override
public void onAuthenticationFailure(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException exception) throws IOException, ServletException {
    setDefaultFailureUrl("/login?error=true");

    super.onAuthenticationFailure(request, response, exception);

    final Locale locale = localeResolver.resolveLocale(request);

    String errorMessage = messages.getMessage("message.badCredentials", null, locale);

    if (exception.getMessage().equalsIgnoreCase("User is disabled")) {
        errorMessage = messages.getMessage("auth.message.disabled", null, locale);
    } else if (exception.getMessage().equalsIgnoreCase("User account has expired")) {
        errorMessage = messages.getMessage("auth.message.expired", null, locale);
    } else if (exception.getMessage().equalsIgnoreCase("blocked")) {
        errorMessage = messages.getMessage("auth.message.blocked", null, locale);
    }

    request.getSession().setAttribute(WebAttributes.AUTHENTICATION_EXCEPTION, errorMessage);
}
 
开发者ID:Baeldung,项目名称:spring-security-registration,代码行数:21,代码来源:CustomAuthenticationFailureHandler.java

示例5: commence

import org.springframework.security.web.WebAttributes; //导入依赖的package包/类
/**
 * {@inheritDoc} Send an SC_UNATHORIZED Error if the request has been send by AJAX
 */
@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {
    HttpServletRequest httpRequest = request;
    HttpServletResponse httpResponse = response;

    if (isAjaxRequest(httpRequest)) {
        // if its an ajax request do not forward to entry point, send 401 and remove saved
        // request for further processing
        httpRequest.getSession().removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
        httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);

        SessionHandler.instance().resetOverriddenCurrentUserLocale(httpRequest);
    } else {
        super.commence(request, response, authException);
    }
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:21,代码来源:CommunoteAuthenticationProcessingFilterEntryPoint.java

示例6: handleLoginFailed

import org.springframework.security.web.WebAttributes; //导入依赖的package包/类
@RequestMapping(method = RequestMethod.GET, value = SecurityActionsUrlsProviderDefaultImpl.LOGIN_FAILED)
public String handleLoginFailed(Model model, HttpServletRequest request) {
	Exception lastException = (Exception) request.getSession().getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
	if (lastException != null) {
		log.info("Login failed due to exception", lastException);
		model.addAttribute("lastExceptionMessage", exceptionTranslatorSimplified.buildUserMessage(lastException));
		// Delete it from session to avoid excessive memory consumption
		request.getSession().removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
	}

	model.addAttribute("loginError", true);

	// Add validation errors
	FieldValidationException validationErrors = ExceptionUtils.findExceptionOfType(lastException,
			FieldValidationException.class);
	if (validationErrors != null) {
		for (ValidationError error : validationErrors.getErrors()) {
			model.addAttribute("ve_" + error.getFieldToken(), msg(error.getMessageCode(), error.getMessageArgs()));
		}
	}

	// add login failed message
	return getLoginForm(model);
}
 
开发者ID:skarpushin,项目名称:summerb,代码行数:25,代码来源:LoginController.java

示例7: onConfigure

import org.springframework.security.web.WebAttributes; //导入依赖的package包/类
@Override
protected void onConfigure() {
    super.onConfigure();

    ServletWebRequest req = (ServletWebRequest) RequestCycle.get().getRequest();
    HttpServletRequest httpReq = req.getContainerRequest();
    HttpSession httpSession = httpReq.getSession();

    Exception ex = (Exception) httpSession.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
    if (ex == null) {
        return;
    }

    String msg = ex.getMessage();
    if (StringUtils.isEmpty(msg)) {
        msg = "web.security.provider.unavailable";
    }

    msg = getLocalizationService().translate(msg, null, getLocale(), msg);
    error(msg);

    httpSession.removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);

    clearBreadcrumbs();
}
 
开发者ID:Evolveum,项目名称:midpoint,代码行数:26,代码来源:PageLogin.java

示例8: login

import org.springframework.security.web.WebAttributes; //导入依赖的package包/类
@RequestMapping(value = "/login", method = RequestMethod.GET)
    public ModelAndView login(
            @RequestParam(value = "logout", required = false, defaultValue = "false") String logout,
            @RequestParam(value = "registered", required = false, defaultValue = "false") String registered,
            HttpServletRequest request
    ) {
//       In our simple case i decided to use standard parameters AuthenticationFailureHandler
//       but we can create our handler

        ModelAndView model = new ModelAndView("login");

        HttpSession session = request.getSession(false);

        if (session != null && session.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION) != null) {
            logger.error(session.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION).toString());
            model.addObject("error", ((AuthenticationException) session.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION)).getMessage());
        }
        if (registered != null && registered.equals("true")) {
            model.addObject("registered", "You`ve been successfully registered. Please activate your account.");
        }
        if (logout != null && logout.equals("true")) {
            model.addObject("logout", "You've been logged out successfully.");
        }
        return model;
    }
 
开发者ID:shivam091,项目名称:Spring-Security-Thymeleaf-Integration,代码行数:26,代码来源:UserController.java

示例9: onAuthenticationSuccess

import org.springframework.security.web.WebAttributes; //导入依赖的package包/类
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {

 	SavedRequest savedRequest = 
 		    new HttpSessionRequestCache().getRequest(request, response);
 	
    if (savedRequest == null) {
          return;
     }
    HttpSession session = request.getSession();
    session.removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);

     
     // Use the DefaultSavedRequest URL
     String targetUrl = savedRequest.getRedirectUrl();
     logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl);
     response.sendRedirect(targetUrl);
 }
 
开发者ID:eteration,项目名称:glassmaker,代码行数:18,代码来源:OAuth2AuthenticationFilter.java

示例10: onInitialize

import org.springframework.security.web.WebAttributes; //导入依赖的package包/类
@Override
protected void onInitialize() {
	super.onInitialize();
	
	// Vérification des retours d'auth pac4J
	HttpServletRequest request = ((ServletWebRequest) RequestCycle.get().getRequest()).getContainerRequest();
	Exception exception = (Exception) request.getSession().getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
	if (exception != null) {
		if (exception instanceof DisabledException) {
			getSession().error(getString("home.identification.classic.error.userDisabled"));
		} else if (exception instanceof AuthenticationServiceException) {
			LOGGER.error("Authentication failed", exception);
			getSession().error(getString("home.identification.error.badCredentials") + exception.getMessage());
		} else {
			LOGGER.error("An unknown error occurred during the authentication process", exception);
			getSession().error(getString("home.identification.error.unknown"));
		}
		request.getSession().removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
	}
}
 
开发者ID:openwide-java,项目名称:artifact-listener,代码行数:21,代码来源:IdentificationPopoverPanel.java

示例11: clearAuthenticationAttributes

import org.springframework.security.web.WebAttributes; //导入依赖的package包/类
private void clearAuthenticationAttributes(HttpServletRequest request) {
    HttpSession session = request.getSession(false);
    if (session == null) {
        return;
    }
    session.removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
}
 
开发者ID:Recks11,项目名称:theLXGweb,代码行数:8,代码来源:UrlAuthenticationSuccessHandler.java

示例12: getLoginErrorForm

import org.springframework.security.web.WebAttributes; //导入依赖的package包/类
@GetMapping(params = ERROR_PARAMETER_NAME)
public String getLoginErrorForm(WebRequest request, Model model) {
	AuthenticationException error = (AuthenticationException) request
			.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION, RequestAttributes.SCOPE_SESSION);
	model.addAttribute(ERROR_PARAMETER_NAME, error != null ? error.getMessage() : DEFAULT_ERROR_MESSAGE);

	return getLoginForm(request, model);
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:9,代码来源:LoginFormController.java

示例13: onAuthenticationFailure

import org.springframework.security.web.WebAttributes; //导入依赖的package包/类
@Override
public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
    AuthenticationException ae = (AuthenticationException) httpServletRequest.getSession().getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
    if(ae==null){
        HttpHelper.setResponseJsonData(httpServletResponse, JSON.toJSONString( JsonUtil.getFailJsonObject()));
    }else{
        HttpHelper.setResponseJsonData(httpServletResponse, JSON.toJSONString( JsonUtil.getFailJsonObject(ae.getMessage())));
    }

}
 
开发者ID:fier-liu,项目名称:FCat,代码行数:11,代码来源:CustomAuthenticationFailureHandler.java

示例14: clearAuthenticationAttributes

import org.springframework.security.web.WebAttributes; //导入依赖的package包/类
/**
 * Removes temporary authentication-related data which may have been stored
 * in the session during the authentication process..
 * 
 */
protected final void clearAuthenticationAttributes(HttpServletRequest request) {
    HttpSession session = request.getSession(false);

    if (session == null) {
        return;
    }

    session.removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
}
 
开发者ID:Apereo-Learning-Analytics-Initiative,项目名称:OpenLRW,代码行数:15,代码来源:AjaxAwareAuthenticationSuccessHandler.java

示例15: clearAuthenticationAttributes

import org.springframework.security.web.WebAttributes; //导入依赖的package包/类
protected void clearAuthenticationAttributes(HttpServletRequest request) {
	HttpSession session = request.getSession(false);

	if (session == null) {
		return;
	}

	session.removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
}
 
开发者ID:edylle,项目名称:pathological-reports,代码行数:10,代码来源:CustomAuthenticationSuccessHandler.java


注:本文中的org.springframework.security.web.WebAttributes类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。