Error

[SpringBoot - - 에러 해결] Caused by: java.lang.IllegalStateException: Can't configure anyRequest after itself

chea-young

1. 에러 메시지

Caused by: java.lang.IllegalStateException: Can't configure anyRequest after itself


2. 원인

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Autowired private CustomOauth2UserService customOauth2UserService;
 
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .csrf().disable()
                .headers().frameOptions().disable() // h2-console 화면을 사용하기 위해 해당 옵션 disable
                .and()
                .authorizeRequests()// URL별 권한 권리
                .antMatchers("/","/css/**","/images/**","/js/**","/h2-console/**").permitAll()
                .antMatchers("/api/v1/**").hasRole(Role.USER.name()) // /api/v1/** 은 USER권한만 접근 가능
                .anyRequest().authenticated() // anyRequest : 설정된 값들 이외 나머지 URL 나타냄, authenticated : 인증된 사용자
                .and()
                .logout()
                .logoutSuccessUrl("/")
                .and()
                .oauth2Login()
                .userInfoEndpoint() // oauth2 로그인 성공 후 가져올 때의 설정들
                // 소셜로그인 성공 시 후속 조치를 진행할 UserService 인터페이스 구현체 등록
                .userService(customOauth2UserService); // 리소스 서버에서 사용자 정보를 가져온 상태에서 추가로 진행하고자 하는 기능 명시
 
        super.configure(http);
    }
}
 

 

configure(http) method 에서 .authorizeRequests().anyRequest().authenticated() 를 호출하고 있기 때문에 security configuration 설정을 커스텀할 때는 super.configure(http)를 또 호출하면 오류가 발생한다.

 


3. 해결

super.configure(http) 를 지운다.