2015-01-10 2 views
2

Spring Security 3.2.5.RELEASE를 사용하고 있으며 실패한 로그인 시도를 잡는 데 어려움이 있습니다. 나는 현재 다음과 같이 ApplicationListener가 구성 : 예상대로 성공적으로 사용자가 로그인 내가 성공 메시지를 볼 수 있습니다Spring Security가 ApplicationListener의 로그인 실패를 catch하지 않습니다.

@Component 
public class MyApplicationListener implements ApplicationListener<AbstractAuthenticationEvent> { 

    private static Logger logger = LogManager.getLogger(MyApplicationListener); 

    @Override 
    public void onApplicationEvent(AbstractAuthenticationEvent abstractAuthenticationEvent) { 

     if (abstractAuthenticationEvent instanceof AbstractAuthenticationFailureEvent) { 

      logger.warn("Detected an invalid login"); 

     } else if (abstractAuthenticationEvent instanceof AuthenticationSuccessEvent) { 

      logger.info("A user logged in successfully"); 
     } 
    } 
} 

합니다. 그러나 사용자가 잘못된 암호 등을 제공하면 오류 메시지가 표시되지 않습니다.

@Component 
public class MyApplicationListener implements ApplicationListener<ApplicationEvent> { 

    private static Logger logger = LogManager.getLogger(MyApplicationListener); 

    @Override 
    public void onApplicationEvent(ApplicationEvent applicationEvent) { 

     logger.info("Got an event of type {}", applicationEvent.getClass()); 
    } 
} 

를 기록하고있는 유일한 보안 관련 이벤트 유형 org.springframework.security.authentication.event.InteractiveAuthenticationSuccessEvent의이다 그러나 : 그것은 다음과 같이 모든 ApplicationEvent를 기록 있도록

나는 청취자를 변경했습니다. 실패한 로그인은 이벤트를 트리거하지 않습니다. 나는 모든 포인터 감사드립니다, 고마워요.

답변

3

어쩌면 조금 늦게,하지만 난 같은 문제를 가지고 있으며이 방법을 해결하기 : 당신의 configureGlobal 방법

을 : auth.authenticationEventPublisher(defaultAuthenticationEventPublisher());

말라가 콩

@Bean 
public DefaultAuthenticationEventPublisher defaultAuthenticationEventPublisher(){ 
    return new DefaultAuthenticationEventPublisher(); 
} 
로 DefaultAuthenticationEventPublisher를 선언하는 것을 잊지

자세한 내용은 여기 : Why the event AbstractAuthenticationFailureEvent is never triggered in spring security?

관련 문제