securitycontext
-
[Spring Security5] SecurityContext에 가졌던 작은 오해개발/Spring 2023. 12. 18. 16:01
- 익명 사용자든 인증된 사용자든 매 요청 때마다 인증 객체(authentication)가 생성됨 - 인증 객체는 SecurityContext에 저장됨 - 익명 사용자의 요청일 때는 SecurityContext 객체를 만들어야 하지만, 인증 사용자는 Session에서 가져오기 때문에 미생성 - 인증 사용자는 SecurityContext 객체를 Session에 저장하지만, 익명 사용자는 Session에 저장하지 않음 - 각 요청마다 ThreadLocal이 만들어지고 SecurityContext는 각 ThreadLocal에 저장 - 이를 전역적으로 관리하는 SecurityContextHolder도 ThreadLocal에서 생성 - 이 안에서 ThreadLocal을 key, SecurityContext 객체를..