diff options
author | Thomas <> | 2022-03-10 14:04:03 +0100 |
---|---|---|
committer | Thomas <> | 2022-03-10 14:04:03 +0100 |
commit | 18b7f8ece152958f8c4978c375cc9844335221df (patch) | |
tree | a41ac5f4b59f8db13a8a703d8533f8bc998e5d53 /modules/authmodule-eIDAS-v2/src/main/java/at/asitplus | |
parent | 5985f2f3bf67d76de41ecd2ef91f74e551e7bced (diff) | |
download | National_eIDAS_Gateway-18b7f8ece152958f8c4978c375cc9844335221df.tar.gz National_eIDAS_Gateway-18b7f8ece152958f8c4978c375cc9844335221df.tar.bz2 National_eIDAS_Gateway-18b7f8ece152958f8c4978c375cc9844335221df.zip |
chore: implement asynch. health-check for IDA metadata
Diffstat (limited to 'modules/authmodule-eIDAS-v2/src/main/java/at/asitplus')
-rw-r--r-- | modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/idaustriaclient/provider/IdAustriaClientAuthHealthCheck.java | 32 |
1 files changed, 28 insertions, 4 deletions
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<Health> 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<Health> 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()); } |