From 495403c917a39fdeb3906f10ac8b997f68eb3875 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Mon, 28 Dec 2020 15:51:42 +0100 Subject: update to HSM-Facade v0.6.0 and add HealthCheck functionality --- .../actuator/HsmFacadeProviderHealthCheck.java | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/actuator/HsmFacadeProviderHealthCheck.java (limited to 'eaaf-springboot-utils/src/main/java/at/gv') diff --git a/eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/actuator/HsmFacadeProviderHealthCheck.java b/eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/actuator/HsmFacadeProviderHealthCheck.java new file mode 100644 index 00000000..d2406552 --- /dev/null +++ b/eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/actuator/HsmFacadeProviderHealthCheck.java @@ -0,0 +1,54 @@ +package at.gv.egiz.eaaf.utils.springboot.actuator; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.actuate.health.HealthIndicator; +import org.springframework.stereotype.Service; + +import at.gv.egiz.eaaf.core.impl.credential.EaafKeyStoreFactory; +import at.gv.egiz.eaaf.core.impl.credential.EaafKeyStoreFactory.HsmFacadeStatus; +import lombok.extern.slf4j.Slf4j; + +/** + * Implements a Spring-Actuator HealthCheck for HSM-Facade from A-SIT+. + * + * @author tlenz + * + */ +@Slf4j +@Service("HsmFacadeProvider") +public class HsmFacadeProviderHealthCheck implements HealthIndicator { + + @Autowired(required = false) EaafKeyStoreFactory factory; + + @Override + public Health health() { + if (factory != null && factory.isHsmFacadeInitialized()) { + try { + HsmFacadeStatus status = factory.checkHsmFacadeStatus(); + log.trace("Current HSM-Facade status: {}", status); + if (HsmFacadeStatus.UP.equals(status)) { + return Health.up().build(); + + } else if (HsmFacadeStatus.DOWN.equals(status)) { + return Health.down().build(); + + } + + } catch (Exception e) { + log.warn("HSM-Facaden Health-Check has an error", e); + return Health.down(e).build(); + + } + + } else { + log.trace("No {} or HSM-Facade is not initialized. Skipping healthCheck ...", + EaafKeyStoreFactory.class.getName()); + + } + + return Health.unknown().build(); + + } + +} -- cgit v1.2.3