• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    해결됨

지원중단

22.05.26 20:19 작성 조회수 1.77k

1

- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요!
- 먼저 유사한 질문이 있었는지 검색해보세요.
- 서로 예의를 지키며 존중하는 문화를 만들어가요.
- 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요.
public class SecurityConfig extends WebSecurityConfigurerAdapter
에서
WebSecurityConfigurerAdapter
 
이게 지원중단이라떠서 더이상 진행이 불가능한데 어떻게 해결할 수 있나요?
 
 
 
 
 

답변 2

·

답변을 작성해보세요.

3

phj2784님의 프로필

phj2784

2022.05.29

스프링 시큐리티 5.7.x 부터 WebSecurityConfigurerAdapter 는 Deprecated 되었습니다.

찾아보니 상황에 따라 SecurityFilterChain 과 WebSecurityCustomizer 를 빈으로 등록해 사용하는 방식을 권장하는 것 같아 저는 아래 코드처럼 사용하고 있습니다.

 

https://spring.io/blog/2022/02/21/spring-security-without-the-websecurityconfigureradapter

@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
public class SecurityConfig {

private final AccountService accountService;
private final DataSource dataSource;

/**
* Spring Security 5.7.x 부터 WebSecurityConfigurerAdapter Deprecated.
* -> SecurityFilterChain, WebSecurityCustomizer 를 상황에 따라 빈으로 등록해 사용한다.
*/
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http.authorizeRequests()
.mvcMatchers("/", "/login", "/sign-up", "/check-email", "/check-email-token",
"/email-login", "/check-email-login", "login-link", "/profile/*").permitAll()
.mvcMatchers(HttpMethod.GET, "/profile/*").permitAll()
.anyRequest().authenticated()
.and()
.formLogin().loginPage("/login").permitAll()
.and()
.logout().logoutSuccessUrl("/")
.and()
.rememberMe().userDetailsService(accountService).tokenRepository(tokenRepository())
.and().build();
}

@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring()
.mvcMatchers("/node_modules/**")
.requestMatchers(PathRequest.toStaticResources().atCommonLocations());
}
}

감사합니다. WebSecurityConfigurerAdapter 문서에서도 이 방법을 권장하고 있습니다.

https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurerAdapter.html

0

스프링님의 프로필

스프링

2022.05.27

저도 궁금합니다!