org.springframework.security.core.userdetails.UsernameNotFoundException无法转换为org.springframework.security.core.userdetails.UserDetails

时间:2019-05-25 05:29:47

标签: java exception spring-security spring-framework-beans

公共类AppLoginFailureHandler实现AuthenticationFailureHandler {

@Override
public void onAuthenticationFailure(HttpServletRequest request,
        HttpServletResponse response, AuthenticationException exception)
        throws IOException, ServletException {

     String message = "";

    if(exception.getClass() == BadCredentialsException.class){
        message = "check your password";

        System.out.println("User Couldn't logged in , entered password is incorrect : "+exception.getMessage());
        System.out.println("Exception : "+exception.getClass());
        request.getRequestDispatcher(String.format("/error.jsp?message=%s", message)).forward(request, response);
    }else if(exception.getClass() == UsernameNotFoundException.class){
        message = "user not found";
        System.out.println("User Couldn't logged in ,usernae not found : "+exception.getMessage());
        System.out.println("Exception : "+exception.getClass());
    }
 }

从方法loadUserByUsername(String username)找不到用户时,我抛出新的UsernameNotFoundException(“ User not found”); 但是在实现AuthenticationFailureHandler无法捕获UsernameNotFoundException的类中,它说- org.springframework.security.core.userdetails.UsernameNotFoundException无法转换为org.springframework.security.core.userdetails.UserDetails

0 个答案:

没有答案