diff options
author | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2021-01-05 18:30:40 +0100 |
---|---|---|
committer | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2021-01-05 18:30:40 +0100 |
commit | 013febf9435d0aa3536897b3636787ae3ba15935 (patch) | |
tree | 5c424808d8bbb31b755736106639d3831c466f2e /eaaf-springboot-utils/src/main/java/at | |
parent | 228d4e40cfb8fc3fa7912064af3768a74beb9312 (diff) | |
parent | 07dcace901880965ea4b25816500f256f17899c0 (diff) | |
download | EAAF-Components-013febf9435d0aa3536897b3636787ae3ba15935.tar.gz EAAF-Components-013febf9435d0aa3536897b3636787ae3ba15935.tar.bz2 EAAF-Components-013febf9435d0aa3536897b3636787ae3ba15935.zip |
Merge branch 'nightlyBuild' of gitlab.iaik.tugraz.at:egiz/eaaf_components into nightlyBuild
Diffstat (limited to 'eaaf-springboot-utils/src/main/java/at')
-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(); + + } + +} |