Spring security authenticate exceptions handling

前端 未结 3 709
星月不相逢
星月不相逢 2020-12-09 19:18

I have an app using Spring Security 3.0.x. There I have a custom AuthenticationProvider:

public class A         


        
3条回答
  •  一生所求
    2020-12-09 19:43

    Authentication failure handler :

    public class CustomAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler {
    
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
      super.onAuthenticationFailure(request, response, exception);
      if(exception.getClass().isAssignableFrom(UsernameNotFoundException.class)) {
        showMessage("BAD_CREDENTIAL");
      } else if (exception.getClass().isAssignableFrom(DisabledException.class)) {
        showMessage("USER_DISABLED");
      }
    }
    

    configuration :

    
        
    
    
      
    
    

提交回复
热议问题