[java-oidc-common] branch main updated: Improve cache builder spec. and general cache building
Phil Smart
philip.smart at jisc.ac.uk
Wed Nov 3 15:27:34 UTC 2021
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=d451c08a7d6255d8507788a23efcdc753682158a
The following commit(s) were added to refs/heads/main by this push:
new d451c08 Improve cache builder spec. and general cache building
d451c08 is described below
commit d451c08a7d6255d8507788a23efcdc753682158a
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Wed Nov 3 15:27:31 2021 +0000
Improve cache builder spec. and general cache building
- Add a LoadingStrategy to obtain a friend source name to log
statements.
---
.../oidc/metadata/cache/LoadingStrategy.java | 14 ++++++++
.../metadata/cache/impl/AbstractMetadataCache.java | 19 ++++++++---
.../metadata/cache/impl/BatchMetadataCache.java | 16 ++++++----
.../cache/impl/BatchMetadataCacheBuilderSpec.java | 8 ++---
.../cache/impl/DefaultFileLoadingStrategy.java | 9 ++++--
.../metadata/cache/impl/DynamicMetadataCache.java | 8 ++---
.../cache/impl/DynamicMetadataCacheBuilder.java | 2 +-
.../cache/impl/MetadataCacheBuilderSpec.java | 27 +++++++++++++++-
.../impl/AbstractDynamicHTTPFetchingStrategy.java | 13 ++++----
.../HTTPProviderConfigurationFetchingStrategy.java | 2 +-
.../metadata/cache/impl/BatchMetadatCacheTest.java | 37 ++++++++++++----------
.../cache/impl/BatchMetadataCacheBuilderTest.java | 17 ++++++++--
.../impl/DynamicMetadataCacheBuilderTest.java | 3 +-
.../metadata/impl/OIDCMapMetadataResolverTest.java | 18 +++++++++--
.../impl/OIDCProviderMetadataResolverTest.java | 17 ++++++++--
15 files changed, 155 insertions(+), 55 deletions(-)
diff --git a/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/cache/LoadingStrategy.java b/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/cache/LoadingStrategy.java
new file mode 100644
index 0000000..f087ead
--- /dev/null
+++ b/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/cache/LoadingStrategy.java
@@ -0,0 +1,14 @@
+package net.shibboleth.oidc.metadata.cache;
+
+import java.util.function.Function;
+
+public interface LoadingStrategy extends Function<CacheLoadingContext, byte[]> {
+
+ /**
+ * Get a friendly name source identifier to use in log statements.
+ *
+ * @return the source identifier friendly name.
+ */
+ String getSourceIdentifier();
+
+}
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/AbstractMetadataCache.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/AbstractMetadataCache.java
index 3329283..f7d37bf 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/AbstractMetadataCache.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/AbstractMetadataCache.java
@@ -79,6 +79,9 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
/** Cached log prefix. */
@Nullable private String logPrefix;
+ /** A friendly name used to identify this cache in log statements.*/
+ @Nullable private String friendlyName;
+
/** Minimum cache duration. */
@NonnullAfterInit private Duration minCacheDuration;
@@ -121,6 +124,13 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
AbstractMetadataCache(@Nonnull final BackingStore<IdentifierType, MetadataType> store) {
this(store, null);
}
+
+ public void setFriendlyName(@Nonnull @NotEmpty final String name) {
+ ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+ ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
+
+ friendlyName = name;
+ }
/**
@@ -404,17 +414,16 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
*/
protected void freshLoad(@Nonnull final List<MetadataType> metadataToStore) {
invalidateAll();
- for (final MetadataType metadata : metadataToStore) {
- final IdentifierType identifier = identifierExtractionStrategy.apply(metadata);
- log.debug("{} Resolved criteria to identifier: {}", getLogPrefix(), identifier);
+ for (final MetadataType metadata : metadataToStore) {
writeToBackingStore(metadata);
- }
-
+ }
}
/**
* Write the given metadata to the backing store index.
*
+ * <p>Should happen within an appropriate lock to ensure thread-safety.</p>
+ *
* @param metadata the metadata to add to the backing store.
*/
protected void writeToBackingStore(@Nonnull final MetadataType metadata) {
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 06522c5..7e47d73 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
@@ -34,6 +34,7 @@ import org.slf4j.LoggerFactory;
import net.shibboleth.oidc.metadata.BatchBackingStore;
import net.shibboleth.oidc.metadata.cache.CacheLoadingContext;
+import net.shibboleth.oidc.metadata.cache.LoadingStrategy;
import net.shibboleth.oidc.metadata.cache.MetadataCacheException;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullAfterInit;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
@@ -51,7 +52,7 @@ import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
* <p>Supports the following:</p>
* <ul>
* <li>Batch reloading of metadata using the supplied loading strategy. The cache
- * is completely reloaded during each background update.</li>
+ * is completely reloaded during each refresh cycle.</li>
* </ul>
*
* @param <IdentifierType> the metadata identifier type.
@@ -72,7 +73,7 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
@NonnullAfterInit @Positive private Duration minRefreshDelay;
/** The function to use to load metadata.*/
- @Nonnull private final Function<CacheLoadingContext, byte[]> loadingStrategy;
+ @Nonnull private final LoadingStrategy loadingStrategy;
/** How to parse the loaded metadata from the loadingStrategy into a usable metadatatype.*/
@Nonnull private final Function<byte[], List<MetadataType>> parsingStrategy;
@@ -87,7 +88,7 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
* @param parseStrategy the strategy used to convert raw metadata in bytes to the given metadata type.
*/
public BatchMetadataCache(@Nonnull final BatchBackingStore<IdentifierType, MetadataType> store,
- @Nonnull final Function<CacheLoadingContext, byte[]> metadataLoadingStrategy,
+ @Nonnull final LoadingStrategy metadataLoadingStrategy,
@Nonnull final Function<byte[], List<MetadataType>> parseStrategy) {
this(store, metadataLoadingStrategy, parseStrategy, null);
}
@@ -102,7 +103,7 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
* @param executor the scheduled executor
*/
protected BatchMetadataCache(@Nonnull final BatchBackingStore<IdentifierType, MetadataType> store,
- @Nonnull final Function<CacheLoadingContext, byte[]> metadataLoadingStrategy,
+ @Nonnull final LoadingStrategy metadataLoadingStrategy,
@Nonnull final Function<byte[], List<MetadataType>> parseStrategy,
@Nullable final ScheduledExecutorService executor) {
super(store, executor);
@@ -206,7 +207,7 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
//TODO lock? could be loading while a read is happening
private synchronized void loadCache() throws MetadataCacheException{
- log.debug("{} Populating metadata cache",getLogPrefix());
+ log.debug("{} Populating metadata cache for '{}'",getLogPrefix(), loadingStrategy.getSourceIdentifier());
final Instant now = Instant.now();
Duration refreshDelay = null;
try {
@@ -262,7 +263,7 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
new AsynchronousRefreshAHeadTask()), nextRefreshDelay, TimeUnit.MILLISECONDS);
log.info("{} Next refresh cycle for metadata provider '{}' will occur on '{}' ('{}' local time)",
- getLogPrefix(), "ADD THIS ONE", nextRefresh, nextRefresh.atZone(ZoneId.systemDefault()));
+ getLogPrefix(), loadingStrategy.getSourceIdentifier(), nextRefresh, nextRefresh.atZone(ZoneId.systemDefault()));
}
@@ -292,6 +293,7 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
return Duration.ofMillis(refreshDelay);
}
+ /** A runnable that triggers a cache reload.*/
private class AsynchronousRefreshAHeadTask implements Runnable {
@Override
@@ -305,6 +307,8 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
try {
loadCache();
} catch (final MetadataCacheException e) {
+ log.warn("{} Failed to background re-load cache for '{}'",getLogPrefix(),
+ loadingStrategy.getSourceIdentifier(), e);
// nothing the thread can do.
return;
}
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 0bf97c2..b301611 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
@@ -7,7 +7,7 @@ import java.util.function.Function;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import net.shibboleth.oidc.metadata.cache.CacheLoadingContext;
+import net.shibboleth.oidc.metadata.cache.LoadingStrategy;
import net.shibboleth.utilities.java.support.annotation.constraint.Positive;
import net.shibboleth.utilities.java.support.logic.Constraint;
@@ -21,7 +21,7 @@ public class BatchMetadataCacheBuilderSpec<IdentifierType, MetadataType>
@Nullable private Function<byte[], List<MetadataType>> parsingStrategy;
/** The function to use to load metadata. Applicable for {@link BatchMetadataCache} types.*/
- @Nullable private Function<CacheLoadingContext, byte[]> loadingStrategy;
+ @Nullable private LoadingStrategy loadingStrategy;
/**
* Refresh interval used when metadata does not contain any validUntil or cacheDuration information.
@@ -101,7 +101,7 @@ public class BatchMetadataCacheBuilderSpec<IdentifierType, MetadataType>
*
* @param strategy the strategy to set.
*/
- public void setLoadingStrategy(@Nonnull final Function<CacheLoadingContext, byte[]> strategy) {
+ public void setLoadingStrategy(@Nonnull LoadingStrategy strategy) {
loadingStrategy = Constraint.isNotNull(strategy,"Batch metadata loading strategy can not be null");
}
@@ -110,7 +110,7 @@ public class BatchMetadataCacheBuilderSpec<IdentifierType, MetadataType>
*
* @return the strategy.
*/
- @Nullable protected Function<CacheLoadingContext, byte[]> getLoadingStrategy() {
+ @Nullable protected LoadingStrategy getLoadingStrategy() {
return loadingStrategy;
}
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DefaultFileLoadingStrategy.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DefaultFileLoadingStrategy.java
index 63f7e08..ddf64c7 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DefaultFileLoadingStrategy.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DefaultFileLoadingStrategy.java
@@ -4,7 +4,6 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.time.Instant;
-import java.util.function.Function;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.ThreadSafe;
@@ -14,13 +13,14 @@ import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
import net.shibboleth.oidc.metadata.cache.CacheLoadingContext;
+import net.shibboleth.oidc.metadata.cache.LoadingStrategy;
import net.shibboleth.oidc.metadata.impl.ResolverHelper;
import net.shibboleth.utilities.java.support.logic.Constraint;
import net.shibboleth.utilities.java.support.resolver.ResolverException;
/** Default strategy for loading information from a file.*/
@ThreadSafe
-public class DefaultFileLoadingStrategy implements Function<CacheLoadingContext, byte[]> {
+public class DefaultFileLoadingStrategy implements LoadingStrategy {
/** Class logger. */
@Nonnull private final Logger log = LoggerFactory.getLogger(DefaultFileLoadingStrategy.class);
@@ -61,4 +61,9 @@ public class DefaultFileLoadingStrategy implements Function<CacheLoadingContext,
}
}
+ @Override
+ public String getSourceIdentifier() {
+ return metadataFile.getAbsolutePath();
+ }
+
}
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DynamicMetadataCache.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DynamicMetadataCache.java
index e3d46b6..5f0acf1 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DynamicMetadataCache.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DynamicMetadataCache.java
@@ -82,7 +82,7 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
private boolean removeIdleEntityData;
/** The function to use to fetch/load metadata if either none exists, or the existing is stale.*/
- @Nonnull private final Function<CriteriaSet, MetadataType> dynamicFetchStrategy;
+ @Nonnull private final Function<CriteriaSet, MetadataType> fetchStrategy;
/**
* Constructor.
@@ -93,7 +93,7 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
public DynamicMetadataCache(@Nonnull final DynamicBackingStore<IdentifierType, MetadataType> store,
@Nonnull final Function<CriteriaSet, MetadataType> metadataFetchStrategy) {
super(store);
- dynamicFetchStrategy =
+ fetchStrategy =
Constraint.isNotNull(metadataFetchStrategy, "Dynamic Metadata fetch strategy can not be null");
}
@@ -109,7 +109,7 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
@Nonnull final Function<CriteriaSet, MetadataType> metadataFetchStrategy,
@Nullable final ScheduledExecutorService executor) {
super(store, executor);
- dynamicFetchStrategy =
+ fetchStrategy =
Constraint.isNotNull(metadataFetchStrategy, "Dynamic Metadata fetch strategy can not be null");
}
@@ -263,7 +263,7 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
log.debug("{} Metadata for '{}' is stale and requires refreshing", getLogPrefix(), identifier);
}
- final MetadataType resolvedMetadata = dynamicFetchStrategy.apply(criteria);
+ final MetadataType resolvedMetadata = fetchStrategy.apply(criteria);
if (resolvedMetadata != null) {
storeNewMetadata(mgmtData, resolvedMetadata, identifier);
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
index 075bb98..a1905d0 100644
--- 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
@@ -50,7 +50,7 @@ public final class DynamicMetadataCacheBuilder {
cache.setInitialCleanupTaskDelay(spec.getInitialCleanupTaskDelay());
cache.setMetadataFilterStrategy(spec.getMetadataFilterStrategy());
cache.setMetadataBeforeRemovalHook(spec.getMetadataBeforeRemovalHook());
- cache.setId("DynamicMetadataCache");
+ cache.setId(spec.getCacheId());
cache.initialize();
return cache;
}
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
index 93df6b2..f8bb0a8 100644
--- 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
@@ -29,7 +29,10 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.shibboleth.oidc.metadata.filter.MetadataFilterContext;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.annotation.constraint.Positive;
+import net.shibboleth.utilities.java.support.component.AbstractIdentifiableInitializableComponent;
+import net.shibboleth.utilities.java.support.component.AbstractInitializableComponent;
import net.shibboleth.utilities.java.support.logic.Constraint;
import net.shibboleth.utilities.java.support.logic.ConstraintViolationException;
import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
@@ -57,6 +60,9 @@ public class MetadataCacheBuilderSpec<IdentifierType, MetadataType> {
/** A strategy to filter metadata. */
@Nonnull private BiFunction<MetadataType, MetadataFilterContext , MetadataType> metadataFilterStrategy;
+ /** An identifier to give the cache this specification builds. Used for logging.*/
+ @Nonnull private String cacheId;
+
/**
* A hook that is executed just before a cache entry will been removed/invalidated/evicted.
* The metadata list could be {@literal null}, the identifier is never {@literal null}.
@@ -71,10 +77,29 @@ public class MetadataCacheBuilderSpec<IdentifierType, MetadataType> {
minCacheDuration = Duration.ofMinutes(10);
refreshDelayFactor = 0.75f;
// create a default direct in/out filter
- metadataFilterStrategy = (metadata, context) -> metadata;
+ metadataFilterStrategy = (metadata, context) -> metadata;
+ //cacheId = "unknown";
}
+ /**
+ * Set the cache identifier of the cache this specification builds.
+ *
+ * @param id the cache identifier.
+ */
+ public void setCacheId(@Nonnull @NotEmpty final String id) {
+ cacheId = Constraint.isNotEmpty(id, "Cache identifier can not be null or empty");
+ }
+
+ /**
+ * Get the cache identifier.
+ *
+ * @return the cache identifier.
+ */
+ @Nonnull public String getCacheId() {
+ return cacheId;
+ }
+
/**
* Set a hook to run before a metadata cache entry is removed from the cache.
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/AbstractDynamicHTTPFetchingStrategy.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/AbstractDynamicHTTPFetchingStrategy.java
index 5262681..c4de82f 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/AbstractDynamicHTTPFetchingStrategy.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/AbstractDynamicHTTPFetchingStrategy.java
@@ -51,16 +51,17 @@ import net.shibboleth.utilities.java.support.component.ComponentInitializationEx
import net.shibboleth.utilities.java.support.component.ComponentSupport;
import net.shibboleth.utilities.java.support.logic.Constraint;
import net.shibboleth.utilities.java.support.primitive.StringSupport;
+import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
import net.shibboleth.utilities.java.support.resolver.ResolverException;
/**
* Abstract strategy for fetching metadata dynamically over HTTP.
*
- * @param <CriteriaType> the type of criteria used to build the request.
* @param <MetadataType> the metadata type.
*/
-public abstract class AbstractDynamicHTTPFetchingStrategy<CriteriaType, MetadataType>
- extends AbstractIdentifiableInitializableComponent implements Function<CriteriaType, MetadataType> {
+//TODO the MDC stuff.
+public abstract class AbstractDynamicHTTPFetchingStrategy<MetadataType>
+ extends AbstractIdentifiableInitializableComponent implements Function<CriteriaSet, MetadataType> {
/** Default list of supported content MIME types. */
private static final String[] DEFAULT_CONTENT_TYPES = new String[] {"application/json",
@@ -201,7 +202,7 @@ public abstract class AbstractDynamicHTTPFetchingStrategy<CriteriaType, Metadata
}
@Override
- @Nullable public MetadataType apply(@Nonnull final CriteriaType criteria) {
+ @Nullable public MetadataType apply(@Nonnull final CriteriaSet criteria) {
log.info("{} fetching metadata based on criteria: {}", getId(), criteria);
final HttpUriRequest request = buildHttpRequest(criteria);
if (request == null) {
@@ -246,7 +247,7 @@ public abstract class AbstractDynamicHTTPFetchingStrategy<CriteriaType, Metadata
* @param criteria the input criteria set
* @return the newly constructed request, or null if it can not be built from the supplied criteria
*/
- @Nullable private HttpUriRequest buildHttpRequest(@Nonnull final CriteriaType criteria) {
+ @Nullable private HttpUriRequest buildHttpRequest(@Nonnull final CriteriaSet criteria) {
final String url = buildRequestURL(criteria);
log.debug("Built request URL of: {}", url);
@@ -270,6 +271,6 @@ public abstract class AbstractDynamicHTTPFetchingStrategy<CriteriaType, Metadata
* @param criteria the input criteria set
* @return the request URL, or null if it can not be built based on the supplied criteria
*/
- @Nullable protected abstract String buildRequestURL(@Nonnull final CriteriaType criteria);
+ @Nullable protected abstract String buildRequestURL(@Nonnull final CriteriaSet criteria);
}
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/HTTPProviderConfigurationFetchingStrategy.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/HTTPProviderConfigurationFetchingStrategy.java
index b50c72f..406ff5d 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/HTTPProviderConfigurationFetchingStrategy.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/HTTPProviderConfigurationFetchingStrategy.java
@@ -56,7 +56,7 @@ import net.shibboleth.utilities.java.support.resolver.ResolverException;
*/
@ThreadSafe //? is a singleton?
public class HTTPProviderConfigurationFetchingStrategy
- extends AbstractDynamicHTTPFetchingStrategy<CriteriaSet, OIDCProviderMetadata> {
+ extends AbstractDynamicHTTPFetchingStrategy<OIDCProviderMetadata> {
/** The returned content_type, must be application/json see openid-connect-discovery section 4.*/
@Nonnull private static final MediaType CONTENT_TYPE = MediaType.JSON_UTF_8;
diff --git a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadatCacheTest.java b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadatCacheTest.java
index 4684895..4acf467 100644
--- a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadatCacheTest.java
+++ b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadatCacheTest.java
@@ -33,8 +33,6 @@ import java.util.function.Function;
import javax.annotation.Nonnull;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -45,6 +43,7 @@ import com.nimbusds.openid.connect.sdk.SubjectType;
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.MetadataCacheException;
import net.shibboleth.oidc.metadata.criterion.IssuerIDCriterion;
import net.shibboleth.oidc.metadata.impl.DefaultBatchBackingStore;
@@ -53,16 +52,13 @@ import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
public class BatchMetadatCacheTest {
- /** Class logger. */
- private final Logger log = LoggerFactory.getLogger(BatchMetadatCacheTest.class);
-
// OIDC provider metadata cache
private BatchMetadataCache<Issuer, OIDCProviderMetadata> cache;
private ManuallyTriggeredScheduledExecutorService scheduler;
@Nonnull
- private Function<CacheLoadingContext, byte[]> defaultLoadingStrategy;
+ private LoadingStrategy defaultLoadingStrategy;
@Nonnull
private Function<byte[], List<OIDCProviderMetadata>> defaultParsingStrategy;
@@ -70,12 +66,22 @@ public class BatchMetadatCacheTest {
@BeforeMethod
void setup() throws Exception {
- defaultLoadingStrategy = context -> {
- try {
- return new OIDCProviderMetadata(new Issuer("http://www.example.org"), List.of(SubjectType.PUBLIC),
- new URI("http://example.oidc.op.org")).toJSONObject().toJSONString().getBytes();
- } catch (final URISyntaxException e) {
- return null;
+
+ defaultLoadingStrategy = new LoadingStrategy() {
+
+ @Override
+ public byte[] apply(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();
+ } catch (final URISyntaxException e) {
+ return null;
+ }
+ }
+
+ @Override
+ public String getSourceIdentifier() {
+ return "Mock loading source";
}
};
@@ -125,10 +131,10 @@ public class BatchMetadatCacheTest {
@Test(enabled = false)
public void testNormalRefreshDelay() throws ComponentInitializationException, InterruptedException {
- BatchMetadataCache<Issuer, OIDCProviderMetadata> localCache =
+ final BatchMetadataCache<Issuer, OIDCProviderMetadata> localCache =
new BatchMetadataCache<Issuer, OIDCProviderMetadata>(
new DefaultBatchBackingStore<Issuer, OIDCProviderMetadata>(), defaultLoadingStrategy,
- defaultParsingStrategy, scheduler);
+ defaultParsingStrategy);
localCache.setIdentifierExtractionStrategy(m -> m.getIssuer());
localCache.setMinRefreshDelay(Duration.ofMillis(100));
@@ -143,8 +149,7 @@ public class BatchMetadatCacheTest {
});
localCache.setRefreshDelayFactor(0.75f);
- localCache.setMinCacheDuration(Duration.ofMinutes(10));
- // cache.setMaxCacheDuration(Duration.ofMinutes(20));
+ localCache.setMinCacheDuration(Duration.ofMinutes(10));
localCache.setMetadataFilterStrategy((metadata, context) -> metadata);
localCache.setId("MockLocalRefreshableCache");
localCache.initialize();
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/BatchMetadataCacheBuilderTest.java
index 34629b3..1f39ac1 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/BatchMetadataCacheBuilderTest.java
@@ -30,6 +30,8 @@ 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.cache.CacheLoadingContext;
+import net.shibboleth.oidc.metadata.cache.LoadingStrategy;
import net.shibboleth.oidc.metadata.criterion.IssuerIDCriterion;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
@@ -40,7 +42,7 @@ public class BatchMetadataCacheBuilderTest {
public void testBatchCacheBuilder_Success() throws ComponentInitializationException {
var builder = new BatchMetadataCacheBuilder.Builder<Issuer, OIDCProviderMetadata>();
- BatchMetadataCacheBuilderSpec<Issuer, OIDCProviderMetadata> spec = new BatchMetadataCacheBuilderSpec<>();
+ final BatchMetadataCacheBuilderSpec<Issuer, OIDCProviderMetadata> spec = new BatchMetadataCacheBuilderSpec<>();
spec.setIdentifierExtractionStrategy(m -> m.getIssuer());
spec.setMinRefreshDelay(Duration.ofMinutes(5));
spec.setMaxRefreshDelay(Duration.ofMinutes(10));
@@ -57,7 +59,18 @@ public class BatchMetadataCacheBuilderTest {
spec.setMinCacheDuration(Duration.ofMinutes(10));
// cache.setMaxCacheDuration(Duration.ofMinutes(20));
spec.setMetadataFilterStrategy((metadata, context) -> metadata);
- spec.setLoadingStrategy(context -> "test".getBytes());
+ spec.setLoadingStrategy(new LoadingStrategy() {
+
+ @Override
+ public byte[] apply(CacheLoadingContext t) {
+ return "test".getBytes();
+ }
+
+ @Override
+ public String getSourceIdentifier() {
+ return "Mock loading source";
+ }
+ });
spec.setParsingStrategy(bytesIn -> {
try {
return List.of(new OIDCProviderMetadata(new Issuer("http://www.example.org"),
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
index 3436572..55ab491 100644
--- 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
@@ -67,7 +67,8 @@ public class DynamicMetadataCacheBuilderTest {
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/impl/OIDCMapMetadataResolverTest.java b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/OIDCMapMetadataResolverTest.java
index 96f877e..28dcf31 100644
--- a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/OIDCMapMetadataResolverTest.java
+++ b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/OIDCMapMetadataResolverTest.java
@@ -24,6 +24,7 @@ import com.nimbusds.oauth2.sdk.id.Issuer;
import net.shibboleth.oidc.metadata.BatchBackingStore;
import net.shibboleth.oidc.metadata.cache.CacheLoadingContext;
+import net.shibboleth.oidc.metadata.cache.LoadingStrategy;
import net.shibboleth.oidc.metadata.cache.impl.BatchMetadataCache;
import net.shibboleth.oidc.metadata.cache.impl.ManuallyTriggeredScheduledExecutorService;
import net.shibboleth.oidc.metadata.criterion.IssuerIDCriterion;
@@ -105,8 +106,19 @@ public class OIDCMapMetadataResolverTest {
@BeforeMethod
public void setup() throws Exception {
- final Function<CacheLoadingContext, byte[]> metadataLoadingStrat =
- c -> GOOD_PROVIDER_CONFIGURATION_INFO.getBytes();
+ final LoadingStrategy metadataLoadingStrat = new LoadingStrategy() {
+
+ @Override
+ public byte[] apply(CacheLoadingContext t) {
+ return GOOD_PROVIDER_CONFIGURATION_INFO.getBytes();
+ }
+
+ @Override
+ public String getSourceIdentifier() {
+ return "Mock loading source";
+ }
+ };
+
final Function<byte[], List<Map<String,Object>>> parsingStrat =
in -> {
@@ -161,7 +173,7 @@ public class OIDCMapMetadataResolverTest {
extends BatchMetadataCache<IdentifierType, MetadataType> {
TestableBatchMetadataCache(@Nonnull final BatchBackingStore<IdentifierType, MetadataType> store,
- @Nonnull final Function<CacheLoadingContext, byte[]> metadataLoadingStrategy,
+ @Nonnull final LoadingStrategy metadataLoadingStrategy,
@Nonnull final Function<byte[], List<MetadataType>> parseStrategy,
@Nullable final ScheduledExecutorService executor) {
super(store, metadataLoadingStrategy, parseStrategy, executor);
diff --git a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/OIDCProviderMetadataResolverTest.java b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/OIDCProviderMetadataResolverTest.java
index ce496c9..0a7985a 100644
--- a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/OIDCProviderMetadataResolverTest.java
+++ b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/OIDCProviderMetadataResolverTest.java
@@ -43,6 +43,7 @@ import net.shibboleth.oidc.metadata.BatchBackingStore;
import net.shibboleth.oidc.metadata.DynamicBackingStore;
import net.shibboleth.oidc.metadata.MetadataManagementData;
import net.shibboleth.oidc.metadata.cache.CacheLoadingContext;
+import net.shibboleth.oidc.metadata.cache.LoadingStrategy;
import net.shibboleth.oidc.metadata.cache.impl.BatchMetadataCache;
import net.shibboleth.oidc.metadata.cache.impl.DynamicMetadataCache;
import net.shibboleth.oidc.metadata.cache.impl.ManuallyTriggeredScheduledExecutorService;
@@ -153,8 +154,18 @@ public class OIDCProviderMetadataResolverTest {
private void setupBatchGlobalCache() throws ComponentInitializationException {
- final Function<CacheLoadingContext, byte[]> metadataLoadingStrat =
- c -> GOOD_PROVIDER_CONFIGURATION_INFO.getBytes();
+ final LoadingStrategy metadataLoadingStrat = new LoadingStrategy() {
+
+ @Override
+ public byte[] apply(CacheLoadingContext t) {
+ return GOOD_PROVIDER_CONFIGURATION_INFO.getBytes();
+ }
+
+ @Override
+ public String getSourceIdentifier() {
+ return "Mock loading source";
+ }
+ };
final Function<byte[], List<OIDCProviderMetadata>> parsingStrat =
in -> {
@@ -423,7 +434,7 @@ public class OIDCProviderMetadataResolverTest {
extends BatchMetadataCache<IdentifierType, MetadataType> {
TestableBatchMetadataCache(@Nonnull final BatchBackingStore<IdentifierType, MetadataType> store,
- @Nonnull final Function<CacheLoadingContext, byte[]> metadataLoadingStrategy,
+ @Nonnull final LoadingStrategy metadataLoadingStrategy,
@Nonnull final Function<byte[], List<MetadataType>> parseStrategy,
@Nullable final ScheduledExecutorService executor) {
super(store, metadataLoadingStrategy, parseStrategy, executor);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list