From 882789ecf04615abf8d5c80e3a0695d1cfc76fa0 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Wed, 5 Feb 2020 12:47:08 +0100 Subject: refactor refresh process in AbstractChainingMetadataProvider --- eaaf_modules/eaaf_module_pvp2_core/pom.xml | 40 +++++++------- .../metadata/AbstractChainingMetadataProvider.java | 63 +++++++++++++++------- 2 files changed, 64 insertions(+), 39 deletions(-) diff --git a/eaaf_modules/eaaf_module_pvp2_core/pom.xml b/eaaf_modules/eaaf_module_pvp2_core/pom.xml index ef56624b..ca112162 100644 --- a/eaaf_modules/eaaf_module_pvp2_core/pom.xml +++ b/eaaf_modules/eaaf_module_pvp2_core/pom.xml @@ -76,7 +76,7 @@ mockwebserver test - + @@ -92,33 +92,33 @@ 1.8 - - - compile - testCompile - - + + + compile + testCompile + + - org.apache.maven.plugins - maven-jar-plugin - 3.1.0 - - - - test-jar - - - - + org.apache.maven.plugins + maven-jar-plugin + 3.1.0 + + + + test-jar + + + + - + maven-surefire-plugin ${surefire.version} - 1 + 1 diff --git a/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/metadata/AbstractChainingMetadataProvider.java b/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/metadata/AbstractChainingMetadataProvider.java index 80511f64..14a641e6 100644 --- a/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/metadata/AbstractChainingMetadataProvider.java +++ b/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/metadata/AbstractChainingMetadataProvider.java @@ -21,6 +21,7 @@ package at.gv.egiz.eaaf.modules.pvp2.impl.metadata; import java.io.IOException; import java.security.cert.CertificateException; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -72,7 +73,7 @@ public abstract class AbstractChainingMetadataProvider implements IGarbageCollec * */ public AbstractChainingMetadataProvider() { - internalResolvers = Collections.synchronizedList(Collections.emptyList()); + internalResolvers = Collections.synchronizedList(new ArrayList<>()); } @@ -110,17 +111,10 @@ public abstract class AbstractChainingMetadataProvider implements IGarbageCollec @Override public synchronized boolean refreshMetadataProvider(final String entityId) { try { - // check if metadata provider is already loaded - try { - if (resolveEntityDescripor(entityId) != null) { - return true; - - } - - } catch (final ResolverException e) { - log.debug("Metadata for EntityId: {} is not valid. Starting refresh ... ", entityId); - - } + //if (resolveEntityDescriporForRefesh(entityId)) { + // return true; + // + //} // reload metadata provider final String metadataUrl = getMetadataUrl(entityId); @@ -131,25 +125,33 @@ public abstract class AbstractChainingMetadataProvider implements IGarbageCollec // check if MetadataProvider is actually loaded final MetadataResolver loadedResover = actuallyLoadedResolver.get(metadataUrl); if (loadedResover instanceof RefreshableMetadataResolver) { - ((RefreshableMetadataResolver) loadedResover).refresh(); - log.info("SAML2 metadata for service provider: " + entityId + " is refreshed."); - return true; + try { + ((RefreshableMetadataResolver) loadedResover).refresh(); + log.info("SAML2 metadata for service provider: {} is refreshed.", entityId); + return true; + + } catch (final ResolverException e) { + log.info("Can not refresh SAML2 metadata for entityId: {}. Reason: {}", entityId, e.getMessage()); + destroyMetadataResolver(loadedResover); + internalResolvers.remove(loadedResover); + + } } else { // load new Metadata Provider internalResolvers.add(createNewMetadataProvider(metadataUrl)); - log.info("SAML2 metadata for service provider: " + entityId + " is added."); + log.info("SAML2 metadata for service provider: {} is added.", entityId); return true; } } else { log.debug( - "Can not refresh SAML2 metadata: NO SAML2 metadata URL for SP with Id: " + entityId); + "Can not refresh SAML2 metadata: NO SAML2 metadata URL for SP with Id: {}", entityId); } - } catch (final IOException | ResolverException | EaafConfigurationException | CertificateException e) { + } catch (final IOException | EaafConfigurationException | CertificateException e) { log.warn("Refresh SAML2 metadata for service provider: " + entityId + " FAILED.", e); } @@ -158,6 +160,7 @@ public abstract class AbstractChainingMetadataProvider implements IGarbageCollec } + @Override public final MetadataFilter getMetadataFilter() { log.warn("{} does NOT support {}", AbstractChainingMetadataProvider.class.getName(), @@ -467,10 +470,32 @@ public abstract class AbstractChainingMetadataProvider implements IGarbageCollec private EntityDescriptor resolveEntityDescripor(String entityId) throws ResolverException { final CriteriaSet criteria = new CriteriaSet(); criteria.add(new EntityIdCriterion(entityId)); - return resolveSingle(criteria); + return internalResolveSingle(criteria); } +// private boolean resolveEntityDescriporForRefesh(String entityId) { +// final CriteriaSet criteria = new CriteriaSet(); +// criteria.add(new EntityIdCriterion(entityId)); +// for (final MetadataResolver resolver : internalResolvers) { +// try { +// if (resolver instanceof RefreshableMetadataResolver +// && resolver.resolveSingle(criteria) != null) { +// +// ((RefreshableMetadataResolver)resolver).refresh(); +// return true; +// +// } +// +// } catch (final ResolverException e) { +// continue; +// +// } +// } +// +// return false; +// } + private void destroyMetadataResolver(MetadataResolver resolver) { if (resolver instanceof AbstractMetadataResolver) { final AbstractMetadataResolver httpprovider = (AbstractMetadataResolver) resolver; -- cgit v1.2.3