SpringBoot Security Adepter
최신버전의 스프링 시큐리티에서는 기존에 설정을 담당해주던 WebSecurityConfigurerAdapter 메소드가 사용되지 않게 바뀌었다.
원래부터 이렇게 사용해라 라는 가이드라인이 내려와 있었지만, 예전에 사용하던 방식을 고수하던것인데, 결국 최신버전에서는 해당 기능을 아예 Deprecated상태로 내려버렸다.
@RequiredArgsConstructor
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/**")
.authorizeRequests()
.antMatchers("/api/v2/**").hasAuthority(USER.name());
http.httpBasic().disable()
.formLogin().disable()
.cors().disable()
.csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.anyRequest().permitAll()
.and()
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
}
}
기존에 사용하던 위와같은 방식을 최신버전에서는 사용하지 못한다는 뜻이다.
해결방법
결국 Spring에서 원하는 것은, 이런 무분별한 메소드들을 { . } 을 이용해 이어붙이는 것 보다, 메서드들관에 연관성을 조금 더 중요시하게 여겨서 사용하라는 취지이다.
일단은 공식문서에서 요구하는 바 대로 SecurityFfilterChain을 사용하여 Configure를 대신하자.
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests((authz) -> authz
.anyRequest().authenticated()
)
.httpBasic(withDefaults());
}
이처럼 바꿔주면 된다.
and, antMatchers 같이 아예 사라지고 다른것으로 대체된 것들도 많으니, 이는 공식문서에서 파악하는것이 제일 편하다.
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
'SpringBoot > 프로젝트 게시판 만들기' 카테고리의 다른 글
[HQL] QueryDSL 프레임워크 (0) | 2023.08.28 |
---|---|
OAuth 2.0 이라는게 뭘까? (0) | 2023.08.23 |
SpringbootTest 오류, JPA 매핑 오류 (0) | 2023.07.14 |
React 와 Spring 환경 구성 세팅 (0) | 2023.07.13 |
Spring 쇼핑몰 프로젝트 - MySQL 연동하기 (0) | 2023.07.12 |