我正在尝试保护项目Actuators内部的端点Spring Boot。但是,改为使用准备运行的Spring Security配置Actuators:
management:
security:
enabled: true
role: ADMINISTRATOR
这太容易了,我需要插入Actuators我们的自定义安全性(这里是CASSSO)。
首先尝试它是context-path添加Actuators:
management:
security:
enabled: true
role: ADMINISTRATOR
context-path: /management
并更新我的WebSecurityConfigurerAdapter配置
@Override
protected void configure(HttpSecurity http) throws Exception {
...
http.authorizeRequests()..antMatchers("/management/**").hasRole(Role.ADMINISTRATOR.toString());
...
}
它可以工作,但我必须硬编码Actuators context-path,所以当我想更新时,management.context-path我必须更新我的安全性。
我知道可以检索值,management.context-path但是当值等于时如何管理它""?
您可以回答我@Autowired EndpointHandlerMapping并检索Actuators端点列表...最后我将复制过去与ManagementSecurityAutoConfiguration.ManagementWebSecurityConfigurerAdapter.
此外ManagementSecurityAutoConfiguration.ManagementWebSecurityConfigurerAdapter @ConditionalOnMissingBean,它指向自身,但ManagementSecurityAutoConfiguration.ManagementWebSecurityConfigurerAdapter它是内部静态受保护类,因此在不传递参数的情况下无法禁用它management.security.enabled=false,这可能很奇怪,因为您的配置说management.security.enabled=false但实际上端点是安全的......
结论
- 有没有办法正确地覆盖(只是一部分)
Actuators安全性 - 我可以错过一些东西,我完全错了吗?