인프런 커뮤니티 질문&답변

Jeong-Woo Kang님의 프로필 이미지

작성한 질문수

Spring Boot JWT Tutorial

Security 설정, Data 설정

WebSecurityConfigurerAdapter deprecated

22.10.19 12:01 작성

·

2.2K

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

2

Kang ho Lee님의 프로필 이미지

2023. 02. 25. 22:29

그리고 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. 15:37

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

0

배상혁님의 프로필 이미지

2022. 10. 28. 14:39

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