[java-oidc-common] branch main updated: Simplify metadata cache builder. Consolidate to a single builder
Phil Smart
philip.smart at jisc.ac.uk
Wed Mar 9 15:17:49 UTC 2022
This is an automated email from the git hooks/post-receive script.
philsmart pushed a commit to branch main
in repository java-oidc-common.
View the commit online:
http://git.shibboleth.net/view/?p=java-oidc-common.git;a=commit;h=52799d6787b881e46c89516a84249d18db25879f
The following commit(s) were added to refs/heads/main by this push:
new 52799d6 Simplify metadata cache builder. Consolidate to a single builder
52799d6 is described below
commit 52799d6787b881e46c89516a84249d18db25879f
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Wed Mar 9 15:17:43 2022 +0000
Simplify metadata cache builder. Consolidate to a single builder
---
.../metadata/cache/impl/BatchMetadataCache.java | 7 +-
.../cache/impl/BatchMetadataCacheBuilder.java | 85 ---------------
.../cache/impl/BatchMetadataCacheBuilderSpec.java | 3 +-
.../cache/impl/DynamicMetadataCacheBuilder.java | 85 ---------------
.../impl/DynamicMetadataCacheBuilderSpec.java | 3 +-
.../impl/FetchThroughMetadataCacheBuilder.java | 77 --------------
.../impl/FetchThroughMetadataCacheBuilderSpec.java | 3 +-
.../metadata/cache/impl/MetadataCacheBuilder.java | 115 +++++++++++++++++++++
.../cache/impl/MetadataCacheBuilderSpec.java | 11 ++
.../impl/MetadataPolicyLookupStrategyFactory.java | 7 +-
.../cache/impl/BatchMetadataCacheTest.java | 30 +++++-
.../impl/DynamicMetadataCacheBuilderTest.java | 77 --------------
...lderTest.java => MetadataCacheBuilderTest.java} | 71 +++++++++----
...etadata-policy-lookup-strategy-factory-test.xml | 3 +-
14 files changed, 219 insertions(+), 358 deletions(-)
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCache.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCache.java
index 723b470..93cb2d8 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCache.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCache.java
@@ -381,6 +381,9 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
freshLoad(parsedMetadata);
// Store away the original, raw, metadata bytes.
getBackingStore().setOriginalValue(rawFetchedMetadata);
+ // Set last update time, technically there is no guarantee the metadata was stored correctly
+ // at this point.
+ getBackingStore().setLastUpdate(now);
}
// Compute metadata expiration from whatever is in the cache (updated or not) will
@@ -388,7 +391,7 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
metadataExpiration = sourceMetadataExpiryStrategy.apply(getBackingStore().getOriginalValue());
} else {
// Metadata is not valid
- log.warn("{} Source metadata is not valid");
+ log.warn("{} Source metadata is not valid, nothing to load", getLogPrefix());
//TODO MUST FINISH THIS !!
}
} else {
@@ -411,7 +414,7 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
final Duration nextRefreshDelay = computeNextRefreshDelay(metadataExpiration);
scheduleNextRefresh(nextRefreshDelay);
}
-
+ // Set last attempted refresh even if failure.
getBackingStore().setLastRefresh(now);
}
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheBuilder.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheBuilder.java
deleted file mode 100644
index a0ed4f4..0000000
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheBuilder.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Licensed to the University Corporation for Advanced Internet Development,
- * Inc. (UCAID) under one or more contributor license agreements. See the
- * NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The UCAID licenses this file to You under the Apache
- * License, Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package net.shibboleth.oidc.metadata.cache.impl;
-
-import javax.annotation.Nonnull;
-
-import net.shibboleth.oidc.metadata.impl.DefaultBatchBackingStore;
-import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-
-
-/**
- * Build a fully initialized and safely published batch metadata cache for use. Each cache is built from its own
- * specification.
- *
- * <p>Spring's XML injection can not enforce type safety here, so an incorrect specification will
- * not be picked up until it is used.</p>
- *
- */
-public final class BatchMetadataCacheBuilder {
-
- /** Private constructor.*/
- private BatchMetadataCacheBuilder() {
-
- }
-
- /**
- * A static builder for generating a batch metadata cache from a given specification.
- *
- * @param <IdentifierType> The identifier type
- * @param <MetadataType> The metadata type
- */
- public static class Builder<IdentifierType, MetadataType> {
-
-
- /**
- * Build the metadata cache from the given specification.
- *
- * @param spec the metadata cache specification.
- *
- * @return the batch metadata cache.
- *
- * @throws ComponentInitializationException on error.
- */
- public BatchMetadataCache<IdentifierType, MetadataType> build(
- @Nonnull final BatchMetadataCacheBuilderSpec<IdentifierType, MetadataType> spec)
- throws ComponentInitializationException {
-
- final BatchMetadataCache<IdentifierType, MetadataType> cache =
- new BatchMetadataCache<>(
- new DefaultBatchBackingStore<>());
- cache.setSourceMetadataExpiryStrategy(spec.getSourceMetadataExpiryStrategy());
- cache.setLoadingStrategy(spec.getLoadingStrategy());
- cache.setParsingStrategy(spec.getParsingStrategy());
- cache.setMinRefreshDelay(spec.getMinRefreshDelay());
- cache.setMaxRefreshDelay(spec.getMaxRefreshDelay());
- cache.setRefreshDelayFactor(spec.getRefreshDelayFactor());
- cache.setIdentifierExtractionStrategy(spec.getIdentifierExtractionStrategy());
- cache.setCriteriaToIdentifierStrategy(spec.getCriteriaToIdentifierStrategy());
- cache.setMetadataFilterStrategy(spec.getMetadataFilterStrategy());
- cache.setMetadataBeforeRemovalHook(spec.getMetadataBeforeRemovalHook());
- cache.setMatchOnIdentifierRequired(spec.isMatchOnIdentifierRequired());
- cache.setMetadataValidPredicate(spec.getMetadataValidPredicate());
- cache.setSourceMetadataValidPredicate(spec.getSourceMetadataValidPredicate());
- cache.setId(spec.getCacheId());
- cache.initialize();
- return cache;
- }
- }
-
-}
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheBuilderSpec.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheBuilderSpec.java
index f65eba7..c60a1d7 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheBuilderSpec.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheBuilderSpec.java
@@ -40,7 +40,8 @@ import net.shibboleth.utilities.java.support.logic.Constraint;
* @param <MetadataType> the metadata type.
*/
public class BatchMetadataCacheBuilderSpec<IdentifierType, MetadataType>
- extends BaseMetadataCacheBuilderSpec<IdentifierType, MetadataType> {
+ extends BaseMetadataCacheBuilderSpec<IdentifierType, MetadataType>
+ implements MetadataCacheBuilderSpec<IdentifierType, MetadataType> {
/**
* How to parse the loaded metadata from the loadingStrategy into a usable metadatatype.
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DynamicMetadataCacheBuilder.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DynamicMetadataCacheBuilder.java
deleted file mode 100644
index 2992abf..0000000
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DynamicMetadataCacheBuilder.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Licensed to the University Corporation for Advanced Internet Development,
- * Inc. (UCAID) under one or more contributor license agreements. See the
- * NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The UCAID licenses this file to You under the Apache
- * License, Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package net.shibboleth.oidc.metadata.cache.impl;
-
-import javax.annotation.Nonnull;
-
-import net.shibboleth.oidc.metadata.impl.DefaultDynamicBackingStore;
-import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-
-/**
- * Build a fully initialized and safely published dynamic metadata cache for use. Each cache is built from its own
- * specification.
- *
- * <p>Spring's XML injection can not enforce type safety here, so an incorrect specification will
- * not be picked up until it is used.</p>
- */
-public final class DynamicMetadataCacheBuilder {
-
- /** Private constructor.*/
- private DynamicMetadataCacheBuilder() {
-
- }
-
- /**
- * A static builder for generating a dynamic metadata cache from a given specification.
- *
- * @param <IdentifierType> The identifier type
- * @param <MetadataType> The metadata type
- */
- public static class Builder<IdentifierType, MetadataType> {
-
- /**
- * Build a metadata cache from the given metadata specification.
- *
- * @param spec the specification used to build the cache.
- *
- * @return the metadata cache.
- *
- * @throws ComponentInitializationException on error.
- */
- public DynamicMetadataCache<IdentifierType, MetadataType>
- build(@Nonnull final DynamicMetadataCacheBuilderSpec<IdentifierType, MetadataType> spec)
- throws ComponentInitializationException {
-
- final DynamicMetadataCache<IdentifierType, MetadataType> cache = new DynamicMetadataCache<>(
- new DefaultDynamicBackingStore<>());
- cache.setFetchStrategy(spec.getFetchStrategy());
- cache.setMinCacheDuration(spec.getMinCacheDuration());
- cache.setMaxCacheDuration(spec.getMaxCacheDuration());
- cache.setRefreshDelayFactor(spec.getRefreshDelayFactor());
- cache.setMaxIdleEntityData(spec.getMaxIdleEntityData());
- cache.setMetadataExpirationTimeStrategy(spec.getMetadataExpirationTimeStrategy());
- cache.setIdentifierExtractionStrategy(spec.getIdentifierExtractionStrategy());
- cache.setCriteriaToIdentifierStrategy(spec.getCriteriaToIdentifierStrategy());
- cache.setCleanupTaskInterval(spec.getCleanupTaskInterval());
- cache.setRemoveIdleEntityData(spec.isRemoveIdleEntityData());
- cache.setInitialCleanupTaskDelay(spec.getInitialCleanupTaskDelay());
- cache.setMetadataFilterStrategy(spec.getMetadataFilterStrategy());
- cache.setMetadataBeforeRemovalHook(spec.getMetadataBeforeRemovalHook());
- cache.setMetadataValidPredicate(spec.getMetadataValidPredicate());
- cache.setId(spec.getCacheId());
- cache.initialize();
- return cache;
- }
-
- }
-
-
-}
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DynamicMetadataCacheBuilderSpec.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DynamicMetadataCacheBuilderSpec.java
index f9f238c..5c20e47 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DynamicMetadataCacheBuilderSpec.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DynamicMetadataCacheBuilderSpec.java
@@ -36,7 +36,8 @@ import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
* @param <MetadataType> the metadata type.
*/
public class DynamicMetadataCacheBuilderSpec <IdentifierType, MetadataType>
- extends BaseMetadataCacheBuilderSpec<IdentifierType, MetadataType> {
+ extends BaseMetadataCacheBuilderSpec<IdentifierType, MetadataType>
+ implements MetadataCacheBuilderSpec<IdentifierType, MetadataType> {
/** The function to use to fetch metadata if either none exists, or the existing is stale.*/
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/FetchThroughMetadataCacheBuilder.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/FetchThroughMetadataCacheBuilder.java
deleted file mode 100644
index 49596a2..0000000
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/FetchThroughMetadataCacheBuilder.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the University Corporation for Advanced Internet Development,
- * Inc. (UCAID) under one or more contributor license agreements. See the
- * NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The UCAID licenses this file to You under the Apache
- * License, Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package net.shibboleth.oidc.metadata.cache.impl;
-
-import javax.annotation.Nonnull;
-
-import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-
-/**
- * Build a fully initialized and safely published fetch-through metadata cache for use. Each cache is built from its own
- * specification.
- *
- * <p>Spring's XML injection can not enforce type safety here, so an incorrect specification will
- * not be picked up until it is used.</p>
- */
-public final class FetchThroughMetadataCacheBuilder {
-
- /** Private constructor.*/
- private FetchThroughMetadataCacheBuilder() {
-
- }
-
- /**
- * A static builder for generating a dynamic metadata cache from a given specification.
- *
- * @param <IdentifierType> The identifier type
- * @param <MetadataType> The metadata type
- */
- public static class Builder<IdentifierType, MetadataType> {
-
- /**
- * Build a metadata cache from the given metadata specification.
- *
- * @param spec the specification used to build the cache.
- *
- * @return the metadata cache.
- *
- * @throws ComponentInitializationException on error.
- */
- public FetchThroughMetadataCache<IdentifierType, MetadataType>
- build(@Nonnull final FetchThroughMetadataCacheBuilderSpec<IdentifierType, MetadataType> spec)
- throws ComponentInitializationException {
-
- final FetchThroughMetadataCache<IdentifierType, MetadataType> cache = new FetchThroughMetadataCache<>();
- cache.setFetchStrategy(spec.getFetchStrategy());
- //TODO refresh delay is not really needed here.
- cache.setRefreshDelayFactor(spec.getRefreshDelayFactor());
- cache.setIdentifierExtractionStrategy(spec.getIdentifierExtractionStrategy());
- cache.setCriteriaToIdentifierStrategy(spec.getCriteriaToIdentifierStrategy());
- cache.setMetadataFilterStrategy(spec.getMetadataFilterStrategy());
- cache.setMetadataBeforeRemovalHook(spec.getMetadataBeforeRemovalHook());
- cache.setMetadataValidPredicate(spec.getMetadataValidPredicate());
- cache.setId(spec.getCacheId());
- cache.initialize();
- return cache;
- }
-
- }
-
-
-}
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/FetchThroughMetadataCacheBuilderSpec.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/FetchThroughMetadataCacheBuilderSpec.java
index b420bda..7176fb0 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/FetchThroughMetadataCacheBuilderSpec.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/FetchThroughMetadataCacheBuilderSpec.java
@@ -33,7 +33,8 @@ import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
* @param <MetadataType> the metadata type.
*/
public class FetchThroughMetadataCacheBuilderSpec <IdentifierType, MetadataType>
- extends BaseMetadataCacheBuilderSpec<IdentifierType, MetadataType> {
+ extends BaseMetadataCacheBuilderSpec<IdentifierType, MetadataType>
+ implements MetadataCacheBuilderSpec<IdentifierType, MetadataType> {
/** The function to use to fetch metadata if either none exists, or the existing is stale.*/
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/MetadataCacheBuilder.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/MetadataCacheBuilder.java
new file mode 100644
index 0000000..c862103
--- /dev/null
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/MetadataCacheBuilder.java
@@ -0,0 +1,115 @@
+package net.shibboleth.oidc.metadata.cache.impl;
+
+import javax.annotation.Nonnull;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import net.shibboleth.oidc.metadata.cache.MetadataCache;
+import net.shibboleth.oidc.metadata.impl.DefaultBatchBackingStore;
+import net.shibboleth.oidc.metadata.impl.DefaultDynamicBackingStore;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+
+/**
+ * A builder that creates, initializes, and safely publishes the correct {@link MetadataCache metadata cache}
+ * based on the supplied {@link MetadataCacheBuilderSpec metadata cache builder specification}.
+ */
+public class MetadataCacheBuilder {
+
+ /** Private constructor.*/
+ private MetadataCacheBuilder() {
+
+ }
+
+ /**
+ * A static builder for generating a batch metadata cache from a given specification.
+ *
+ * @param <IdentifierType> The identifier type
+ * @param <MetadataType> The metadata type
+ */
+ public static class Builder<IdentifierType, MetadataType> {
+
+ /** Class logger. */
+ @Nonnull private final Logger log = LoggerFactory.getLogger(MetadataCacheBuilder.class);
+
+
+ /**
+ * Build the metadata cache from the given specification.
+ *
+ * @param specification the metadata cache specification.
+ *
+ * @return the batch metadata cache.
+ *
+ * @throws ComponentInitializationException on error.
+ */
+ public MetadataCache<MetadataType> build(
+ @Nonnull final MetadataCacheBuilderSpec<IdentifierType, MetadataType> specification)
+ throws ComponentInitializationException {
+
+ if (specification instanceof BatchMetadataCacheBuilderSpec) {
+ final BatchMetadataCacheBuilderSpec<IdentifierType, MetadataType> spec =
+ (BatchMetadataCacheBuilderSpec<IdentifierType, MetadataType>) specification;
+ final BatchMetadataCache<IdentifierType, MetadataType> cache =
+ new BatchMetadataCache<>(
+ new DefaultBatchBackingStore<>());
+ cache.setSourceMetadataExpiryStrategy(spec.getSourceMetadataExpiryStrategy());
+ cache.setLoadingStrategy(spec.getLoadingStrategy());
+ cache.setParsingStrategy(spec.getParsingStrategy());
+ cache.setMinRefreshDelay(spec.getMinRefreshDelay());
+ cache.setMaxRefreshDelay(spec.getMaxRefreshDelay());
+ cache.setRefreshDelayFactor(spec.getRefreshDelayFactor());
+ cache.setIdentifierExtractionStrategy(spec.getIdentifierExtractionStrategy());
+ cache.setCriteriaToIdentifierStrategy(spec.getCriteriaToIdentifierStrategy());
+ cache.setMetadataFilterStrategy(spec.getMetadataFilterStrategy());
+ cache.setMetadataBeforeRemovalHook(spec.getMetadataBeforeRemovalHook());
+ cache.setMatchOnIdentifierRequired(spec.isMatchOnIdentifierRequired());
+ cache.setMetadataValidPredicate(spec.getMetadataValidPredicate());
+ cache.setSourceMetadataValidPredicate(spec.getSourceMetadataValidPredicate());
+ cache.setId(spec.getCacheId());
+ cache.initialize();
+ return cache;
+ } else if (specification instanceof DynamicMetadataCacheBuilderSpec) {
+ final DynamicMetadataCacheBuilderSpec<IdentifierType, MetadataType> spec =
+ (DynamicMetadataCacheBuilderSpec<IdentifierType, MetadataType>) specification;
+ final DynamicMetadataCache<IdentifierType, MetadataType> cache = new DynamicMetadataCache<>(
+ new DefaultDynamicBackingStore<>());
+ cache.setFetchStrategy(spec.getFetchStrategy());
+ cache.setMinCacheDuration(spec.getMinCacheDuration());
+ cache.setMaxCacheDuration(spec.getMaxCacheDuration());
+ cache.setRefreshDelayFactor(spec.getRefreshDelayFactor());
+ cache.setMaxIdleEntityData(spec.getMaxIdleEntityData());
+ cache.setMetadataExpirationTimeStrategy(spec.getMetadataExpirationTimeStrategy());
+ cache.setIdentifierExtractionStrategy(spec.getIdentifierExtractionStrategy());
+ cache.setCriteriaToIdentifierStrategy(spec.getCriteriaToIdentifierStrategy());
+ cache.setCleanupTaskInterval(spec.getCleanupTaskInterval());
+ cache.setRemoveIdleEntityData(spec.isRemoveIdleEntityData());
+ cache.setInitialCleanupTaskDelay(spec.getInitialCleanupTaskDelay());
+ cache.setMetadataFilterStrategy(spec.getMetadataFilterStrategy());
+ cache.setMetadataBeforeRemovalHook(spec.getMetadataBeforeRemovalHook());
+ cache.setMetadataValidPredicate(spec.getMetadataValidPredicate());
+ cache.setId(spec.getCacheId());
+ cache.initialize();
+ return cache;
+ } else if (specification instanceof FetchThroughMetadataCacheBuilderSpec) {
+ final FetchThroughMetadataCacheBuilderSpec<IdentifierType, MetadataType> spec =
+ (FetchThroughMetadataCacheBuilderSpec<IdentifierType, MetadataType>) specification;
+ final FetchThroughMetadataCache<IdentifierType, MetadataType> cache = new FetchThroughMetadataCache<>();
+ cache.setFetchStrategy(spec.getFetchStrategy());
+ //TODO refresh delay is not really needed here.
+ cache.setRefreshDelayFactor(spec.getRefreshDelayFactor());
+ cache.setIdentifierExtractionStrategy(spec.getIdentifierExtractionStrategy());
+ cache.setCriteriaToIdentifierStrategy(spec.getCriteriaToIdentifierStrategy());
+ cache.setMetadataFilterStrategy(spec.getMetadataFilterStrategy());
+ cache.setMetadataBeforeRemovalHook(spec.getMetadataBeforeRemovalHook());
+ cache.setMetadataValidPredicate(spec.getMetadataValidPredicate());
+ cache.setId(spec.getCacheId());
+ cache.initialize();
+ return cache;
+ }
+ log.error("Unable to construct metadata cache, unknown specification type '{}'",
+ specification.getClass().getSimpleName());
+ throw new ComponentInitializationException("Cache Specification type not recognized");
+ }
+ }
+
+}
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/MetadataCacheBuilderSpec.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/MetadataCacheBuilderSpec.java
new file mode 100644
index 0000000..8dcd28b
--- /dev/null
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/MetadataCacheBuilderSpec.java
@@ -0,0 +1,11 @@
+package net.shibboleth.oidc.metadata.cache.impl;
+
+/**
+ * Marker interface for metadata cache builder specifications.
+ *
+ * @param <IdentifierType> the identifier type.
+ * @param <MetadataType> the metadata type.
+ */
+public interface MetadataCacheBuilderSpec<IdentifierType, MetadataType> {
+
+}
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/MetadataPolicyLookupStrategyFactory.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/MetadataPolicyLookupStrategyFactory.java
index 556b52d..7953fd0 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/MetadataPolicyLookupStrategyFactory.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/MetadataPolicyLookupStrategyFactory.java
@@ -30,6 +30,7 @@ import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import net.shibboleth.ext.spring.resource.PreferFileSystemResourceLoader;
+import net.shibboleth.oidc.metadata.cache.MetadataCache;
import net.shibboleth.oidc.metadata.policy.MetadataPolicy;
import net.shibboleth.oidc.metadata.policy.MetadataPolicyResolver;
import net.shibboleth.oidc.metadata.policy.impl.OIDCMetadataPolicyResolver;
@@ -71,8 +72,8 @@ public class MetadataPolicyLookupStrategyFactory {
final Function<ProfileRequestContext, CriteriaSet> criteriaSetLookupStrategy,
@ParameterName(name="id") @Nonnull final String id) throws ComponentInitializationException, IOException{
- final BatchMetadataCacheBuilder.Builder<String, Map<String, MetadataPolicy>> builder =
- new BatchMetadataCacheBuilder.Builder<>();
+ final MetadataCacheBuilder.Builder<String, Map<String, MetadataPolicy>> builder =
+ new MetadataCacheBuilder.Builder<>();
Resource fileResource = null;
if (resource != null && !resource.isEmpty()) {
@@ -84,7 +85,7 @@ public class MetadataPolicyLookupStrategyFactory {
cacheSpec.setLoadingStrategy(fileStrategy);
cacheSpec.setCacheId(id + "-cache");
- final BatchMetadataCache<String, Map<String, MetadataPolicy>> cache = builder.build(cacheSpec);
+ final MetadataCache<Map<String, MetadataPolicy>> cache = builder.build(cacheSpec);
final OIDCMetadataPolicyResolver resolver = new OIDCMetadataPolicyResolver(cache);
resolver.setId(id + "-resolver");
diff --git a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheTest.java b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheTest.java
index bb941f6..fe0d3b2 100644
--- a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheTest.java
+++ b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheTest.java
@@ -35,8 +35,6 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
-import javax.annotation.Nonnull;
-
import org.opensaml.core.criterion.EntityIdCriterion;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -76,7 +74,7 @@ public class BatchMetadataCacheTest {
public byte[] load(final CacheLoadingContext t) {
try {
return new OIDCProviderMetadata(new Issuer("http://www.example.org"), List.of(SubjectType.PUBLIC),
- new URI("http://example.oidc.op.org")).toJSONObject().toJSONString().getBytes();
+ new URI("http://www.example.org/metadata")).toJSONObject().toJSONString().getBytes();
} catch (final URISyntaxException e) {
return null;
}
@@ -375,6 +373,32 @@ public class BatchMetadataCacheTest {
assertTrue(metadata.isEmpty() == false);
}
+
+ @Test
+ public void testSourceNotValid_Success() throws ComponentInitializationException, MetadataCacheException {
+ cache.setSourceMetadataValidPredicate(Predicates.alwaysFalse());
+ cache.initialize();
+ final List<OIDCProviderMetadata> metadata =
+ cache.get(new CriteriaSet(new IssuerIDCriterion(new Issuer("http://www.example.org"))));
+ assertTrue(metadata.isEmpty() == true);
+ }
+
+
+ @Test
+ public void testSourceNotValid_EntryAllreadyExist_Success() throws Exception {
+
+ final Issuer iss = new Issuer("http://www.example.org");
+ // Add an entry
+ cache.getBackingStore().getIndexedValues().put(iss, List.of(
+ new OIDCProviderMetadata(new Issuer("http://www.example.org"), List.of(SubjectType.PUBLIC),
+ new URI("http://www.example.org/metadata"))));
+
+ cache.setSourceMetadataValidPredicate(Predicates.alwaysFalse());
+ cache.initialize();
+ final List<OIDCProviderMetadata> metadata =
+ cache.get(new CriteriaSet(new IssuerIDCriterion(iss)));
+ assertTrue(metadata.isEmpty() == true);
+ }
@Test
public void testGetNotCached_RefreshAHead_Success()
diff --git a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/DynamicMetadataCacheBuilderTest.java b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/DynamicMetadataCacheBuilderTest.java
deleted file mode 100644
index f4545c5..0000000
--- a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/DynamicMetadataCacheBuilderTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the University Corporation for Advanced Internet Development,
- * Inc. (UCAID) under one or more contributor license agreements. See the
- * NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The UCAID licenses this file to You under the Apache
- * License, Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package net.shibboleth.oidc.metadata.cache.impl;
-
-import static org.testng.Assert.assertNotNull;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.time.Duration;
-import java.util.List;
-
-import org.testng.annotations.Test;
-
-import com.nimbusds.oauth2.sdk.id.Issuer;
-import com.nimbusds.openid.connect.sdk.SubjectType;
-import com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata;
-
-import net.shibboleth.oidc.metadata.criterion.IssuerIDCriterion;
-import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-
-public class DynamicMetadataCacheBuilderTest {
-
-
- @Test
- public void testDynamicCacheBuilder_Success() throws ComponentInitializationException {
- var builder = new DynamicMetadataCacheBuilder.Builder<Issuer, OIDCProviderMetadata>();
-
- DynamicMetadataCacheBuilderSpec<Issuer, OIDCProviderMetadata> spec = new DynamicMetadataCacheBuilderSpec<>();
- spec.setIdentifierExtractionStrategy(m -> m.getIssuer());
-
- spec.setMetadataExpirationTimeStrategy(ctx -> ctx.getNow().plus(Duration.ofMinutes(5)));
- spec.setCriteriaToIdentifierStrategy(crit -> {
- final IssuerIDCriterion issuerId = crit.get(IssuerIDCriterion.class);
- if (issuerId != null) {
- return issuerId.getIssuerID();
- }
- return null;
- });
- spec.setCleanupTaskInterval(Duration.ofSeconds(100));
- spec.setInitialCleanupTaskDelay(Duration.ofSeconds(1));
- spec.setMaxIdleEntityData(Duration.ofMinutes(10));
- spec.setRefreshDelayFactor(0.75f);
- spec.setMinCacheDuration(Duration.ofMinutes(10));
- // cache.setMaxCacheDuration(Duration.ofMinutes(20));
- spec.setMetadataFilterStrategy((metadata, context) -> metadata);
- spec.setFetchStrategy(crit -> {
- try {
- final Issuer iss = crit.get(IssuerIDCriterion.class).getIssuerID();
- return new OIDCProviderMetadata(iss, List.of(SubjectType.PUBLIC),
- new URI("http://example.oidc.op.org"));
- } catch (final URISyntaxException e) {
- return null;
- }
- });
- spec.setCacheId("MockDynamicCache");
-
- final DynamicMetadataCache<Issuer, OIDCProviderMetadata> cache = builder.build(spec);
- assertNotNull(cache);
-
- }
-
-}
diff --git a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheBuilderTest.java b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/MetadataCacheBuilderTest.java
similarity index 56%
rename from oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheBuilderTest.java
rename to oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/MetadataCacheBuilderTest.java
index 08d327e..620ffd9 100644
--- a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheBuilderTest.java
+++ b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/MetadataCacheBuilderTest.java
@@ -15,24 +15,10 @@
* limitations under the License.
*/
-package net.shibboleth.oidc.metadata.cache.impl;/*
-
- * Inc. (UCAID) under one or more contributor license agreements. See the
- * NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The UCAID licenses this file to You under the Apache
- * License, Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+package net.shibboleth.oidc.metadata.cache.impl;
import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
import java.net.URI;
import java.net.URISyntaxException;
@@ -49,15 +35,57 @@ import com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata;
import net.shibboleth.oidc.metadata.cache.CacheLoadingContext;
import net.shibboleth.oidc.metadata.cache.LoadingStrategy;
+import net.shibboleth.oidc.metadata.cache.MetadataCache;
import net.shibboleth.oidc.metadata.criterion.IssuerIDCriterion;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-public class BatchMetadataCacheBuilderTest {
+/** Tests for the {@link MetadataCacheBuilder}.*/
+public class MetadataCacheBuilderTest {
+ @Test
+ public void testDynamicCacheBuilder_Success() throws ComponentInitializationException {
+ final var builder = new MetadataCacheBuilder.Builder<Issuer, OIDCProviderMetadata>();
+
+ final DynamicMetadataCacheBuilderSpec<Issuer, OIDCProviderMetadata> spec =
+ new DynamicMetadataCacheBuilderSpec<>();
+ spec.setIdentifierExtractionStrategy(OIDCProviderMetadata::getIssuer);
+
+ spec.setMetadataExpirationTimeStrategy(ctx -> ctx.getNow().plus(Duration.ofMinutes(5)));
+ spec.setCriteriaToIdentifierStrategy(crit -> {
+ final IssuerIDCriterion issuerId = crit.get(IssuerIDCriterion.class);
+ if (issuerId != null) {
+ return issuerId.getIssuerID();
+ }
+ return null;
+ });
+ spec.setCleanupTaskInterval(Duration.ofSeconds(100));
+ spec.setInitialCleanupTaskDelay(Duration.ofSeconds(1));
+ spec.setMaxIdleEntityData(Duration.ofMinutes(10));
+ spec.setRefreshDelayFactor(0.75f);
+ spec.setMinCacheDuration(Duration.ofMinutes(10));
+ // cache.setMaxCacheDuration(Duration.ofMinutes(20));
+ spec.setMetadataFilterStrategy((metadata, context) -> metadata);
+ spec.setFetchStrategy(crit -> {
+ try {
+ final Issuer iss = crit.get(IssuerIDCriterion.class).getIssuerID();
+ return new OIDCProviderMetadata(iss, List.of(SubjectType.PUBLIC),
+ new URI("http://op.example.org/jwk"));
+ } catch (final URISyntaxException e) {
+ return null;
+ }
+ });
+ spec.setCacheId("MockDynamicCache");
+
+ final MetadataCache<OIDCProviderMetadata> cache = builder.build(spec);
+ assertNotNull(cache);
+ assertTrue(cache instanceof DynamicMetadataCache);
+
+ }
+
@Test
public void testBatchCacheBuilder_Success() throws ComponentInitializationException {
- final var builder = new BatchMetadataCacheBuilder.Builder<Issuer, OIDCProviderMetadata>();
+ final var builder = new MetadataCacheBuilder.Builder<Issuer, OIDCProviderMetadata>();
final BatchMetadataCacheBuilderSpec<Issuer, OIDCProviderMetadata> spec = new BatchMetadataCacheBuilderSpec<>();
spec.setIdentifierExtractionStrategy(OIDCProviderMetadata::getIssuer);
@@ -88,15 +116,16 @@ public class BatchMetadataCacheBuilderTest {
});
spec.setParsingStrategy(bytesIn -> {
try {
- return List.of(new OIDCProviderMetadata(new Issuer("http://www.example.org"),
+ return List.of(new OIDCProviderMetadata(new Issuer("http://op.example.org"),
List.of(SubjectType.PUBLIC),
- new URI("http://example.oidc.op.org")));
+ new URI("http://op.example.org/jwk")));
} catch (final URISyntaxException e) {
return Collections.emptyList();
}
});
- final BatchMetadataCache<Issuer, OIDCProviderMetadata> cache = builder.build(spec);
+ final MetadataCache<OIDCProviderMetadata> cache = builder.build(spec);
assertNotNull(cache);
+ assertTrue(cache instanceof BatchMetadataCache);
}
diff --git a/oidc-common-metadata-impl/src/test/resources/net/shibboleth/oidc/metadata/impl/metadata-policy-lookup-strategy-factory-test.xml b/oidc-common-metadata-impl/src/test/resources/net/shibboleth/oidc/metadata/impl/metadata-policy-lookup-strategy-factory-test.xml
index b9dd1d9..6a687a1 100644
--- a/oidc-common-metadata-impl/src/test/resources/net/shibboleth/oidc/metadata/impl/metadata-policy-lookup-strategy-factory-test.xml
+++ b/oidc-common-metadata-impl/src/test/resources/net/shibboleth/oidc/metadata/impl/metadata-policy-lookup-strategy-factory-test.xml
@@ -45,8 +45,7 @@
factory-bean="shibboleth.oidc.test.MetadataPolicyLookupStrategyFactory"
factory-method="buildFileLoadingMetadataPolicyResolver"
c:cacheSpec-ref="shibboleth.oidc.test.BatchMetadataCacheBuilderSpec"
- c:criteriaSetLookupStrategy="#{null}"
- />
+ c:criteriaSetLookupStrategy="#{null}"/>
<bean id="shibboleth.oidc.test.MetadataPolicyLookupStrategyOne"
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list