-
카테고리
-
세부 분야
백엔드
-
해결 여부
미해결
질문이 있습니당.
22.05.13 15:06 작성 조회수 219
0
질문이 있습니당.
BasicAuthenticationFilter는 인증이 필요한 주소로 요청했을 때만 실행된다고 하셨는데
/home 으로 요청을 해도 doFilterInternal가 실행되는 것 같습니다. 제가 잘 못 이해한것인지 해서 질문드립니다..!
@Override
protected void configure(HttpSecurity http) throws Exception {
http.addFilterBefore(new MyFilter3(), SecurityContextPersistenceFilter.class);
http.csrf().disable();
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.addFilter(corsFilter)
.formLogin().disable()
.httpBasic().disable()
.addFilter(new JwtAuthenticationFilter(authenticationManager()))
.addFilter(new JwtAuthorizationFilter(authenticationManager(), userRepository))
.authorizeRequests()
.antMatchers("/api/v1/user/**")
.access("hasRole('ROLE_USER') or hasRole('ROLE_MANAGER') or hasRole('ROLE_ADMIN')")
.antMatchers("/api/v1/manager/**")
.access("hasRole('ROLE_MANAGER') or hasRole('ROLE_ADMIN')")
.antMatchers("/api/v1/admin/**")
.access("hasRole('ROLE_ADMIN')")
.anyRequest().permitAll();
}
@Slf4j
public class JwtAuthorizationFilter extends BasicAuthenticationFilter {
private UserRepository userRepository;
public JwtAuthorizationFilter(AuthenticationManager authenticationManager, UserRepository userRepository) {
super(authenticationManager);
this.userRepository = userRepository;
}
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
log.info("인증이나 권한이 필요한 주소로 요청됨.");
http://localhost:7979/home 요청 =>
2022-05-13 2022-05-13 15:04:12.889 INFO 9192 --- [nio-7979-exec-5] com.cos.jwt.filter.MyFilter3 : MyFilter3 호출
2022-05-13 15:04:12.889 INFO 9192 --- [nio-7979-exec-5] com.cos.jwt.filter.MyFilter3 : authorization=
2022-05-13 15:04:12.889 INFO 9192 --- [nio-7979-exec-5] c.c.j.config.jwt.JwtAuthorizationFilter : 인증이나 권한이 필요한 주소로 요청됨.
2022-05-13 15:04:12.889 INFO 9192 --- [nio-7979-exec-5] c.c.j.config.jwt.JwtAuthorizationFilter : jwtHeader=
2022-05-13 15:04:12.890 INFO 9192 --- [nio-7979-exec-5] com.cos.jwt.filter.MyFilter1 : MyFilter1 호출
2022-05-13 15:04:12.890 INFO 9192 --- [nio-7979-exec-5] com.cos.jwt.filter.MyFilter2 : MyFilter2 호출
답변을 작성해보세요.
답변 2