![Spring Security WebSecurityConfigurerAdapter / cors, csrf Deprecated 해결하기](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FCjYCn%2FbtsrCxEbT1l%2FfDzhFsy46OXLV2k0FroF81%2Fimg.png)
서론
최근 토이 프로젝트 진행중에 간단하게 회원기능을 구현하고자 Security를 사용하는데
이전 사용했던 WebSecurityConfigurerAdapter을 상속받아 구현하던 Config설정에 바뀐 부분이 있고
또한 시큐리티를 통한 권한 확인이나 로그인, 로그아웃 등 기타 작업등은 하지 않을 계획이라
csrf(), cors() disable을 설정하는 과정에서도 Deprecated된 것을 확인하여 기록하고자 함
아래는 각각 WebSecurityConfigurerAdapter와, Spring Security 6.1.2버전에서의
Deprecated API를 정리해둔 공식 docs
https://spring.io/blog/2022/02/21/spring-security-without-the-websecurityconfigureradapter
Spring Security without the WebSecurityConfigurerAdapter
In Spring Security 5.7.0-M2 we deprecated the WebSecurityConfigurerAdapter, as we encourage users to move towards a component-based security configuration. To assist with the transition to this new style of configuration, we have compiled a list of common
spring.io
HttpSecurity (spring-security-docs 6.1.2 API)
securityContext Deprecated, for removal: This API element is subject to removal in a future version. Returns: the SecurityContextConfigurer for further customizations Throws: Exception
docs.spring.io
본론
구글링을 통한 blog나 stackoverflow도 좋지만
아래처럼 공식문서를 통해 간단하게 해결할 수 있는 부분이다.
![](https://blog.kakaocdn.net/dn/CjYCn/btsrCxEbT1l/fDzhFsy46OXLV2k0FroF81/img.png)
![](https://blog.kakaocdn.net/dn/dys3k6/btsrxnWQOro/3q1tsFw7l278GkTMdhMI3k/img.png)
딱히 무언가 권한이나 기타 설정들은 하지 않을 것이기 때문에 아래처럼 Config파일을 구성할 수 있었다.
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception{
return http
.csrf((csrf) -> csrf.disable())
.cors((cors) -> cors.disable())
.build();
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
2023.04 ~ 백엔드 개발자의 기록
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!