• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

WebSecurityConfigurerAdapter deprecated

22.10.19 12:01 작성 조회수 1.99k

0

WebSecurityConfigurerAdapter 가 이제 더 이상 지원을 하지 않는다고 하여 WebSecurityFilterChain으로 하래서 시도중인데 계속하여 401 에러가 뜹니다...

@EnableWebSecurity
public class SecurityConfig {
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception{
        http
                .authorizeRequests() 
                .antMatchers("api/hello").permitAll()
                .anyRequest().authenticated(); 

        return http.build();
    }

}

답변 3

·

답변을 작성해보세요.

1

Kang ho Lee님의 프로필

Kang ho Lee

2023.02.25

그리고 antMatchers도 deprecated 되어서 밑에와 같은 방식으로 해주시면 진행 될거에요.

@Configuration
@EnableWebSecurity
public class SecurityConfig {

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http
                .authorizeHttpRequests()
                .requestMatchers("/api/hello").permitAll()
                .anyRequest().authenticated();

        return http.build();
    }
}

0

준준님의 프로필

준준

2022.12.25

api 앞에 "/" 빠져서 그런거 아닌가요?

0

배상혁님의 프로필

배상혁

2022.10.28

@EnableWebSecurity 대신에 @Configuration 한번 달아보실래요?