春季安全性OAuth2:permitAll()对我不起作用(HTTP 401用于不受保护的端点)

时间:2019-08-05 10:13:50

标签: java spring-boot spring-security spring-security-oauth2

我必须在未作答的那一堆中添加另一个帖子,以表示相同的问题。我正在使用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);
  }
  ...
}

在此先感谢您让我知道我在做错什么。

亲切的问候,

尼古拉斯

1 个答案:

答案 0 :(得分:1)

如注释 string filePath = @"path_to_file"; string url = "http://00.00.00.00:0000/api/apiName/building/"; string usr = "someuser"; string pwd = "somepassword"; RestClient client = new RestClient(url); client.Authenticator = new HttpBasicAuthenticator(usr, pwd); RestRequest request = new RestRequest(url); request.Method = Method.POST; request.AddFile(Path.GetFileNameWithoutExtension(filePath), filePath); try { IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); } catch (Exception ex) { Console.WriteLine(ex); } Console.ReadLine(); 中所述,这不是有效的模式。 AntMatcher每个方法调用采用1个字符串模式。

”/, /**/test/**”