2016-12-30 2 views
1

내가 로그인 오류의 2 개 가지 유형이 있습니다봄 보안 - 사용자 정의 로그인 오류 메시지

  • 잘못된 사용자/PW
  • IP는 지금 봄이를 전달하는 너무 많은 시도

차단 두 경우 모두 사용자가 www.site.com/login?error입니다. 어떻게하면 로그인 동작을 사용자 정의하여 대소 문자에 따라 사용자를 error1 또는 error2로 전달할 수 있습니까? 이 앞으로의 행동은 어디에도 명시 적으로 선언되어 있지 않은 것으로 보이며 이에 대한 문서를 찾을 수 없습니다.

당신은 사용자 정의 AuthenticationFailureHandler를 구현해야

답변

1

, 참조 : Spring security authenticate exceptions handling

그냥 error1하거나 있고 Error2, 구현은 단순한 리디렉션 방법이 될 수있는 사용자를 리디렉션하려면 다음

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)) { 
    response.sendRedirect("error1") 
    } else if (exception.getClass().isAssignableFrom(LockedException.class)) { 
    response.sendRedirect("error2") 
    } 
} 
} 
+0

방법 그 클래스를 사용하도록 Spring을 설정합니까? @Component로 주석 달기를 시도하고 XML 구성을 pom.xml에 추가하려고 시도했다. 'authentication-failure-handler-ref는 허용되지 않습니다. '라는 불평을합니다. –

+0

@Atte pom.xml이 아닌 application-security.xml에 구성해야합니다. pom.xml은 주로 종속성, 플러그인 및 프로파일을 추가하기위한 것입니다. –

+0

좋아, 내가 찾은 몇 가지 예에 따라 application-security.xml 파일을 설정하려고했지만 여전히 작동하지 않습니다. 그 파일에 정의 된 문서가없는 것 같습니다. –

관련 문제