Spring Security ‐ 이벤트 처리 - woojin-playground/Backend-PlayGround GitHub Wiki
인증 이벤트 - Authentication Events
- Spring Security는 인증이 성공하거나 실패하게 되면
AuthenticationSuccessEvent 또는 AuthenticationFailureEvent를 발생시킨다.
- 이벤트를 수신하려면
ApplicationEventPublisher를 사용하거나 시큐리티에서 제공하는 AuthenticationEventPublihser를 사용해서 발행해야 한다.
AuthenticationEventPublisher의 구현체로 DefaultAuthenticationEventPublisher가 제공된다.
인증 이벤트 - AuthenticationEventPublisher 활용
AuthenticationException이 발생했을 때 해당 예외에 매핑된 이벤트가 발행이 안되어 있을 경우 기본 AuthenticationFailureEvent를 발행 및 수신할 수 있다.
인가 이벤트 - Authorization Events
- Spring Security는 권한 부여 이벤트 처리를 지원하며 권한이 부여되거나 거부된 경우에 발생하는 이벤트를 수신할 수 있다.
- 이벤트를 수신하려면
ApplicationEventPublisher를 사용하거나 시큐리티에서 제공하는 AuthorizationEventPublisher를 사용한다.
AuthorizationEventPublisher의 구현체로 SpringAuthorizationEventPublisher가 제공된다.
- 위와 같이 인가 이벤트를 발행하기 위해서는
SpringAuthorizationEventPublisher를 빈으로 등록해야 한다.