我正在尝试保护项目Actuators
内部的端点Spring Boot
。但是,改为使用准备运行的Spring Security
配置Actuators
:
management:
security:
enabled: true
role: ADMINISTRATOR
这太容易了,我需要插入Actuators
我们的自定义安全性(这里是CAS
SSO)。
首先尝试它是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
安全性 - 我可以错过一些东西,我完全错了吗?