Подтвердить что ты не робот

Spring OAuth 2: открытый доступ к ресурсу

Как разрешить публичный доступ в определенном URL-адресе в приложении Spring Security OAuth-2 Rest.

У меня есть все URL-адреса, начинающиеся с /rest/** protected, но хотели бы сделать /rest/about общедоступным, поэтому я бы не требовал от пользователя аутентификации для доступа к нему. Я попытался использовать permitAll(), но по-прежнему требуется токен в запросе. Это моя конфигурация HttpSecurity:

@Configuration
@EnableResourceServer
protected static class ResourceServerConfiguration extends
        ResourceServerConfigurerAdapter {

    @Override
    public void configure(ResourceServerSecurityConfigurer resources) {
        resources.resourceId(RESOURCE_ID);
    }

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .antMatchers("/rest/about").permitAll()
                .antMatchers("/rest/**").authenticated()
                ;
    }
}

Запрос GET для /rest/about все еще возвращает 401 Unauthorized - "error":"unauthorized","error_description":"Full authentication is required to access this resource"

4b9b3361

Ответ 1

Нашел ответ. Мне просто нужно добавить anonymous():

public void configure(HttpSecurity http) throws Exception {
        http
                .anonymous().and()
                .authorizeRequests()
                .antMatchers("/rest/about").permitAll()
                .antMatchers("/rest/**").authenticated()
                ;
    }

Получил ответ от: fooobar.com/info/311281/...