1

我想弄清楚如何使用弹簧安全OAuth2的@EnableResourceServer,同时保持默认的春季启动的执行器安全未触及。我正在使用Spring Boot 1.5.1和依赖项的默认版本。我有以下配置弹簧启动与春季安全OAuth2和执行器

@Configuration 
@EnableResourceServer 
@EnableWebSecurity(debug=true) 
@EnableGlobalMethodSecurity 
public class OAuthConfig extends ResourceServerConfigurerAdapter { 

    @Override 
    public void configure(final HttpSecurity http) throws Exception { 
     http 
     .authorizeRequests() 
     .antMatchers(HttpMethod.OPTIONS, "/**").permitAll() 
     .mvcMatchers("/resource/{type}").permitAll() 
     .antMatchers("/resource/data/**").authenticated(); 
    } 
} 

我没有明确配置任何其他安全设置。我想想到执行器端点将继续得到适当的保护,但我得到401,并且在检查安全调试日志时,它没有显示任何关于HTTP Basic的信息。任何我做错了什么?我需要一些其他配置?

+0

您请求什么网址?我期望.antMatchers(“/ /**”)。permitAll() – farrellmr

回答

0

标识想到这样的事情 -

@Override 
public void configure(final HttpSecurity http) throws Exception { 
    http 
    .authorizeRequests() 
    .antMatchers(HttpMethod.OPTIONS, "/**").permitAll() 
    .antMatchers("/health/**").permitAll() 
    .mvcMatchers("/resource/{type}").permitAll() 
    .antMatchers("/resource/data/**") 
    .anyRequest().authenticated(); 
} 
+0

我至少希望我不需要明确地设置执行器的安全性(我有这一切/大约)。问题是执行器安全设置每个执行器端点设置不同。例如,'/ health'端点是公开可用的,但'/ metrics'不是,我宁愿不(如果可能的话)重新执行所有安全配置。 –

0

您必须添加到应用程序性能管理的角色,像这样management.security.roles=ROLE_SOMEROLENAME用户应该持有这个角色才能够进入执行器的端点。您也可以使用此属性设置执行器端点的路径management.context-path=/myactuator