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

obe*_*ker 5 java spring spring-security spring-boot-actuator

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

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

但是假设我/info在我的应用程序中(在端口 8080 上)有一个自定义请求映射,并且在端口 8081 上启用了执行器信息端点。我如何在 Spring Security 中区分这两个?

And*_*own 2

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

@Inject
private List<AbstractEndpointMvcAdapter<? extends Endpoint<?>>> actuatorEndpoints;
Run Code Online (Sandbox Code Playgroud)

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