【发布时间】:2019-07-10 00:32:01
【问题描述】:
我正在尝试构建一个 Spring Boot 应用程序并希望利用 Actuator 功能,但我想保护 Actuator /health、/shutdown 等的端点。我的以下配置似乎不起作用。即,应用程序从不提示输入凭据,或者当邮递员点击时不会给出 403。我尝试了各种方法,甚至是 spring 文档中的一种。任何人都可以帮助解决这个问题。这又是 Spring Boot 2.1.x。我知道在之前版本的spring的application.yml中可以进行配置
@Configuration
public class ActuatorSecurity extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.requestMatchers(EndpointRequest.to(ShutdownEndpoint.class, InfoEndpoint.class, HealthEndpoint.class,
MetricsEndpoint.class))
.hasRole("ENDPOINT_ADMIN").requestMatchers(PathRequest.toStaticResources().atCommonLocations())
.authenticated().and().httpBasic();
}
application.yml
spring:
security:
user:
name: admin
password: admin
roles:
- ENDPOINT_ADMIN
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
shutdown:
enabled: true
health:
show-details: when-authorized
roles:
- ENDPOINT_ADMIN
mappings:
enabled: true
【问题讨论】:
标签: spring-boot spring-security spring-boot-actuator