2010-01-26 4 views
2

안녕 Spring 웹 플로우와 스프링 보안을 사용하는 j2ee 어플리케이션이 있습니다. 계정 잠금을 3 번 수행하면 계정이 잠길 수 있습니다. 어떻게 구현해야합니까?스프링 보안 계정 잠금

답변

4

AuthenticationFailureHandler을 사용할 수 있습니까? 이 접근법은 Acegi FAQ에서 제안되었습니다 (일반적인 문제점 # 3 참조).

+0

내가 빈 응용 프로그램 핸들러를 구현하고 AuthenticationFailureHandler의 인스턴스에 대한 검사를 등록 사용할 수 있습니다 – cedric

1

이 동작은 밑줄 인증 공급자에 속합니다. LDAP를 사용하는 경우 암호 정책이 있습니다. LdapAuthenticationProvider은 계정이 차단 된 경우 예외를 발생시킵니다.
현재 AuthenticationProvider에이 기능이없는 경우 서브 클래 싱하십시오.

0

당신은 AuthenticationFailureHandler

public class MySimpleAuthenticationFailureHandler implements 
AuthenticationFailureHandler { 

private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); 

public MySimpleAuthenticationFailureHandler() { 
     super(); 
    } 
public void onAuthenticationFailure(HttpServletRequest request, 
     HttpServletResponse response, AuthenticationException exception) 
       throws IOException, ServletException { 

    String message = ""; 

    if(exception instanceof UsernameNotFoundException) { 
     message = "UsernameNotFoundException"; 
    } else if(exception instanceof AuthenticationCredentialsNotFoundException) { 
     message = "AuthenticationCredentialsNotFoundException"; 
    }else if(exception instanceof InsufficientAuthenticationException) { 
     message = "InsufficientAuthenticationException"; 
    }else if(exception instanceof AccountExpiredException) { 
     message = "AccountExpiredException"; 
    }else if(exception instanceof CredentialsExpiredException) { 
     message = "CredentialsExpiredException"; 
    }else if(exception instanceof DisabledException) { 
     message = "DisabledException"; 
    }else if(exception instanceof LockedException) { 
     message = "LockedException"; 
    }else if(exception instanceof BadCredentialsException) { 
     message = "BadCredentialsException"; 
    }else{ 
     message = exception.getMessage(); 
    } 
    final HttpSession session = request.getSession(); 
    session.setAttribute("errorMessage", message); 
    redirectStrategy.sendRedirect(request, response, "/login?error="+message); 
} 

}