Spring Security 5

Spring Security Configuration 실험

실험 1 만약 authorizeHttpRequests 를 연거푸 호출하면 모든 설정이 제대로 반영될까? 정확한 실험 이유는 다음과 같다. 💡 만약 authorizeHttpRequests 를 연거푸 호출하면 모든 설정이 제대로 반영될까? 혹시 마지막에 사용된 authorizeHttpRequests 만 반영되는 구조인 것인가? @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { // 만약 덮어씌우기라면 사라져야 할 설정 1. http.authorizeHttpRequests(b -> b.requestMatchers(AntPathRequestMatcher.antMatcher(HttpMethod.GET,..

Spring Security 2023.09.30

인증 필터는 어떻게 재정의할 수 있을까?

👣 인증 필터의 업무 파악 우선 인증 필터가 수행해야 하는 업무를 나열하면 다음과 같다. 인증 전 AuthenticationToken을 만들기 해당 Authentication Token을 AuthenticationManager에게 위임해서 인증된 AuthenticationToken 만들기 SecurityContextHolder에 안착시키기 인증 오류 발생 시, 오류 처리하기 위 업무 중 3번과 4번을 미리 해결한 추상 클래스를 찾아보면 AbstractAuthenticationProcessingFilter 라는 클래스를 찾아볼 수 있다. 👣 AbstractAuthenticationProcessingFilter 분석 AbstractAuthenticationProcessingFilter는 3번을 해결하기 위해..

Spring Security 2023.09.01

AuthenticationProvider를 내 맘대로 커스터마이징할 수 있을까?

👣 개요 결국 UserDetailsService를 사용하고 싶지 않아도 UsernamePasswordAuthenticationToken을 사용한다면 어쩔 수 없이 UserDetailsService를 사용해야 한다는 것이다. 만약 JWT에 Username을 넣으면 안 된다거나 Id값을 Payload에 넣고 싶다면 [혹은 등등의 어떠한 이유로] UserDetailsService.loadUserByUsername()가 아닌 다른 인터페이스를 사용해야 할지도 모른다. 해당 상황에 대해 어떻게 대처를 할 수 있을까? 👣 AuthenicationManager 작동 원리 파악 우선 AuthenicationManager의 구현체, 즉 ProviderManager가 AuthenticationProvider를 선택하는 과..

Spring Security 2023.09.01

UserDetailsService 구현은 항상 요구되는 것인가?

👣 개요 나의 의문점은 UserDetailsService와 UserDetails 인터페이스는 모든 AuthenticationProvider에서 요구하냐는 것이었다. 때문에 관련 질문을 ChatGPT에게 물어봤다. 물론 답변은 이렇게 나왔으나 ChatGPT는 자신이 모르는 정보라도 아는 것 마냥 거짓말을 하는 경우가 자주 발생하기 때문에 해당 사실을 파악하기 위해 직접 코드를 확인하기로 했다. 👣 AuthenticationProvider 구현체들 코드 분석 우선 AuthenticationProvider 구현체들의 목록은 다음과 같다. 모든 클래스를 전수 조사하는 것은 쉽지 않기에 대표적인 몇몇 클래스로 확인하고자 했다. AbstractUserDetailsAuthenticationProvider Abstra..

Spring Security 2023.09.01

인증 관련 Architecture 분석

👣 개요 Spring Security를 다루면서 들었던 의문점들을 해소하고자 해당 게시물을 작성하게 되었다. 해당 게시물에서는 인증 과정에서 일어나는 과정들을 상세히 다루고자 하며 Spring Security 내에서 일어나는 이벤트들에 중점적으로 다루며 코드 분석 중심으로 작성한다. 👣 Architecture 인증 과정 순서는 그림에 명시되어 있어서 설명은 생략한다. 👣 UserDetailsService 구현은 항상 요구되는 것인가? UserDetailsService 구현은 항상 요구되는 것인가? 👣 개요 나의 의문점은 UserDetailsService와 UserDetails 인터페이스는 모든 AuthenticationProvider에서 요구하냐는 것이었다. 때문에 관련 질문을 ChatGPT에게 물어봤다..

Spring Security 2023.09.01