2014-09-23 7 views
12

Wie erlaube ich öffentlichen Zugriff in einer bestimmten URL in einer Spring Security OAuth-2 Rest-Anwendung.Spring OAuth 2: Öffentlicher Zugriff auf eine Ressource

Ich habe alle URLs mit /rest/** gesichert gestartet, möchte aber /rest/about öffentlich machen, also würde ich nicht verlangen, dass der Benutzer sich authentifizieren, um darauf zuzugreifen. Ich versuchte mit permitAll(), aber es erfordert immer noch das Token in der Anfrage. Dies ist meine HttpSecurity Konfiguration:

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

Eine GET-Anfrage an /rest/about noch gibt 401 Unauthorized - "error":"unauthorized","error_description":"Full authentication is required to access this resource"

Antwort

20

die Antwort gefunden. Ich brauchte nur anonymous() hinzuzufügen:

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

Haben Sie die Antwort aus: https://stackoverflow.com/a/25280897/256245

Verwandte Themen