2012-07-27 5 views
1

토큰으로 로그인하는 다른 방법을 사용자에게 제공하려고합니다. 나는 이미 PreAuthenticationFilter 클래스에서 사용자를 인증 처리하지만 내가 발사 할 필요가 내 안에 방법을 발생시키는Spring을 사용하여 수동으로 AuthenticationSuccessHandler를 실행하는 방법

super.onAuthenticationSuccess()

을 수행

AuthenticationSuccessHandler.onAuthenticationSuccess()

의 기본 클래스의

SavedRequestAwareAuthenticationSuccessHandler.

내 preauthentication 필터에서 AuthenticationSuccessHandler? 나는 의 인증 설정을 시도하여 자동으로 AuthenticationSuccessHandler을 시작한다고 생각했지만 그렇지 않습니다. 이것은 내가 그렇게하려고 시도한 방법입니다.

Authentication authentication = new UsernamePasswordAuthenticationToken(Username, Password); 
SecurityContextHolder.getContext().setAuthentication(authentication); 

불행히도, 그것은 작동하지 않습니다. 따라서 미리 인증 필터에서 AuthenticationSuccessHandler을 발사하는 방법을 알아야합니다.

답변

0

RememberMeAuthenthicationFilter이 봄 보안에서 작동하는 방식에 영감을 얻을 수 있습니다. AuthenticationSuccessHandler에 대한 참조가 있고 onAuthenticationSuccess을 수동으로 호출합니다.

0

PreAuthenticationFilter를 확장하고 successfulAuthentication 메소드를 덮어 써야합니다. 거기에서 주입 성공 핸들러를 트리거 할 수 있습니다.

관련 문제