Spring:使用 Spring 安全性为执行器端点配置安全性

Spring: Configure security for actuator endpoints with Spring Security

是否可以通过 Spring 安全性以通用方式为 Spring 应用程序的执行器端点配置安全性?

根据 https://github.com/spring-projects/spring-boot/issues/8646,我需要在我的自定义 Spring 安全配置中执行此操作。

但是假设我在我的应用程序中(在端口 8080 上)有针对 /info 的自定义请求映射,并且在端口 8081 上启用了执行器信息端点。我如何在 [=20= 中区分这两者] 安全?

有可能,但不是特别明显。在 WebSecurityConfigurerAdapter 的扩展中,您可以注入执行器端点的集合:

@Inject
private List<AbstractEndpointMvcAdapter<? extends Endpoint<?>>> actuatorEndpoints;

然后在 configureHttpSecurity(HttpSecurity http) 的重写中,您可以使用每个执行器端点的 getPath() 成员传递给 http 参数上可用的 .requestMatchers(forPortAndPath(managementPort, actuatorPath)) 构建器。

我刚刚发现 Spring Boot 2 明确解决了这个问题。 参见 https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#production-ready-endpoints-security