首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring OAuth 2:对资源的公共访问

Spring OAuth 2:对资源的公共访问
EN

Stack Overflow用户
提问于 2014-09-24 00:21:50
回答 1查看 10.8K关注 0票数 16

如何在Spring Security OAuth-2 Rest应用程序中的特定URL中允许公共访问。

我有所有的URL开始与/rest/**安全,但想让/rest/about公开,所以我不需要用户进行身份验证来访问它。我尝试使用permitAll(),但它仍然需要请求中的令牌。这是我的HttpSecurity配置:

代码语言:javascript
复制
@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"

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-24 01:38:27

找到答案了。我只需要添加anonymous()

代码语言:javascript
复制
public void configure(HttpSecurity http) throws Exception {
        http
                .anonymous().and()
                .authorizeRequests()
                .antMatchers("/rest/about").permitAll()
                .antMatchers("/rest/**").authenticated()
                ;
    }

答案来自:https://stackoverflow.com/a/25280897/256245

票数 33
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26000040

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档