【发布时间】:2014-11-17 22:50:12
【问题描述】:
如何在 Spring Security OAuth-2 Rest 应用程序中允许特定 URL 中的公共访问。
我已将所有以 /rest/** 开头的 URL 设为安全,但希望将 /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()
;
}
}
对/rest/about 的GET 请求仍然返回401 Unauthorized - "error":"unauthorized","error_description":"Full authentication is required to access this resource"
【问题讨论】:
标签: spring rest spring-mvc spring-security oauth-2.0