스프링 시큐리티의 구조
- 사용자가 입력한 사용자 정보를 가지고 인증을 요청한다.(Request)
- AuthenticationFilter가 이를 가로채 UsernamePasswordAuthenticationToken(인증용 객체)를 생성한다
- 필터는 요청을 처리하고 AuthenticationManager의 구현체 ProviderManager에 Authentication과 UsernamePasswordAuthenticationToken을 전달한다.
- AuthenticationManager는 검증을 위해 AuthenticationProvider에게 Authentication과 UsernamePasswordAuthenticationToken을 전달한다.
- 이제 DB에 담긴 사용자 인증정보와 비교하기 위해 UserDetailsService에 사용자 정보를 넘겨줍니다.
- DB에서 찾은 사용자 정보인 UserDetails 객체를 만든다.
- AuthenticationProvider는 UserDetails를 넘겨받고 비교한다.
- 인증이 완료되면 권한과 사용자 정보를 담은 Authentication 객체가 반환된다.
- AuthenticationFilter까지 Authentication정보를 전달한다.
- Authentication을 SecurityContext에 저장한다.
Authentication정보는 결국 SecurityContextHolder 세션 영역에 있는 SecurityContext에 Authentication 객체를 저장한다. 세션에 사용자 정보를 저장한다는 것은 전통적인 세션-쿠키 기반의 인증 방식을 사용한다는 것을 의미한다.
'Spring & SpringBoot' 카테고리의 다른 글
Java/SpringBoot 게시판 기능 구현_Token 관련 예외 처리 (0) | 2023.07.05 |
---|---|
SpringBoot 게시판_이미지 대표이미지 출력 (0) | 2023.05.12 |
[Spring] SpringBoot_게시글 수정하기 (JPA, MySQL) (0) | 2023.01.18 |
SpringBoot postman 404 error (0) | 2022.11.16 |
Spring boot - HTTPS 설정 (0) | 2022.05.04 |