티스토리 뷰

Spring Security - 아키텍쳐 AuthenticationManager Authentication

  • Spring Security에서 인증 (Authenticaiton) 은 AuthenticationManager가 담당한다.

 

AuthenticationManager

 

인자로 받은 Authentication 객체가 유저에 대한 인증 정보를 담고있다.
해당 인증 정보가 유효하다면 UserDetailsService에서 Return한 객체 [Principal] 을 담고있는 Authentication 객체를 리턴한다.

 

기본 구현체는 ProviderManager 를 사용한다.
직접 AuthenticationManager를 구현해도 되지만 대부분의 Application에서 기본 구현체 정도에서 해결이 된다.

  • 직접 구현하는 경우는 매우 드물다.

 

인증 프로세스

  • 유저를 생성하고, 로그인 폼에서 정상적인 인증 요청을 했을경우
  • ProviderManager의 authentcation 메서드로 진입을 한다.
    • 이때 Authentication 객체를 파라메터로 받는다.
    • Authentcation 객체에는 principal에 해당하는 username 정보와 credentials에 해당하는 password가 들어오게 된다.
    • authorities 권한에 해당하는 정보는 아직 알 수 없기때문에 빈값이 들어온다.
  • 해당 요청에 대한 인증을 처리할수 있는 Provider를 찾아 이를 처리한 뒤 인증정보가 담긴 Authentication 객체를 반환한다.

 

 

ProviderManager는 인증을 직접 처리하는것이 아닌 다른 여러 Provider를 사용해서 진행한다.

  • 다른 여러 Provider들에게 위임하는 구조

  • 현재 파라메터로 들어온 Authentication 객체는 UsernameAuthenticationToken 타입이다

  • Authentication 객체의 타입마다 처리할 수 있는 Provider가 다르다.

UsernameAuthenticationToken.java

 

 

현재 ProviderManager는 AnnoymousAuthenticationProvider만을 가지고 있기때문에 UsernamePasswordAuthenticationToken에 대한 인증을 처리할 수 없다.

 

 

 

현재 ProviderManager에게 처리 할수 있는 Provider가 존재하지 않을경우 ProviderManager의 Parent에게 위임한다.

 

 

  • ProviderManager의 Parent가 인증 요청을 위임받아, 처리할수 있는 Provider를 찾은뒤 인증을 처리한다.
  • 이때 ProviderManager와 ProviderManager의 Parent는 다른 ProviderManager이며 처리 가능한 Provider도 다르다.

 

인증 요청을 위임받은 ProviderManager는 DaoAuthenticationProvider를 사용하며, DaoAuthenticationProvider는 우리가 직접 구현한 UserDetailsService를 사용한다.

 

 

인증이 완료되어 ProviderManager에서 반환하는 객체는 이전에 살펴본 SecurityContextHolder를 이용해 접근할 수 있는 Authentication 객체와 동일하다.

- 인증이 완료되어 반환되는 객체가 SecurityContext에 저장되는 것이다.

 

 

 

인증 과정에서 발생하는 예외들

  • DisabledException
    • 계정이 비활성화 되어있는 경우
  • LockedException
    • 계정이 잠겨 있는 경우
  • BadCredentialsException
    • 비밀번호가 일치하지 않는 경우
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함