스프링 시큐리티는 두 가지 방식의 OAuth 2.0 Bearer Token 엔드포인트를 지원한다.
이 기능은 애플리케이션이 권한 관리를 authorization server(ex. Okta or Ping Identity)에 위임한 경우 유용하다.
SecurityFilterChain
다이어그램이다.
/private
리소스로 요청을 한다.FilterSecurityInterceptor
는 인증되지 않은 요청이 거부되었음을 AccessDeniedException
을 던짐으로써 나타낸다.ExceptionTranslationFilter
는 인증을 시작한다.
AuthenticationEntryPoint
는 WWW-Authenticate 헤더를 전송하는 BearerTokenAuthenticationEntryPoint
인스턴스다.
BearerTokenAuthenticationFilter
가 HttpServletRequest
에서 토큰을 추출하여 Authentication
의 한 타입인 BearerTokenAuthenticationToken
을 생성한다.HttpServletRequest
는 사용할 AuthenticationManager
를 결정하는 AuthenticationManagerResolver
로 전달된다.
BearerTokenAuthenticationToken
은 인증되기 위해 AuthenticationManager
로 전달된다.SecurityContextHolder
가 클리어된다.AuthenticationEntryPoint
가 호출되어 WWW-Authenticate 헤더가 다시 전송되도록 트리거한다.SecurityContextHolder
에 Authentication
이 설정된다.BeforeTokenAuthenticationFilter
가 FilterChain.doFilter(request, response)
를 호출하여 애플리케이션 로직이 계속되도록 한다.