我们已经看到了许多与端点有关的1.5+版本的问题。经历了很多次之后,我们仍然不知所措。
我们的目标是:
HttpSecurity)我们试过:
WebSecurityConfigurerAdapter并配置WebSecurity对象以忽略/health端点的安全性,然后根据Routing multiple URLs to Spring Boot Actuator's health endpoint将单独的端点映射到/health端点,希望启用安全路径。security.oauth2.resource.filter-order=3符合https://github.com/spring-projects/spring-boot/issues/5072中的建议。这将OAuth2AuthenticationProcessingFilter放在Actuator的Mvc端点之前,并允许处理包含预验证的Authorization: Bearer ...头(例如JWT授权)的请求。但是,它规定所有请求都包含授权,否则,FilterSecurityInterceptor将触发Secure object: FilterInvocation: URL: /health; Attributes: [#oauth2.throwOnError(authenticated)]和AccessDeniedException。使用/health和OAuth2的基本身份验证对其他一切都是不可行的(参见Spring boot oauth2 management httpbasic authentication & https://github.com/spring-projects/spring-boot/issues/5072)。
我们一直在讨论的问题是,我们如何获得:
/health端点的匿名请求,以充当非安全Authorization: Bearer ...头的请求)给/health端点,而没有适当的授权或角色作为不安全的。Authorization: Bearer ...标头的请求)给具有/health端点的具有适当授权或角色作为安全的的请求。我们可以很容易地允许任何请求访问/health,方法如下:
@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) throws Exception {
super.configure(web);
web.ignoring().antMatchers(HttpMethod.GET, "/health", "/info");
}
}仅仅作为一种准备/活性的探测,这是非常有效的。但是,当用户实际经过身份验证时,它并没有提供查看哪些支持服务可能行为不当的好处。
提前感谢!
发布于 2017-06-20 14:39:07
我遇到了类似的情况,这在一定程度上起了作用:为执行器添加了一个黑客访问规则,例如:#oauth2.clientHasRole('ROLE_CLIENT')或hasRole('ROLE_ANONYMOUS'),它允许为执行器端点填充安全上下文(对于经过身份验证和未经身份验证的请求),并调整“敏感”执行器端点配置。如果您启用管理安全性并将其标记为非敏感的,/health应该返回匿名的基本信息和身份验证的完整信息。您仍然需要保持过滤器配置。
发布于 2018-10-19 14:07:55
试试这个,为我工作
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/**").authorizeRequests()
.antMatchers("/actuator/**","/assets/**")
.permitAll()
........
;
}https://stackoverflow.com/questions/44164258
复制相似问题