본문 바로가기

Spring🍃/Spring Security🛡️

정수원의 Spring Security Oauth2 (4) : Http Basic

728x90

가장 일반적인 Http의 인증방식은 Basic 인증 방식이다

 

RFC 7235 표준으로, 인증에 필요한 인증 정보를 Base 64로 인코딩해 서버에 인증을 요청한다

(Base 64는 디코딩이 쉽기 때문에 Https와 같은 TLS를 함께 사용해야 한다)

 

1. HttpBasicConfigurer

- Basic 인증 초기화를 진행하며 속성에 대한 기본값 설정

- 기본 AuthenticationEntryPoint는 BasicAuthenticationEntryPoint이다

- 필터는 BasicAuthenticaionFilter를 사용

 

2. BasicAuthenticaionFilter

기본 인증 서비스 제공, 요청 헤더의 인증정보 유효성을 체크하며 인증정보인 아이디와 패스워드를 추출한다. 인증 결과에 따라 Authenticaion 객체를 Securty Context에 저장하거나 재 인증을 요구하는 BasicAuthenticationEntryPoint를 호출한다. 인증 이후 세션 사용하지 않는 경우에는 매번 인증을 요구하게 된다

 

3. 흐름도

요청 - BasicAuthenticaionFilter - BasicAuthenticationConverter -

UsernamePasswordAuthenticationToken(유저 네임, 패스워드 저장)

-> authenticationRequired(username)

-> 1) N : Chain.doFilter

-> 2) Y : ProviderManager

 

- DaoAuthenticationProvider

-> 1) 인증 성공 : UsernamePasswordAuthenticationToekn에서 Principal이 User인 Authentication 객체 생성 - SecurityContext 저장

-> 2) 인증 실패 : BasicAuthenticationEntryPoint - 재인증(login prompt) 또는 401Unauthorized

728x90