org.springframework.security.web.authentication.AuthenticationFailureHandler Java Examples

The following examples show how to use org.springframework.security.web.authentication.AuthenticationFailureHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueryFilter.java    From api-layer with Eclipse Public License 2.0 6 votes vote down vote up
public QueryFilter(
    String authEndpoint,
    AuthenticationSuccessHandler successHandler,
    AuthenticationFailureHandler failureHandler,
    AuthenticationService authenticationService,
    HttpMethod httpMethod,
    boolean protectedByCertificate,
    AuthenticationManager authenticationManager) {
    super(authEndpoint);
    this.successHandler = successHandler;
    this.failureHandler = failureHandler;
    this.authenticationService = authenticationService;
    this.httpMethod = httpMethod;
    this.protectedByCertificate = protectedByCertificate;
    this.setAuthenticationManager(authenticationManager);
}
 
Example #2
Source File: WebSecurityConfig.java    From spring-security with Apache License 2.0 6 votes vote down vote up
@Bean
public AuthenticationFailureHandler authenticationFailureHandler(){
    return new AuthenticationFailureHandler() {
        /**
         * 处理登录失败的请求
         * @param httpServletRequest
         * @param httpServletResponse
         * @param e
         * @throws IOException
         * @throws ServletException
         */
        @Override
        public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
            httpServletResponse.setContentType("application/json;charset=utf-8");
            PrintWriter out = httpServletResponse.getWriter();
            out.write("{\"status\":\"error\",\"msg\":\"登录失败\"}");
            out.flush();
            out.close();
        }
    };
}
 
Example #3
Source File: WebSecurityConfig.java    From spring-security with Apache License 2.0 6 votes vote down vote up
@Bean
public AuthenticationFailureHandler authenticationFailureHandler(){
    return new AuthenticationFailureHandler() {
        /**
         * 处理登录失败的请求
         * @param httpServletRequest
         * @param httpServletResponse
         * @param e
         * @throws IOException
         * @throws ServletException
         */
        @Override
        public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
            httpServletResponse.setContentType("application/json;charset=utf-8");
            PrintWriter out = httpServletResponse.getWriter();
            out.write("{\"status\":\"error\",\"msg\":\"登录失败\"}");
            out.flush();
            out.close();
        }
    };
}
 
Example #4
Source File: WebSecurityConfiguration.java    From cola with MIT License 6 votes vote down vote up
@Bean
public SmsLoginConfigurer smsLoginConfigurer(SmsCredentialProperties properties) {

	AuthenticationFailureHandler failureHandler = new ForwardAuthenticationFailureHandler(properties.getLoginFailureUrl());

	SmsLoginConfigurer<HttpSecurity> configurer = new SmsLoginConfigurer<>();
	configurer.successHandler(this.successHandler())
			.failureHandler(failureHandler)
			.eventPublisher(applicationEventPublisher)
			.permitAll();

	//拦截登录验证码
	captchaAuthenticationFilter.addRequestMatcher(new AntPathRequestMatcher(properties.getLoginProcessUrl(), HttpMethod.POST.name()), failureHandler);

	return configurer;
}
 
Example #5
Source File: WebSecurityConfig.java    From spring-security with Apache License 2.0 6 votes vote down vote up
@Bean
public AuthenticationFailureHandler authenticationFailureHandler(){
    return new AuthenticationFailureHandler() {
        /**
         * 处理登录失败的请求
         * @param httpServletRequest
         * @param httpServletResponse
         * @param e
         * @throws IOException
         * @throws ServletException
         */
        @Override
        public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
            httpServletResponse.setContentType("application/json;charset=utf-8");
            PrintWriter out = httpServletResponse.getWriter();
            out.write("{\"status\":\"error\",\"msg\":\"登录失败\"}");
            out.flush();
            out.close();
        }
    };
}
 
Example #6
Source File: CaptchaAuthenticationFilter.java    From cola with MIT License 6 votes vote down vote up
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
	HttpServletRequest request = (HttpServletRequest) req;
	HttpServletResponse response = (HttpServletResponse) res;

	AuthenticationFailureHandler authenticationFailureHandler = requiresAuthentication(request, response);
	if (authenticationFailureHandler == null) {
		chain.doFilter(request, response);
		return;
	}

	Object captcha = request.getSession().getAttribute(LOGIN_CAPTCHA_SESSION_KEY);

	if (captcha == null) {
		chain.doFilter(request, response);
	} else {
		if (!String.valueOf(captcha).equalsIgnoreCase(request.getParameter(LOGIN_CAPTCHA_PARAM_NAME))) {
			authenticationFailureHandler.onAuthenticationFailure(request, response, new InsufficientAuthenticationException("验证码错误"));
		} else {
			chain.doFilter(request, response);
		}
	}
}
 
Example #7
Source File: RefreshTokenProcessingFilter.java    From iotplatform with Apache License 2.0 5 votes vote down vote up
public RefreshTokenProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler,
    AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
  super(defaultProcessUrl);
  this.successHandler = successHandler;
  this.failureHandler = failureHandler;
  this.objectMapper = mapper;
}
 
Example #8
Source File: CrowdSecurityConfiguration.java    From ods-provisioning-app with Apache License 2.0 5 votes vote down vote up
/**
 * define an failure handler in case of an authentication failure
 *
 * @return
 */
@Bean
public AuthenticationFailureHandler authenticationFailureHandler() {
  UsernameStoringAuthenticationFailureHandler failureHandler =
      new UsernameStoringAuthenticationFailureHandler();
  failureHandler.setDefaultFailureUrl("/login?error=true");
  failureHandler.setUseForward(true);
  return failureHandler;
}
 
Example #9
Source File: WechatAuthenticationConfigurer.java    From fast-family-master with Apache License 2.0 5 votes vote down vote up
public WechatAuthenticationConfigurer(WxMpService wxMpService, UserDetailsService userDetailsService,
                                      AuthenticationFailureHandler authenticationFailureHandler,
                                      AuthenticationSuccessHandler authenticationSuccessHandler) {
    this.wxMpService = wxMpService;
    this.userDetailsService = userDetailsService;
    this.authenticationFailureHandler = authenticationFailureHandler;
    this.authenticationSuccessHandler = authenticationSuccessHandler;
}
 
Example #10
Source File: MiniAppAuthenticationConfigurer.java    From fast-family-master with Apache License 2.0 5 votes vote down vote up
public MiniAppAuthenticationConfigurer(UserDetailsService userDetailsService,
                                       AuthenticationFailureHandler authenticationFailureHandler,
                                       AuthenticationSuccessHandler authenticationSuccessHandler) {
    this.userDetailsService = userDetailsService;
    this.authenticationFailureHandler = authenticationFailureHandler;
    this.authenticationSuccessHandler = authenticationSuccessHandler;
}
 
Example #11
Source File: RestPublicLoginProcessingFilter.java    From Groza with Apache License 2.0 5 votes vote down vote up
public RestPublicLoginProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler,
                                       AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
    super(defaultProcessUrl);
    this.successHandler = successHandler;
    this.failureHandler = failureHandler;
    this.objectMapper = mapper;
}
 
Example #12
Source File: JwtTokenAuthenticationProcessingFilter.java    From iotplatform with Apache License 2.0 5 votes vote down vote up
@Autowired
public JwtTokenAuthenticationProcessingFilter(AuthenticationFailureHandler failureHandler,
    TokenExtractor tokenExtractor, RequestMatcher matcher) {
  super(matcher);
  this.failureHandler = failureHandler;
  this.tokenExtractor = tokenExtractor;
}
 
Example #13
Source File: RestLoginProcessingFilter.java    From IOT-Technical-Guide with Apache License 2.0 5 votes vote down vote up
public RestLoginProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler,
                                 AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
    super(defaultProcessUrl);
    this.successHandler = successHandler;
    this.failureHandler = failureHandler;
    this.objectMapper = mapper;
}
 
Example #14
Source File: JwtTokenAuthenticationProcessingFilter.java    From IOT-Technical-Guide with Apache License 2.0 5 votes vote down vote up
@Autowired
public JwtTokenAuthenticationProcessingFilter(AuthenticationFailureHandler failureHandler,
                                              TokenExtractor tokenExtractor, RequestMatcher matcher) {
    super(matcher);
    this.failureHandler = failureHandler;
    this.tokenExtractor = tokenExtractor;
}
 
Example #15
Source File: RestPublicLoginProcessingFilter.java    From IOT-Technical-Guide with Apache License 2.0 5 votes vote down vote up
public RestPublicLoginProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler,
                                       AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
    super(defaultProcessUrl);
    this.successHandler = successHandler;
    this.failureHandler = failureHandler;
    this.objectMapper = mapper;
}
 
Example #16
Source File: RefreshTokenProcessingFilter.java    From IOT-Technical-Guide with Apache License 2.0 5 votes vote down vote up
public RefreshTokenProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler,
                                    AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
    super(defaultProcessUrl);
    this.successHandler = successHandler;
    this.failureHandler = failureHandler;
    this.objectMapper = mapper;
}
 
Example #17
Source File: ExceptionMappingAuthenticationFailureHandler.java    From yes-cart with Apache License 2.0 5 votes vote down vote up
@Override
public void onAuthenticationFailure(HttpServletRequest request,
                                    HttpServletResponse response, AuthenticationException exception)
        throws IOException, ServletException {
    final AuthenticationFailureHandler handler = failureUrlMap.get(exception.getClass().getName());

    if (handler != null) {
        handler.onAuthenticationFailure(request, response, exception);
    } else {
        super.onAuthenticationFailure(request, response, exception);
    }
}
 
Example #18
Source File: RefreshTokenProcessingFilter.java    From Groza with Apache License 2.0 5 votes vote down vote up
public RefreshTokenProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler,
                                    AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
    super(defaultProcessUrl);
    this.successHandler = successHandler;
    this.failureHandler = failureHandler;
    this.objectMapper = mapper;
}
 
Example #19
Source File: JwtTokenAuthenticationProcessingFilter.java    From Groza with Apache License 2.0 5 votes vote down vote up
@Autowired
public JwtTokenAuthenticationProcessingFilter(AuthenticationFailureHandler failureHandler,
                                              TokenExtractor tokenExtractor, RequestMatcher matcher) {
    super(matcher);
    this.failureHandler = failureHandler;
    this.tokenExtractor = tokenExtractor;
}
 
Example #20
Source File: SecurityConfig.java    From pizzeria with MIT License 5 votes vote down vote up
@Bean
public AuthenticationFailureHandler authenticationFailureHandler() {
    RedirectAuthenticationFailureHandler redirectAuthenticationFailureHandler = new RedirectAuthenticationFailureHandler();
    redirectAuthenticationFailureHandler.setDefaultReturnUrl("/");
    redirectAuthenticationFailureHandler.setQueryParam("loginError");
    return redirectAuthenticationFailureHandler;
}
 
Example #21
Source File: RestLoginProcessingFilter.java    From Groza with Apache License 2.0 5 votes vote down vote up
public RestLoginProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler,
                                 AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
    super(defaultProcessUrl);
    this.successHandler = successHandler;
    this.failureHandler = failureHandler;
    this.objectMapper = mapper;
}
 
Example #22
Source File: LoginFilter.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
public LoginFilter(
    String authEndpoint,
    AuthenticationSuccessHandler successHandler,
    AuthenticationFailureHandler failureHandler,
    ObjectMapper mapper,
    AuthenticationManager authenticationManager,
    ResourceAccessExceptionHandler resourceAccessExceptionHandler) {
    super(authEndpoint);
    this.successHandler = successHandler;
    this.failureHandler = failureHandler;
    this.mapper = mapper;
    this.resourceAccessExceptionHandler = resourceAccessExceptionHandler;
    this.setAuthenticationManager(authenticationManager);
}
 
Example #23
Source File: CookieContentFilter.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
public CookieContentFilter(AuthenticationManager authenticationManager,
                           AuthenticationFailureHandler failureHandler,
                           ResourceAccessExceptionHandler resourceAccessExceptionHandler,
                           AuthConfigurationProperties authConfigurationProperties) {
    super(authenticationManager, failureHandler, resourceAccessExceptionHandler, new String[0]);
    this.authConfigurationProperties = authConfigurationProperties;
}
 
Example #24
Source File: CookieContentFilter.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
public CookieContentFilter(AuthenticationManager authenticationManager,
                           AuthenticationFailureHandler failureHandler,
                           ResourceAccessExceptionHandler resourceAccessExceptionHandler,
                           AuthConfigurationProperties authConfigurationProperties,
                           String[] endpoints) {
    super(authenticationManager, failureHandler, resourceAccessExceptionHandler, endpoints);
    this.authConfigurationProperties = authConfigurationProperties;
}
 
Example #25
Source File: LoginProcessingFilter.java    From secrets-proxy with Apache License 2.0 5 votes vote down vote up
public LoginProcessingFilter(
    String loginUrl,
    AuthenticationSuccessHandler successHandler,
    AuthenticationFailureHandler failureHandler,
    ObjectMapper mapper) {
  super(loginUrl);
  log.info("Initializing Login processing filter for " + loginUrl);
  this.successHandler = successHandler;
  this.failureHandler = failureHandler;
  this.mapper = mapper;
}
 
Example #26
Source File: WebSecurityConfig.java    From jeesupport with MIT License 5 votes vote down vote up
/**
 * 登陆失败后的处理,提示可以通过URL参数或者Session参数获取
 *
 * @return
 */
@Bean
public AuthenticationFailureHandler failureHandler(){
    return new AuthenticationFailureHandler(){
        @Override
        public void onAuthenticationFailure( HttpServletRequest _request, HttpServletResponse _response, AuthenticationException _e ) throws IOException, ServletException{
            log.debug( "--登陆失败:" + _e.getMessage() );
            redirectStrategy().sendRedirect( _request, _response,
                                             "/" + CommonConfig.getString( "jees.webs.login", "login" ) + "?" + ISupportEL.Login_Err );
        }
    };
}
 
Example #27
Source File: AdminUserProcessingFilter.java    From OpenLRW with Educational Community License v2.0 5 votes vote down vote up
public AdminUserProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler,
    AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
  super(defaultProcessUrl);
  this.successHandler = successHandler;
  this.failureHandler = failureHandler;
  this.objectMapper = mapper;
}
 
Example #28
Source File: OpenIdAuthenticationSecurityConfig.java    From paascloud-master with Apache License 2.0 5 votes vote down vote up
@Autowired
public OpenIdAuthenticationSecurityConfig(AuthenticationSuccessHandler pcAuthenticationSuccessHandler, AuthenticationFailureHandler pcAuthenticationFailureHandler, SocialUserDetailsService userDetailsService, UsersConnectionRepository usersConnectionRepository) {
	this.pcAuthenticationSuccessHandler = pcAuthenticationSuccessHandler;
	this.pcAuthenticationFailureHandler = pcAuthenticationFailureHandler;
	this.userDetailsService = userDetailsService;
	this.usersConnectionRepository = usersConnectionRepository;
}
 
Example #29
Source File: JwtTokenAuthenticationProcessingFilter.java    From OpenLRW with Educational Community License v2.0 5 votes vote down vote up
@Autowired
public JwtTokenAuthenticationProcessingFilter(AuthenticationFailureHandler failureHandler, 
        TokenExtractor tokenExtractor, RequestMatcher matcher) {
    super(matcher);
    this.failureHandler = failureHandler;
    this.tokenExtractor = tokenExtractor;
}
 
Example #30
Source File: AjaxLoginProcessingFilter.java    From OpenLRW with Educational Community License v2.0 5 votes vote down vote up
public AjaxLoginProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler, 
        AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
    super(defaultProcessUrl);
    this.successHandler = successHandler;
    this.failureHandler = failureHandler;
    this.objectMapper = mapper;
}