1. SecurityContextHolder와 Authentication
2. AuthenticationManager와 Authentication
3. ThreadLocal
4. Authentication과 SecurityContextHolder
1. SecurityContextHolder와 Authentication

1-1) SecurityContextHolder(인증 정보를 담고 있는 곳)
- SecurityContext 제공, 기본적으로 ThreadLocal을 사용함.
- 결국 인증이 된 Authentication 객체가 SecurityContextHolder에 들어가는 거임.
1-2) Security Context
1-3) Authentication(인증)
2. AuthenticationManager와 Authentication
- 스프링 시큐리티에서 인증(Authentication)은 AuthenticationManager가 한다.
- 인증 정보
- 인증 처리
- AuthenticationManager
- 인자로 받은 Authentication
- 사용자가 입력한 인증에 필요한 정보(username, password)로 만든 객체
- Principal : “ssu”
- Credentials : “123”
- 유효한 인증인지 확인
- 사용자가 입력한 패스워드가 UserDetailsService를 통해 읽어온
- UserDetails 객체에 들어있는 패스워드와 일치하는지 확인
- 해당 사용자 계정이 활성인지 비활성인지 확인
- Authentication 객체를 리턴
- Principal : UserDetailsService에서 리턴한 그 객체(User)
- Credentials
- GrantedAuthorities
2-1) AuthenticationManager
- AuthenticationManager는 Authenticate()라는 ‘메소드’하나 밖에 없음.

2-1)-1. ProviderManager

-
View(Login)

-
DeBug Mode

2-1)-2. AbstractUserDetailsAuthenticationProvider

2-1)-3. DaoAuthenticationProvider

2-1)-4. ProviderManager
- ProviderManager에서 return result가 Authentication의 authenticate() 메소드임.

3. ThreadLocal
- TheadLocal
- Java.lang.패키지에서 제공하는 쓰레드 범위 변수.
- 즉, 쓰레드 수준의 데이터 저장소.
- 같은 쓰레드 내에서만 공유
- 따라서 같은 쓰레드라면 해당 데이터를 메소드 매개변수로 넘겨줄 필요 없음.
- SecurityContextHolder의 기본 적략
3-1) AccountContext(SecurityContextHolder의 기본 적략)

3-2) SampleController

3-3) SampleService

3-4) Console

4. Authentication과 SecurityContextHolder
- Authentication 객체를 리턴(이거 하는 거임)
- Principal : UserDetailsService에서 리턴한 그 객체(User)
- Credentials
- GrantedAuthorities
- AuthenticationManager가 인증을 마친 뒤 리턴 받은 Authentication 객체의 행방은?
4-1) SampleService