스프링 시큐리티 OAuth2/Spring Security Fundamentals

AuthenticationEntryPoint 이해

webmaster 2022. 12. 17. 11:00
728x90

SpringSecurity는 기본적으로 2개의 설정(FormLoginConfigurer, HttpBasicConfigurer) 방식으로 설정한다.

  • FormLoginConfigurer, HttpBasicConfigurer 든 예외처리를 하기 위해서는 EntryPoint에 대한 설정을 해야 한다
  • ExceptionHandlingConfigurer에서 EntryPoint에 대한 설정을 한다
  • 인증 예외가 발생했을 때, ExceptionHandlingConfigurer에서 후속처리를 어떻게 진행할 것인지 결정한다.

FormLoginConfigurer 동작 과정

  1. FormLoginConfigurer에서 인증 에러가 발생했을 때의 EntryPoint를 결정해야 한다.
  2. FormLoginConfigurer에서 인증 에러가 발생하게 되면 ExceptionHandlingConfigurer에 설정되어 있는 값을 통해 후속처리를 한다.
    • FormLoginConfigurer에서 인증 에러가 발생했을 때, 등록되는 후속처리 클래스는 LoginUrlAuthenticationEntryPoint이다.
  3. LoginUrlAuthenticationEntryPoint 객체를 전달받아 defaultEntryPointMappings.put이라는 Map에 저장하게 된다.

HttpBasicConfigurer 동작 과정

  1. HttpBasicConfigurer에서 인증 에러가 발생했을 때의 EntryPoint를 결정해야 한다.
  2. HttpBasicConfigurer에서 인증 에러가 발생하게 되면 ExceptionHandlingConfigurer에 설정되어 있는 값을 통해 후속처리를 한다.
    • HttpBasicConfigurer에서 인증 에러가 발생했을 때 등록되는 후속처리 클래스는 BasicAuthenticationEntryPoint이다.
  3. BasicAuthenticationEntryPoint 객체를 전달받아 defaultEntryPointMappings.put이라는 Map에 추가 저장하게 된다.

EntryPoint 선택 과정

  • CustomAuthenticationEntryPoint : 커스텀하게 만든 EntryPoint 
    • 커스텀 생성한 것이 가장 우선시된다.
  • 초기 커스텀한 엔트리 포인트가 존재하는지 확인 후 있으면 커스텀 EntryPoint를 없으면 defaultEntryPointMappings에 존재하는 값을 반환한다.
    • 만약 defaultEntryPointMappings가 비어있다면 Http403 ForbinddenEntryPoint를 반환
    • 만약 size == 1 이면, 그것을 반환하고 그보다 크면 SpringSecurity가 알아서 판단하여 값을 반환하여 준다
  • 최종적으로 하나의 EntryPoint를 ExceptionTranslationFilter에게 전달해야 한다.
728x90