스파르타 부트캠프(spring)

[내일배움캠프_Spring] 자바 Spring 입문_Spring Security 주요 컴포넌트_230131

wkdwldP 2023. 2. 1. 00:55

Spring Security 와 Filter

spring security

  • 요청이 들어오면 Servlet FilterChain을 자동으로 구성한 후 거치게 함
  • 필터는 클라이언트 요청이 전달되기 전후의 URL패턴에 맞는 모든 요청에 필터링을 해줌
  • 보안 검사를 통해 올바른 요청이 아닐 경우 차단

->따라서 Spring Security는 이런한 기능을 활용하기위해 Filter를 사용하여 인증/인가를 구현하고 있다.

 

SecurityFilterChain

: Spring 의 보안 Filter를 결정하는데 사용되는 Filter

->session, jwt 등의 인증 방식 들을 사용하는데 필요한 설정을 완전 분리할 수 있는 환경 제공

 

AbstractAuthenticationProcessingFilter

  • 사용자의 credential을 인증하기 위한 베이스 Filter

 

UsernamePasswordAuthenticationFilter

  • AbstractAuthenticationProcessingFilter를 상속한 Filter
  • 기본적으로 아래와 같은 Form Login 기반을 사용할 때 username 과 password 확인하여 인증한다.
  • Form Login 기반은 인증이 필요한 URL 요청이 들어왔을 때 인증이 되지 않았다면 로그인페이지를 반환

SecurityContextHolder

  • 스프링 시큐리티로 인증을 한 사용자의 상세 정보를 저장

Authentication

  • 현재 인증된 사용자(SecurityContext에서 가져올 수 있다.)
  • principal : 사용자를 식별한다. Username/Password 방식으로 인증할 때 보통 UserDetails 인스턴스
  • credentials : 주로 비밀번호, 대부분 사용자 인증에 사용하고 비움
  • authorities : 사용자에게 부여한 권한을 GrantedAuthority 로 추상화하여 사용

 

UserDetailsService

  • UserDetailsService는 username/password 인증방식을 사용할 때 사용자를 조회하고 검증한 후 UserDetails를 반환
  • Custom하여 Bean으로 등록 후 사용 가능하다.

 

UserDetails

  • 검증된 UserDetails는 UsernamePasswordAuthenticationToken 타입의 Authentication를 만들 때 사용되며 해당 인증객체는 SecurityContextHolder에 세팅된다.
  • Custom하여 사용가능하다.