Безопасность Spring Boot: не могу настроить antMatchers после любого запроса - PullRequest
0 голосов
/ 15 января 2020

Я пытаюсь отфильтровать 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());
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...