2014-09-23 23 views
12

Spring Spring OAuth-2 Rest uygulamasında belirli bir URL'ye genel erişime nasıl izin verebilirim?Spring OAuth 2: bir kaynağa genel erişim

/rest/** numaralı telefonla başlatılan tüm URL'leri kullanıyorum ancak /rest/about genel kullanıma açmak istiyorum, dolayısıyla kullanıcının kimlik doğrulaması yapmasını istemiyorum. permitAll() kullanmayı denedim, ancak yine de istekte belirtecini gerektirir.

@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() 
       ; 
    } 
} 

/rest/about için GET isteği hala 401 Unauthorized - "error":"unauthorized","error_description":"Full authentication is required to access this resource"

cevap

20

cevap Bulunan döndürür: Bu benim HttpSecurity yapılandırmasıdır. Sadece anonymous() eklemek için gerekli: https://stackoverflow.com/a/25280897/256245

:

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

cevabını aldım

İlgili konular