oauth 기능을 추가하고 코드를 빌드하는 과정에서 오류 발생함
Caused by: org.springframework.beans.BeanInstantiationException:
Failed to instantiate [javax.servlet.Filter]:
Factory method 'springSecurityFilterChain' threw exception;
nested exception is java.lang.IllegalStateException:
Can't configure anyRequest after itself
@RequiredArgsConstructor
@EnableWebSecurity // Spring Security 설정 활성화
public class SecurityConfig{// extends WebSecurityConfigurerAdapter {
private final 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("USER") // /api/v1/** 은 USER권한만 접근 가능
.anyRequest().authenticated() // anyRequest : 설정된 값들 이외 나머지 URL 나타냄, authenticated : 인증된 사용자
.and()
.logout()
.logoutSuccessUrl("/")
.and()
.oauth2Login()
.userInfoEndpoint() // oauth2 로그인 성공 후 가져올 때의 설정들
// 소셜로그인 성공 시 후속 조치를 진행할 UserService 인터페이스 구현체 등록
.userService(customOAuth2UserService); // 리소스 서버에서 사용자 정보를 가져온 상태에서 추가로 진행하고자 하는 기능 명시
// super.configure(http);
}
}