diff options
author | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2020-02-05 12:47:08 +0100 |
---|---|---|
committer | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2020-02-05 12:47:08 +0100 |
commit | 882789ecf04615abf8d5c80e3a0695d1cfc76fa0 (patch) | |
tree | c238310cd1a132726559da81b12860a01f60fd5e | |
parent | fc8aab29eb278a1489a75847efa38ea72b941c79 (diff) | |
download | EAAF-Components-882789ecf04615abf8d5c80e3a0695d1cfc76fa0.tar.gz EAAF-Components-882789ecf04615abf8d5c80e3a0695d1cfc76fa0.tar.bz2 EAAF-Components-882789ecf04615abf8d5c80e3a0695d1cfc76fa0.zip |
refactor refresh process in AbstractChainingMetadataProvider
-rw-r--r-- | eaaf_modules/eaaf_module_pvp2_core/pom.xml | 40 | ||||
-rw-r--r-- | eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/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 @@ <artifactId>mockwebserver</artifactId> <scope>test</scope> </dependency> - + </dependencies> <build> @@ -92,33 +92,33 @@ <target>1.8</target> </configuration> <executions> - <execution> - <goals> - <goal>compile</goal> - <goal>testCompile</goal> - </goals> - </execution> + <execution> + <goals> + <goal>compile</goal> + <goal>testCompile</goal> + </goals> + </execution> </executions> </plugin> <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <version>3.1.0</version> - <executions> - <execution> - <goals> - <goal>test-jar</goal> - </goals> - </execution> - </executions> - </plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>3.1.0</version> + <executions> + <execution> + <goals> + <goal>test-jar</goal> + </goals> + </execution> + </executions> + </plugin> - <!-- enable co-existence of testng and junit --> + <!-- enable co-existence of testng and junit --> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>${surefire.version}</version> <configuration> - <threadCount>1</threadCount> + <threadCount>1</threadCount> </configuration> <dependencies> <dependency> 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; |