AuthenticationManager 생성시점
111
34 asked
가끔 securityconfig 설정 중 AbstractAuthenticationProcessingFilter 상속한 필터를 만들 때 AuthenticationManager가 필요해서 http.shareObject로 받아오면 Null을 반환하더라구요.
protected void beforeConfigure() throws Exception {
if (this.authenticationManager != null) {
this.setSharedObject(AuthenticationManager.class, this.authenticationManager);
} else {
ObjectPostProcessor<AuthenticationManager> postProcessor = this.getAuthenticationManagerPostProcessor();
AuthenticationManager manager = (AuthenticationManager)this.getAuthenticationRegistry().build();
if (manager != null) {
this.setSharedObject(AuthenticationManager.class, (AuthenticationManager)postProcessor.postProcess(manager));
}
}
여기서 httpSecurity의 해당 메서드에서 providerManger를 생성하는 거 같으나 디버깅했을때
여기보다 제가 Bean으로 정의한 SecurityFilterchain이 먼저 걸려 httpSecurity.getShareObject()를 하면 null을 반환하더라구요. 그래서 authenticationConfiguration.getAuthenticationManager()으로 넣기는 하였으나 이게 정확히 AuthenticationManager생성주기가 매우 궁금하여 질문드립니다.
Answer 1
0
안녕하세요, 인프런 AI 인턴입니다.
hoonseung님, 질문 주신 내용은 Spring Security의 AuthenticationManager 생성 시점과 관련이 있군요. AuthenticationManager의 생성 주기는 보통 SecurityFilterChain 설정 시점과 관련이 깊습니다. Spring Security에서 AuthenticationManager는 일반적으로 SecurityFilterChain에 설정된 보안 규칙에 따라 설정되며, Spring Boot에서는 사용자 정의 SecurityFilterChain이 있으면 기본 보안 설정을 비활성화하게 됩니다.
http.getSharedObject(AuthenticationManager.class)가 null을 반환하는 이유는 보통 SecurityFilterChain 내의 HttpSecurity가 아직 AuthenticationManager를 완전히 구성하지 않았기 때문입니다. 그리고 직접 SecurityFilterChain을 정의하여 Bean으로 등록한 경우, 그 설정이 우선 적용되어 기본 보안 설정을 대체합니다.
authenticationConfiguration.getAuthenticationManager() 메서드를 사용하여 AuthenticationManager를 가져오는 것은 유효한 방법입니다. 이는 전체 보안 설정이 초기화될 때 AuthenticationManager가 올바로 설정되었는지를 확인하는 데 도움이 됩니다.
추가로, @Bean으로 정의된 AuthenticationManager, AuthenticationProvider, 혹은 UserDetailsService가 있으면 이는 기본 InMemoryUserDetailsManager Bean 생성이 막히게 되어 Spring Security의 전체 기능을 사용할 수 있습니다. 이러한 Bean의 정의는 AuthenticationManager의 초기화 및 설정 순서에 영향을 주게 됩니다.
더 구체적인 구성과 관련된 사항은 해석의 여지가 있을 수 있으니, 특정 구현에 대한 질문이 필요하다면 관련 코드나 설정을 자세히 검토하여 보는 것이 좋습니다. Spring Boot 공식 문서를 참조하시면 추가적인 정보를 얻을 수 있습니다.
도움이 되셨기를 바랍니다. 추가 질문이 있다면 언제든지 문의해 주세요!
authorization-server 라이브러리 질문이 있습니다.
0
71
1
loadUser 중 Missing attribute 'preferred_username' in attributes 에러 발생
0
72
2
JWT 조회 에 대한 질문
0
67
1
password grant 방식 에러 응답
0
83
3
FormLoginConfigure에서 생성하는 필터
0
72
2
현업에서 springboot를 3.5.5 를 사용해서 공부중인데...
0
280
2
Jdbc 관련 강의 및 깃헙 문의
0
73
1
OAuth2AuthorizedClient 이해 및 활용 강의 내용 질문
0
207
1
UserInfo 엔드포인트 요청 실습
0
71
1
RFC 문서에서의 AccessToken 발급 방식 궁금한점
0
147
1
강의자료.zip 를 다운로드 받았는데 압축이 풀리지 않습니다. 확인 부탁드려요
0
133
2
OIDC SSO 관련 질문 입니다.
0
128
1
AuthenticationEntryPoint 강의 누락 문의
0
118
1
cors설정방법
0
113
1
jwt decoder 토큰 검증 시 질문
0
217
1
클라이언트에서 userinfo 엔드포인트 호출 시 질문
0
182
2
JOSE 구성요소의 api에 관한 질문
0
137
2
스프링 부트 3버전으로 따라가시는 분들 참고하세요
1
522
1
CustomOAuth2AuthenticationFilter 구현 중 질문
0
139
2
FormLogin과 Oauth2Client 둘 중 사용하는 시점
0
120
1
postman userinfo 엔드포인트 질문
0
122
2
강의 수강신청하고 듣기 전입니다 질문있습니다.
0
108
1
인증 코드를 통해 발급 받은 토큰의 관리
0
195
1
SPA의 로그인 페이지 사용하면서 자체 인가 서버 구성하는 법
0
243
1

