【问题标题】:How to set custom AbstractHealthIndicator as not sensitive in Spring Boot so it shows for /health endpoint?如何在 Spring Boot 中将自定义 AbstractHealthIndicator 设置为不敏感,以便显示 /health 端点?
【发布时间】:2017-07-24 21:21:30
【问题描述】:

我正在运行 Spring Boot v1.5.2.RELEASE。

如何在不禁用整个 Spring Boot 项目的安全性的情况下让/health 显示在下方?

{
    "status": "UP",
    "testing": {
        "status": "UNKNOWN",
        "foo": "bar"
    }
}

下面是我的 TestingHealthIndicator.java 代码:

import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health.Builder;
import org.springframework.stereotype.Component;

@Component
public class TestingHealthIndicator extends AbstractHealthIndicator {

    @Override
    protected void doHealthCheck(Builder builder) throws Exception {
        builder.withDetail("foo", "bar");
    }
}

只有当我在application.properties 中设置以下内容时,“测试”才会显示在 /health 中

management.security.enabled=false
management.health.defaults.enabled=false

但我不想禁用整个项目的安全性。

我确实在这里看到了一些有用的信息:https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html,但没有看到将自定义 AbstractHealthIndicator 设置为非敏感的特定方式。

【问题讨论】:

  • 你在使用 Spring Security 和 Actuator 吗?!这是解决还是不解决?! :)
  • 我将 Spring Security 与 Actuator 一起使用。没有解决:(

标签: java spring-boot spring-boot-actuator


【解决方案1】:

假设您只想为运行状况检查禁用安全性。对于其余的 api,您希望像往常一样进行身份验证。因此,健康需要显示所有信息。我曾经在 Springboot 4.4 中拥有相同的项目。这是我在 application.yml 中配置的

endpoints:
  health: 
    sensitive:  false 

management:
  security:
    enabled: false
  health:
    defaults:
      enabled: true

在安全方面,把其他api做fullAuthentication。

<intercept-url pattern="/health access="permitAll" />
<intercept-url pattern="/api/**" access="isFullyAuthenticated()" />

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2016-05-29
    • 1970-01-01
    • 2016-09-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-22
    • 1970-01-01
    • 2017-12-04
    • 1970-01-01
    相关资源
    最近更新 更多