SecurityContext & SecurityContextHolder

midas·2022년 5월 17일
0

📄 SecurityContext란?

  • Authentication 객체가 저장되는 보관소

  • 필요 시 언제든지 Authentication을 꺼내 쓸 수 있는 클래스

  • ThreadLocal에 저장되어서 아무곳에서나 접근 가능? 🤔

  • 인증이 완료되면 Session에 저장되어 앱 전역적으로 참조가 가능

  • 익명 사용자의 경우?

    • AnonymousAuthenticationFilter → AnonymousAuthenticationToken 발행
    • SecurityContext에 위의 Token을 저장
  • 인증 시

    • SecurityContext 새로 생성 → UsernamePasswordAuthentication에서 인증
    • 인증이 성공 되면 Username... → Authentication 객체를 SecurityContext에 저장
    • 인증이 최종 완료되면 Session에 SecurityContext를 저장
  • 인증 후

    • Session에서 SecurityContext를 가져와서 SecurityContextHolder에 저장
    • SecurityContext에 Authentication 객체가 존재한다면 인증 상태를 유지

📥 SecurityContextHolder란?

  • SecurityContext의 보관소 → 세부 정보를 가지고 있다?
    정의 부분을 잘 모르겠음 🤔
  • SecurityContext 저장 방식 3가지
    • MODE_THREADLOCAL : [기본값] 스레드 하나 → SecurityContext를 할당
    • MODE_INHERITABLETHREADLOCAL : 메인 스레드와 자식 스레드에 동일한 SecurityContext를 유지
    • MODE_GLOBAL : 응용 프로그램에서 단 하나의 SecurityContext 관리
  • 참고
    ✨ 정리 겁나 잘한 블로그 글 (강의 교안 사진 그대로 쓴거 같은데...? 괜찮..?)
    Spring Security #3 아키텍처 이해하기, 인증 및 인가 원리
profile
BackEnd 개발 일기

0개의 댓글