當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。