diff options
author | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2020-12-28 15:51:42 +0100 |
---|---|---|
committer | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2020-12-28 15:51:42 +0100 |
commit | 495403c917a39fdeb3906f10ac8b997f68eb3875 (patch) | |
tree | 6797d9af002bbf384597ea016f9c7afa021692a3 /eaaf-springboot-utils/src/main/java/at/gv | |
parent | 1aafdf3bbae55b09e6d28e97281797ba9e53aad0 (diff) | |
download | EAAF-Components-495403c917a39fdeb3906f10ac8b997f68eb3875.tar.gz EAAF-Components-495403c917a39fdeb3906f10ac8b997f68eb3875.tar.bz2 EAAF-Components-495403c917a39fdeb3906f10ac8b997f68eb3875.zip |
update to HSM-Facade v0.6.0 and add HealthCheck functionality
Diffstat (limited to 'eaaf-springboot-utils/src/main/java/at/gv')
-rw-r--r-- | eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/actuator/HsmFacadeProviderHealthCheck.java | 54 |
1 files changed, 54 insertions, 0 deletions
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(); + + } + +} |