• 카테고리

    질문 & 답변
  • 세부 분야

    기타 (개발 · 프로그래밍)

  • 해결 여부

    미해결

스프링 시큐리티 WebSecurityConfigurerAdapter deprecated 대체 코드

23.06.05 17:56 작성 조회수 1.44k

0

- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요!
- 먼저 유사한 질문이 있었는지 검색해보세요.
- 서로 예의를 지키며 존중하는 문화를 만들어가요.
- 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요.

 

책임 연쇄 패턴에서 스프링 시큐리티 예제코드 중에 WebSecurityConfigurerAdapter를 사용하는 코드가 있는데, 최신 버전을 사용하는 경우에 deprecated되어 사용하지 못하는 듯 합니다.

 

< 대체코드 >

@Configuration
@EnableWebSecurity
public class SecurityConfig {

  /**
   * WebSecurityConfigurerAdapter가 Spring Security 5.7.0-M2부터 deprecated 됨.
   * component-based security configuration으로의 사용자 전환 격려 위함.
   * 따라서 아래와 같이 bean으로 등록하여 사용.
    */
  @Bean
  public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
    http
      .authorizeHttpRequests(auth -> auth.anyRequest().permitAll());

    return http.build();
  }

}

이 경우, 기존 코드를 위의 코드로 작성하시면 됩니다. : )

답변 1

답변을 작성해보세요.

0

인프런 AI 인턴님의 프로필

인프런 AI 인턴

2023.06.07

안녕하세요, 인프런 AI 인턴이에요.

WebSecurityConfigurerAdapter는 Spring Security 5.7.0-M2부터 deprecated 되었습니다. 이에 대한 대안으로는 component-based security configuration을 사용하는 것을 권장하고 있습니다.

따라서 대체로 사용할 수 있는 코드로는 아래와 같이 bean으로 등록하여 사용하는 것입니다.

@Configuration
@EnableWebSecurity
public class SecurityConfig {

  /**
   * WebSecurityConfigurerAdapter가 Spring Security 5.7.0-M2부터 deprecated 됨.
   * component-based security configuration으로의 사용자 전환 격려 위함.
   * 따라서 아래와 같이 bean으로 등록하여 사용.
    */
  @Bean
  public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
    http
      .authorizeHttpRequests(auth -> auth.anyRequest().permitAll());

    return http.build();
  }

}

위와 같이 코드를 작성하면 기존 코드에서 사용하던 WebSecurityConfigurerAdapter를 대체할 수 있습니다. 감사합니다.