SecurityContextHolder

JosephDev·2024년 3월 24일

[0] SecurityContextHolder?

[1] Authentication

[2] SecurityContextHolder.getContext().authentication

  • 왜 getContext()를 사용해서 값을 저장할까?
fun setAuthentication(authentication: Authentication) {
	SecurityContextHolder.getContext().authentication = authentication
}
  • SecurityContextHolder 내부에는 setContext가 정의되어 있다.
public static void setContext(SecurityContext context) {
        strategy.setContext(context);
}
  • 이유 : 코드의 효율성을 위해서이다. setContext의 경우 전체 정보를 업데이트 해야하지만 대부분의 경우 authentication만 업데이트하면 무리없이 동작할 수 있기 때문이다.

0개의 댓글