ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

使用oauth2范围代替角色来保护弹簧执行器管理端点

2019-11-11 18:19:35  阅读:225  来源: 互联网

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


我最近已升级到Spring Cloud Dalston,这意味着Spring Boot 1.5.1,并且我无法再通过检查oauth2范围来保护管理端点.它曾在Spring Cloud Camden中工作.

这是之前起作用的配置:

@Configuration
public class SecurityConfiguration extends ResourceServerConfigurerAdapter {

    @Value("${management.context-path}")
    private String managementContextPath;

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests() 
                // some paths I don't want to secure at all
                .antMatchers("/path1/**", "/path2/**").permitAll() 
                // access to health endpoint is open to anyone
                .antMatchers(HttpMethod.GET, managementContextPath + "/health").permitAll() 
                // but app.admin scope is necessary for other management endpoints
                .antMatchers(managementContextPath + "/**").access("#oauth2.hasScope('my-super-scope')") //
                // And we make sure the user is authenticated for all the other cases
                .anyRequest().authenticated();
    }
}

这是配置的重要部分:

security:
  oauth2:
    client:
      clientId: a-client
      clientSecret: the-client-password
    resource:
      tokenInfoUri: http://my-spring-oauth2-provider/oauth/check_token

management:
  context-path: /my-context
  security:
    enabled: true
endpoints:
  health:
    sensitive: false

当我尝试在/ my-context / refresh上进行POST时,即使我提供了有效的OAuth2令牌,也会收到HTTP 401“需要完整身份验证”

查看日志,我发现我的请求被认为是匿名的,检查FilterChainProxy日志后发现没有调用OAuth2AuthenticationProcessingFilter.经过一些挖掘I found that I could change the oauth2 resource filter order,所以我尝试了一下,现在我有了OAuth2身份验证,是的,完成了吗?

哼,不,现在我的访问权限被拒绝.用户必须具有以下角色之一:ACTUATOR错误.

我尝试了其他一些方法,包括禁用管理安全性(但是我的规则未应用且访问权限向所有人开放),(ugh)@Order(无更改),甚至还有,瞧瞧,reading and applying the documentation都说:

To override the application access rules add a @Bean of type
WebSecurityConfigurerAdapter and use
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER) if you don’t want to
override the actuator access rules, or
@Order(ManagementServerProperties.ACCESS_OVERRIDE_ORDER) if you do
want to override the actuator access rules.

但这并没有改变错误:用户必须具有以下角色之一:ACTUATOR

有人有解决方法/想法吗?

更新:我也在使用Zuul,所以我终于创建了一条到我所需端点的特定zuul路由(在我的情况下为云总线刷新),在其他未公开的后端服务上不受保护,并使用oauth2保护了该zuul路由.

不过,如果有人找到解决方法,我将在这里留下这个问题,可能会有用.

解决方法:

可能明显是队长,但请参见http://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-monitoring.html.您可以使用management.security.roles覆盖角色,并简单地添加Oauth2凭据具有的任何角色.

标签:spring-boot,spring-security,spring-cloud,spring-security-oauth2,spring
来源: https://codeday.me/bug/20191111/2021751.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有