728x90
커스텀 인증 필터를 만들기 위해서
AuthenticationManager를 필터에 넘겨주고 싶을 때
1. 일단 AuthenticationManager은 기본적으로 Bean 이 아니다
2. (1) 이유로 필터를 Bean으로 생성할 시 AuthenticationManager은 주입을 받을 수 없다
물론 Bean 으로 등록할 수 있긴하지만 초기화 과정의 AuthenticationManager과
Bean 으로 등록한 AuthenticationManager 은 서로 다른 객체가 된다
일단 공유 방법을 보자
공유 객체로 인증매니저빌더를 가져와서
빌드하는데
이때 일렉트릭 쇼크마냥 메서드 호출이 엄청 일어나는데
여기선, 제일 마지막 메서드가 핵심이다
build() > doBuild() > init() ... configure() ... performBuild()
performBuild() 의 리턴값이 AuthenticationManager 이다
구현체는 ProviderManager
따라서 다른 코드에서 AuthenticationManager 가 필요하다면 HttpSerucity 만 주입 받을 수 있다면
AuthenticationManagerBuilder 의 getObject() 메서드로 AuthenticationManager 를 가져 올 수 있다
또 build() 를 호출하지 말자
728x90
'개발 > spring-security' 카테고리의 다른 글
spring security 와 jwt 주저리 (0) | 2024.06.01 |
---|---|
JWT 토큰 (0) | 2024.06.01 |
SpringSecurity - CORS 허용 (0) | 2024.05.12 |
AuthenticationManager 를 Bean 등록해보자 (0) | 2024.05.11 |
GET 방식으로 로그아웃 처리를 해보자 (0) | 2024.05.07 |