반응형
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();
}
반응형
'오류' 카테고리의 다른 글
Swagger-ui.html 404 not found error (0) | 2022.08.19 |
---|---|
Each child in a list should have a unique "key" prop. (0) | 2022.08.18 |
could not open `C:\Program Files\Java\jre1.8.0_311\lib\amd64\jvm.cfg' (0) | 2022.07.07 |
이 사이트에 연결할 수 없습니다. localhost 연결을 거부했습니다 (0) | 2022.06.28 |
java.util.NoSuchElementException: No value present (0) | 2022.06.22 |
댓글