스터디-Spring

[스프링 시큐리티] SecurityContextHolder와 Authentication

일태우 2022. 1. 10. 21:59
반응형

https://docs.spring.io/spring-security/site/docs/5.1.5.RELEASE/reference/htmlsingle/#securitycontextholder-securitycontext-and-authentication-objects

 

Spring Security Reference

The authenticator is also responsible for retrieving any required user attributes. This is because the permissions on the attributes may depend on the type of authentication being used. For example, if binding as the user, it may be necessary to read them

docs.spring.io

 

SecurityContextHolder

  • 가장 기본적인 객체, SecurityContext 제공, 기본적으로 ThreadLocal을 사용한다.

SecurityContext

  • Authentication 제공

Authentication

  • Principal과 GrantAuthority를 제공

Principal

  • "누구"에 해당하는 정보
  • UserDetailsService에서 반환하는 객체 - UserDetails 타입

GrantAuthority

  • "ROLE_USER", "ROLE_ADMIN"등 Principal이 가지고 있는 "권한"을 나타낸다
  • 인증 이후, 인가 및 권한 확인할 때 이 정보를 조회한다

UserDetails

  • 어플리케이션이 가지고 있는 유저 정보와 스프링 시큐리티가 사용하는 Authentication 객체 사이의 어댑터
  • It represents a principal, but in an extensible and application-specific way. Think of UserDetails as the adapter between your own user database and what Spring Security needs inside the SecurityContextHolder

UserDetailsService

  • 유저 정보를 UserDetails 타입으로 가져오는 DAO (Data Access Object) 인터페이스
반응형