diff options
Diffstat (limited to 'modules/authmodule_id-austria/src/main/java/at/asitplus')
-rw-r--r-- | modules/authmodule_id-austria/src/main/java/at/asitplus/eidas/specific/modules/auth/idaustria/utils/IdAustriaAuthHealthCheck.java | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/modules/authmodule_id-austria/src/main/java/at/asitplus/eidas/specific/modules/auth/idaustria/utils/IdAustriaAuthHealthCheck.java b/modules/authmodule_id-austria/src/main/java/at/asitplus/eidas/specific/modules/auth/idaustria/utils/IdAustriaAuthHealthCheck.java new file mode 100644 index 00000000..5e1d889e --- /dev/null +++ b/modules/authmodule_id-austria/src/main/java/at/asitplus/eidas/specific/modules/auth/idaustria/utils/IdAustriaAuthHealthCheck.java @@ -0,0 +1,80 @@ +package at.asitplus.eidas.specific.modules.auth.idaustria.utils; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import org.apache.commons.lang3.StringUtils; +import org.opensaml.saml.saml2.metadata.EntityDescriptor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.actuate.health.HealthIndicator; + +import at.asitplus.eidas.specific.modules.auth.idaustria.IdAustriaAuthConstants; +import at.gv.egiz.eaaf.core.api.idp.IConfiguration; +import lombok.extern.slf4j.Slf4j; +import net.shibboleth.utilities.java.support.resolver.ResolverException; + +/** + * Spring Actuator HealthCheck for ID Austria client that evaluates the current status of + * ID Austria SAML2 metadata that are loaded into MS-ProxyService. + * + * @author tlenz + * + */ +@Slf4j +public class IdAustriaAuthHealthCheck implements HealthIndicator { + + private static final int DEADLINE = 3; + + @Autowired IConfiguration authConfig; + @Autowired IdAustriaAuthMetadataProvider metadataService; + + @Override + public Health health() { + String msNodeEntityID = authConfig.getBasicConfiguration( + IdAustriaAuthConstants.CONFIG_PROPS_IDAUSTRIA_METADATAURL); + + if (StringUtils.isEmpty(msNodeEntityID)) { + log.trace("No ID Austria EntityId in configuration. Skipping tests ... "); + return Health.unknown().build(); + + } + + CompletableFuture<Health> asynchTestOperation = new CompletableFuture<>(); + Executors.newCachedThreadPool().submit(() -> runConnectionTest(asynchTestOperation, msNodeEntityID)); + try { + return asynchTestOperation.get(DEADLINE, TimeUnit.SECONDS); + + } catch (InterruptedException | ExecutionException | TimeoutException e) { + log.info("Receive no respose from Health-Check after {} seconds.", DEADLINE); + return Health.outOfService().withException(e).build(); + + } + + + } + + + private void runConnectionTest(CompletableFuture<Health> completableFuture, String entityId) { + try { + EntityDescriptor connectorMetadata = + metadataService.getEntityDescriptor(entityId); + if (connectorMetadata != null) { + completableFuture.complete(Health.up().build()); + + } else { + completableFuture.complete(Health.outOfService().withDetail("Reason", "No SAML2 metadata").build()); + + } + + } catch (ResolverException e) { + completableFuture.complete(Health.down(e).build()); + + } + + } + +} |