Spring Security
🧡 스프링 시큐리티의 동작 구조

ApplicationFilterChain을 의미한다.DelegatingFilterProxy를 사용한다.
DelegatingFilterProxy는 서블릿 컨테이너의 생명주기와 스프링 애플리케이션 컨텍스트(ApplicationContext) 사이에서 다리 역할을 수행하는 필터 구현체이다.FilterChainProxy)를 내부에 가지고 있다. 필터체인 프록시는 스프링 부트 자동 설정에 의해 자동 생성된다.SecurityFilterChain)을 통해 많은 보안 필터를 사용할 수 있다.별도의 설정이 없다면 스프링 시큐리티에서는 아래와 같이 SecurityFilterChain에서 사용하는 필터 중 UsernamePasswordAuthenteicationFilter를 통해 인증을 처리한다.

위 그림의 인증 수행 과정은 다음과 같다.
SecurityFilterhain으로 작업이 위임되고 그중 UsernamePasswordAuthenticationFilter(위 그림에서 AuthenticationFilter에 해당)에서 인증을 처리한다.AuthenticationFilter는 요청 객체(HttpServletRequest)에서 username과 password를 추출해서 토큰을 생성한다.AuthenticationManager에게 토큰을 전달한다. AuthenticationManager는 인터페이스이며, 일반적으로 사용되는 구현체는 ProviderManager이다.ProviderManager는 인증을 위해 AuthenticationProvider로 토큰을 전달한다.AuthenticationProvider는 토큰의 정보를 UserDetailsService에 전달한다.UserDetailsService는 전달받은 정보를 통해 데이터베이스에서 일치하는 사용자를 찾아 UserDetails 객체를 생성한다.UserDetails 객체는 AuthenticationProvider로 전달되며, 해당 Provider에서 인증을 수행하고 성공하게 되면 ProviderManager로 권한을 담은 토큰을 전달한다.ProviderManager는 검증된 토큰을 AuthenticationFilter로 전달한다.AuthenticationFilter는 검증된 토큰을 SecuritycontextHolder에 있는 SecurityContext에 저장한다.JWT
https://velog.io/@sunlake123/JWT
🧡
UserDetails와UserDetailsService구현
public interface UserDetails extends Serializable {
Collection<? extends GrantedAuthority> getAuthorities();
String getUsername();
String getPassword();
boolean isAccountNonExpired();
boolean isAccountNonLocked();
boolean isCredentialsNonExpired();
boolean isEnabled();
}
getAuthorities() : 계정이 가지고 있는 권한 목록을 리턴.getPassword() : 계정의 비밀번호를 리턴.getUsername() : 계정의 이름을 리턴한다. 일반적으로 아이디를 리턴.isAccountNonExpired() : 계정이 만료됐는지 리턴. true는 만료되지 않았다는 의미.isAccountNonLocked() : 계정이 잠겨있는지 리턴. true는 잠기지 않았다는 의미.isCredentialsNonExpired() : 비밀번호가 만료됐는지 리턴한다. true는 만료되지 않았다는 의미.isEnabled() : 계정이 활성화돼 있는지 리턴한다. true는 활성화 상태를 의미.