restSecurityFilterChian에서 addFilterBefore와 authenticationManger 질문
210
작성한 질문수 50
httpSecurity.formLogin()을 설정해주지 않으면, securityFilterChain에 UsernamePasswordAuthenticationFilter가 없지 않나요?
restAuthenticationFilter를 UsernamePasswordAuthenticationFilter 앞에 추가할 수 있나요?
restAuthenticationFilter에서 authenticationManager를 사용할 수 있도록 설정해주었는데, httpSecurity에 또 세팅해줘야 하는 이유가 있는걸까요?
답변 1
0
네
필터의 순서를 정할 때는 스프링 시큐리티가 내부적으로 관리하는 모든 필터에 대한 순서를 이미 정해 놓고 저장하고 있습니다.
즉 UsernamePasswordAuthenticationFilter 의 순서가 정해져 있습니다.
그렇기 때문에 httpSecurity.formLogin() 설정과는 별개로 진행이 됩니다.

내부 소스를 보시면 위와 같이 실행이 되는데 registeredFilter 가 UsernamePasswordAuthenticationFilter 이고 이 필터는 filterOrders 에 순서가 이미 저장되어 있습니다.
그리고 authenticationManager 를 httpSecurity에 저장해 주어야 하는 이유는 authenticationManager 를 얻어오는 방법이 httpSecurity 로부터 직접 수동으로 생성해서 얻어오기 때문에 httpSecurity 에 저장해 주어야 하는 과정이 필요하다고 이해하시면 됩니다.
그렇지 않으면 httpSecurity 가 또 authenticationManager 을 얻어오기 위한 생성을 중복으로 하기 때문에 오류가 발생합니다.
이 부분은 강의에서 설명하고 있는 내용으로만 이해하셔도 됩니다. 그렇게 깊이까지는 아실 필요는 없습니다.
0
UsernamePasswordAuthenticationFilter
각 필터마다 필터 순서가 정해져 있고, UsernamePasswordAuthenticationFilter가 SecurityFilterChain에 포함되어 있는 지 여부에 상관 없이,
restAuthenticationFilter를 SecurityFilterChain에 포함한다면 UsernamePasswordAuthenticaionFilter의 앞 순서로 지정하는 거 뿐이다. 이렇게 이해하면 될까요?
AuthenticationManager
HttpSecurity에 AuthenticationManager 설정을 해주지 않으면 AuthenticaionManager 생성을 중복으로 하기 때문에 이미 생성한 AuthenticationManager를 설정해줘야 한다는 말씀 맞을까요?
로그아웃-logout()-2 강에서 겟방식 로그아웃 호출 후 화면이동 질문입니다.
0
35
2
단원별 소스코드
0
64
2
CustomAuthenticationProvider 추가 관련 문의
0
78
2
AOP 의존성 명칭 변경
0
76
1
빈 1개 등록 시 다른 해결 방법
0
70
1
@Bean으로 AuthenticationProvider를 등록 시 http.authenticationProvider 함수를 이용해서 추가해줘야되나요?
0
87
2
OIDC의 id token에 담긴 데이터에 대해
0
78
1
loginPage("/loginPage") 질문드립니다.
0
69
1
@EnableWebSecurity
0
148
1
트랜잭션과 롤백
0
99
1
68. 인증 이벤트 - AuthenticationEventPublisher 활용 강좌 음성 문제
0
91
2
AuthenticationManager 사용 방법
0
153
2
HttpSecurity.authorizeHttpRequests() - 2 강의 부분에 대한 질문
0
108
2
spring security 6.3에서는 HttpSecurity가 만들어지기 전 WebSecurity가 먼저 만들어지는게 맞나요??
0
192
1
init(B Builder), configure(B builder) 에 대하여 질문 드립니다.
0
109
2
메타 주석 질문
0
69
1
동시세션제어 기능에서 로그아웃하기
0
152
3
로그인 후, redirect 에서 error
0
140
3
Session 생성 타이밍에 대한 질문
0
86
2
강의 참고 내용을 개발 로그로 작성해도 될지 문의드립니다.
0
135
2
customAuthentication 관련
0
132
2
authenticationManagerBuilder 주입받은거 vs 만든 거
0
114
1
UserDetailsService()에서 UserDetail이 아닌 타입을 반환할 수 있나요?
0
101
1
9:28 패턴 3의 경우 마지막으로 설정한 것만 적용되는 것 같습니다.
0
162
2





