본문 바로가기
오류

'org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter' is deprecated

by 뇽꾸리 2022. 7. 21.
반응형

In Spring Security 5.7.0-M2 we deprecated the WebSecurityConfigurerAdapter

우선 deprecated 여도 항상 작동은 잘하지만 기분나빠서 변경해준다.

 

  • before  
 @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.csrf().disable()

                //h2
                .headers()
                .frameOptions()
                .sameOrigin()

                // 시큐리티는 기본적으로 세션을 사용
                // 여기서는 세션을 사용하지 않기 때문에 세션 설정을 Stateless 로 설정
                .and()
                .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()

                //권한
                .authorizeRequests()
                .antMatchers("/resources/**","/css/**", "/images/**","/js/**", "/h2-console/**", "/v2/api-docs", "/configuration/**", "/swagger*/**", "/webjars/**")
                .permitAll()
                //.antMatchers("/**").hasRole("USER")
                .anyRequest().authenticated()   // 나머지 API 는 전부 인증 필요
                .and()
                .addFilterBefore(new JwtAuthenticationFilter(jwtTokenProvider,userDetailService), UsernamePasswordAuthenticationFilter.class)
              ;
    }
  • after 
  @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http
                .csrf().disable()
                .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                .authorizeHttpRequests((authz) ->
                        authz.antMatchers("/resources/**","/css/**", "/images/**","/js/**", "/h2-console/**", "/v2/api-docs", "/configuration/**", "/swagger*/**", "/webjars/**")
                                .permitAll()
                                .anyRequest().authenticated()
                )
                .httpBasic(withDefaults());
        return http.build();
    }
반응형

댓글