【问题标题】:Spring Boot with Spring Security OAuth2 and Actuator带有 Spring Security OAuth2 和 Actuator 的 Spring Boot
【发布时间】:2017-02-16 14:55:36
【问题描述】:

我正在尝试弄清楚如何使用 Spring Security OAuth2 的 @EnableResourceServer,同时保持默认 Spring Boot 的执行器安全性不变。我使用 Spring Boot 1.5.1 和默认版本的依赖项。我有以下配置

@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 的信息。我做错了什么吗?我还需要一些其他配置吗?

【问题讨论】:

  • 你要什么网址?我希望 .antMatchers("//**").permitAll()

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


【解决方案1】:

我期待这样的事情 -

@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();
}

【讨论】:

  • 我至少希望不需要为执行器显式设置安全性(我在 /about 下都有这些)。问题是每个执行器端点的执行器安全设置不同。例如,/health 端点是公开可用的,但 /metrics 不是,我宁愿不(如果可能)重新做所有的安全配置。
【解决方案2】:

您必须将管理角色添加到应用程序属性中,例如 management.security.roles=ROLE_SOMEROLENAME 您的用户应该拥有此角色才能访问执行器端点。您还可以使用此属性 management.context-path=/myactuator 设置执行器端点的路径

【讨论】:

    猜你喜欢
    • 2017-10-02
    • 2017-09-11
    • 1970-01-01
    • 2016-10-02
    • 2018-01-29
    • 2017-07-22
    • 2017-08-01
    • 1970-01-01
    • 2020-06-20
    相关资源
    最近更新 更多