sungwon-097 / Spring_Security

1 stars 0 forks source link

SpringSecurity : deprecated issue #21

Closed sungwon-097 closed 1 year ago

sungwon-097 commented 2 years ago
// before
public class SecurityConfig extends WebSecurityConfigurerAdapter{   
...
          @Override
      protected void configure(HttpSecurity http) throws Exception {
            ...
            .addFilter(new JwtAuthenticationFilter(authenticationManager()))
            ...
          }
}

// after
public class SecurityConfig {
...
          @Bean
      SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
            ...
            .apply(new MyCustomDsl()) // 커스텀 필터 등록
            ...
          }

          public class MyCustomDsl extends AbstractHttpConfigurer<MyCustomDsl, HttpSecurity> {
        @Override
        public void configure(HttpSecurity http) throws Exception {
            AuthenticationManager authenticationManager = http.getSharedObject(AuthenticationManager.class);
            http
                    .addFilter(corsConfig.corsFilter())
                    .addFilter(new JwtAuthenticationFilter(authenticationManager))
                    .addFilter(new JwtAuthorizationFilter(authenticationManager, userRepository));
        }
    }
}
sungwon-097 commented 1 year ago

https://github.com/sungwon-097/Spring_Security/blob/main/security1/src/main/java/com/cos/security1/config/SecurityConfig.java