From 18b7f8ece152958f8c4978c375cc9844335221df Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Thu, 10 Mar 2022 14:04:03 +0100 Subject: chore: implement asynch. health-check for IDA metadata --- .../provider/IdAustriaClientAuthHealthCheck.java | 32 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'modules/authmodule-eIDAS-v2/src/main/java/at/asitplus') diff --git a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/idaustriaclient/provider/IdAustriaClientAuthHealthCheck.java b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/idaustriaclient/provider/IdAustriaClientAuthHealthCheck.java index b54b501d..32bbfa54 100644 --- a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/idaustriaclient/provider/IdAustriaClientAuthHealthCheck.java +++ b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/idaustriaclient/provider/IdAustriaClientAuthHealthCheck.java @@ -1,5 +1,11 @@ package at.asitplus.eidas.specific.modules.auth.eidas.v2.idaustriaclient.provider; +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; @@ -21,6 +27,8 @@ import net.shibboleth.utilities.java.support.resolver.ResolverException; @Slf4j public class IdAustriaClientAuthHealthCheck implements HealthIndicator { + private static final int DEADLINE = 3; + @Autowired IConfiguration authConfig; @Autowired IdAustriaClientAuthMetadataProvider metadataService; @@ -35,19 +43,35 @@ public class IdAustriaClientAuthHealthCheck implements HealthIndicator { } + CompletableFuture asynchTestOperation = new CompletableFuture<>(); + Executors.newCachedThreadPool().submit(() -> runConnectionTest(asynchTestOperation, msNodeEntityID)); + try { + return asynchTestOperation.get(DEADLINE, TimeUnit.SECONDS); + + } catch (InterruptedException | ExecutionException | TimeoutException e) { + log.warn("Receive no respose from Health-Check after {} seconds.", DEADLINE, e); + return Health.outOfService().withException(e).build(); + + } + + + } + + + private void runConnectionTest(CompletableFuture completableFuture, String entityId) { try { EntityDescriptor connectorMetadata = - metadataService.getEntityDescriptor(msNodeEntityID); + metadataService.getEntityDescriptor(entityId); if (connectorMetadata != null) { - return Health.up().build(); + completableFuture.complete(Health.up().build()); } else { - return Health.outOfService().withDetail("Reason", "No SAML2 metadata").build(); + completableFuture.complete(Health.outOfService().withDetail("Reason", "No SAML2 metadata").build()); } } catch (ResolverException e) { - return Health.down(e).build(); + completableFuture.complete(Health.down(e).build()); } -- cgit v1.2.3