【发布时间】:2019-12-12 20:28:12
【问题描述】:
我必须在一堆未回答的帖子中添加另一个帖子,表明同样的问题。我正在使用 Spring Boot 2.1.6.RELEASE 和 spring-security-oauth2 2.1.5.RELEASE。我有以下资源配置:
@Configuration
public class RdfResourceServerConfig extends ResourceServerConfigurerAdapter
{
@Override
public void configure(HttpSecurity httpSecurity) throws Exception
{
httpSecurity
.csrf().disable()
.authorizeRequests().antMatchers("/, /**/test/**").permitAll()
.and().authorizeRequests().anyRequest().authenticated();
}
}
基于此配置,我希望http://localhost:8080/.../test/ 的 GET 是允许的,但它返回 HTTP 401:
{
"error": "unauthorized",
"error_description": "Full authentication is required to access this resource"
}
当然,我的 Application 类声明了所有必需的注解:
@SpringBootApplication
@EnableResourceServer
public class ReferenceDataFactoryApplication extends SpringBootServletInitializer
{
public static void main(String[] args)
{
SpringApplication.run(ReferenceDataFactoryApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder)
{
return builder.sources(ReferenceDataFactoryApplication.class);
}
...
}
非常感谢您让我知道我做错了什么。
亲切的问候,
尼古拉斯
【问题讨论】:
-
您的网址可能与
/, /**/test/**模式不匹配。你最好分成两个不同的模式 -
就是这样,非常感谢。但是我见过类似的东西: .antMatchers("/", "/favicon.ico", "/**/*.png", "/**/*.gif", "/**/*.svg ", "/**/*.jpg", "/**/*.html", "/**/*.css", "/**/*.js") .permitAll() 不知道怎么做投票反对这个解决方案...
标签: java spring-boot spring-security spring-security-oauth2