윤개발

Spring Security 원리 및 방식 정리 본문

백엔드/스프링

Spring Security 원리 및 방식 정리

DEV_SJ 2021. 3. 22. 13:58

 

용어 설명

  • Authentication(인증) : 사용자가 본인인지 맞는지 확인
  • Authorization(권한) : 인증된 사용자가 요청에 접근 가능한지 확인

기본 원리

  • Client의 요청은 Filter Chain을 거쳐 처리된다.
  • 여러 필터를 지나며 인증이 완료되면 해당요청은 인증된 요청이 된다.
  • 모든 필터를 지나며 인증되지 않았다면 인증되지 않은 요청(403)이 된다.

처리 방식

 

  1. 요청이 오면 인증을 담당하는 AuthenticationFilter에서 처리한다.
  2. UsernamePasswordAuthenticationToken을 만들어 AuthenticationManager(인터페이스)에게 위임한다.
  3. AuthenticationManager를 구현한 ProviderManager는 AuthenricationProvider(interface)를 List로 돌며 인증이 가능한 클래스를 찾는다.
  4. AuthenricationProvider를 구현한 클래스들 중에 인증이 가능한 클래스가 인증을 담당한다.
  5. (AuthenricationProvider를 구현한 AbstractUserDetailsAuthenticationProvider 객체를 지원 )
  6. UserDetailsService에서 User를 조회하여 인증을 진행한다.
  7. 인증이 완료되면 SecurityContextHolder에 저장된다.
Comments