인프런 커뮤니티 질문&답변

개발중님의 프로필 이미지

작성한 질문수

스프링 시큐리티

9) 인증 성공 핸들러 : CustomAuthenticationSuccessHandler

super.onAuthenticationSuccess 호출 문의

21.08.22 12:57 작성

·

585

0

안녕하세요. 강사님

CustomAuthenticationSuccessHandler 에서는

super.onAuthenticationSuccess 호출 안 함. 

CustomAuthenticationFailureHandler 에서는 

super.onAuthenticationFailure 호출

CustomAuthenticationSuccessHandler 에서 super.onAuthenticationSuccess 하지 않은 이유가 있을까요?

CustomAuthenticationFailureHandler 에서 super.onAuthenticationFailure 호출하지 않으면 정상적으로 작동하지 않는 듯 합니다.  한편, CustomAuthenticationSuccessHandler 에서는 super.onAuthenticationSuccess 가 있든 없든 정상적으로 작동하는데  주석을 보니 "Removes temporary authentication-related data which may have been stored in the authentication process. " 라고 되어 있습니다.

CustomAuthenticationSuccessHandler 는  super.onAuthenticationSuccess  호출이 선택인가요?

답변 1

1

정수원님의 프로필 이미지
정수원
지식공유자

2021. 08. 24. 17:47

CustomAuthenticationSuccessHandler 와 CustomAuthenticationFailureHandler 모두 super 클래스를 호출하지 않아도 상관없습니다.

다만 CustomAuthenticationFailureHandler 는 실패 이후 이동할 페이지를 지정할 경우 상위클래스에게 위임하는 것이 더 좋다고 판단되어 그렇게 한 것 뿐입니다.

실패와 관련된 여러가지 후속 처리를 해주기 때문입니다.

그렇지만 CustomAuthenticationFailureHandler 가 SimpleUrlAuthenticationSuccessHandler 클래스를 상속하지 않고 AuthenticationSuccessHandler 인터페이스를 구현하셔도 됩니다.

CustomAuthenticationSuccessHandler 는 성공 이후의 작업을 처리하는 클래스인데 상위 클래스를 보시면 성공 이후 이동할 페이지를 결정하는 구문이 여러 갈래로 나뉘어져 있고 그 중에서 하나가 결정되어 이동합니다. 즉 선택권이 없습니다.

그래서 원하는 페이지로 이동하도록 간단하게 직접 구현한 것입니다.

상위 클래스의 로직를 분석해 보시면 여러가지로 도움이 될 수 있습니다.