본문 바로가기
개발 관련 지식/Spring Framework Basic

Security - Authentication(인증) 개념

by 권태일1147 2022. 4. 3.

사용자의 인증정보를 저장하는 토큰 개념

  • 인증 시 id와 password를 담고 인증 검증을 위해 전달되어 사용된다.
  • 인증 후 최종 인증 결과(user 객체, 권한 정보)를 담고 SecurityContext에 저장되어 전역적으로 참조 가능
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication()

구조

  • principal : 사용자의 아이디 혹은 User 객체를 저장
  • credentials : 사용자 비밀번호
  • authorities : 인증된 사용자의 권한 목록
  • details : 인증 부가 정보
  • authenticated : 인증 여부

 

인증 흐름

  1. 로그인 요청(username + password)
  2. UsernamePasswordAuthenticationFilter가 받아서 username과 password를 이용해서 Authentication 객체를 만든다
    1. principal : username
    2. credentials : password
  3. AuthenticationManager가 Authentication 객체를 가지고 인증 처리를 한다.
  4. 인증에 성공하면 AuthenticationManager가 Authentication 객체를 새로 만든다.
    • principal : 최종적으로 인증에 성공한 결과를 담는다.
    • credentials : 패스워드를 담지만 보안상 비워두기도 한다.
    • Authorities: 권한 목록
    • Authenticated : true
  5. SecurityContext 객체 안에 Authentication 객체를 저장한다.