작성
·
325
0
@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("인증이나 권한이 필요한 주소로 요청됨.");
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 호출