Я пытаюсь отфильтровать URL через @EnableActiveDirectoryOAuth2ResourceServer
. Я настроил компонент типа ResourceServerConfigurer
в соответствии с документацией, но по какой-то причине я получаю следующую ошибку:
Caused by: java.lang.IllegalStateException: Can't configure antMatchers after anyRequest
Код:
@EnableActiveDirectoryOAuth2ResourceServer
@EnableWebSecurity
public class OAuthConfiguration {
@Bean
public ResourceServerConfigurer resourceServerConfigurer() {
return new ResourceServerConfigurerAdapter() {
@Override
public void configure(HttpSecurity http) throws Exception {
http.csrf()
.disable()
.requestMatcher(httpGetMethodForPath("/url1"))
.requestMatcher(httpGetMethodForPath("/url2"))
.requestMatcher(httpGetMethodForPath("/url3"))
.authorizeRequests()
.anyRequest().access("#oauth2.isClient() and #oauth2.hasScope('myscope')");
}
};
}
private RequestMatcher httpGetMethodForPath(String URI) {
return request -> request.getRequestURI().contains(URI) && HttpMethod.GET.name().equalsIgnoreCase(request.getMethod());
}
}