【发布时间】:2017-07-05 23:28:03
【问题描述】:
我最近升级到 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 上发布时,我得到一个 HTTP 401“需要完整身份验证”,即使我提供了一个有效的 OAuth2 令牌
查看日志我看到我的请求被认为是匿名的,检查 FilterChainProxy 日志发现 OAuth2AuthenticationProcessingFilter 没有被调用。经过一番挖掘I found that I could change the oauth2 resource filter order,所以我尝试了一下,现在我有了 OAuth2 身份验证,是的,完成了吗?
嗯,不,现在我有一个Access is denied. User must have one of the these roles: ACTUATOR 错误。
我尝试了其他一些事情,包括禁用管理安全性(但我的规则不适用,并且对所有人开放),玩(呃)@Order(没有变化),甚至,你瞧,@ 987654322@ 上面写着:
要覆盖应用程序访问规则,请添加 @Bean 类型 WebSecurityConfigurerAdapter 和使用 @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER) 如果你不想 覆盖执行器访问规则,或 @Order(ManagementServerProperties.ACCESS_OVERRIDE_ORDER) 如果你这样做 想要覆盖执行器访问规则。
但这并没有改变错误:User must have one of these roles: ACTUATOR
有人有解决方法/想法吗?
更新:我也在使用 Zuul,所以我最终创建了一个特定的 zuul 路由到我需要的端点(在我的例子中是云总线刷新),不受其他未公开的其他后端服务的保护,并保护了那个 zuul使用 oauth2 路由。
不过,我还是把这个问题留在这里,如果有人找到解决方法,可能会有用。
【问题讨论】:
-
这个运气好吗?我面临着类似的问题。
-
不,很遗憾,我希望 Dalston.RC1 能解决这个问题,但没有运气。我可能很快会再次检查,但如果你在此期间发现什么我真的很感兴趣:)
标签: spring spring-boot spring-security spring-cloud spring-security-oauth2