[java-oidc-common] branch main updated: Add match on identifier required flag to batch metadata cache
Phil Smart
philip.smart at jisc.ac.uk
Thu Nov 4 12:06:49 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=68dca0a4e22f2d60f11bcae3585a8272f1fbbbe1
The following commit(s) were added to refs/heads/main by this push:
new 68dca0a Add match on identifier required flag to batch metadata cache
68dca0a is described below
commit 68dca0a4e22f2d60f11bcae3585a8272f1fbbbe1
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Thu Nov 4 12:06:46 2021 +0000
Add match on identifier required flag to batch metadata cache
- also fix checkstyle and javadoc
---
.../metadata/cache/impl/AbstractMetadataCache.java | 25 +++----
...Spec.java => BaseMetadataCacheBuilderSpec.java} | 22 ++++--
.../metadata/cache/impl/BatchMetadataCache.java | 28 +++++++-
.../cache/impl/BatchMetadataCacheBuilder.java | 3 +-
.../cache/impl/BatchMetadataCacheBuilderSpec.java | 57 ++++++++++++++-
.../cache/impl/DefaultFileLoadingStrategy.java | 26 +++++++
.../cache/impl/DefaultJSONMapParsingStrategy.java | 5 +-
.../cache/impl/DynamicMetadataCacheBuilder.java | 29 +++++++-
.../impl/DynamicMetadataCacheBuilderSpec.java | 26 ++++++-
.../impl/AbstractDynamicHTTPFetchingStrategy.java | 7 +-
.../impl/AbstractFileOIDCEntityResolver.java | 16 -----
.../impl/ChainingProviderMetadataResolver.java | 17 +++++
.../impl/FilesystemProviderMetadataResolver.java | 2 +-
.../impl/ReloadingProviderMetadataProvider.java | 27 ++++++--
.../metadata/cache/impl/BatchMetadatCacheTest.java | 80 ++++++++++++++++++++++
15 files changed, 313 insertions(+), 57 deletions(-)
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 f7d37bf..bef03bf 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,9 +79,6 @@ 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;
@@ -120,19 +117,16 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
/** Whether we created our own schedular during object construction. */
private boolean createOwnSchedular;
- /** Package private constructor. For safe-construction through the factory only.*/
+ /**
+ * Package private constructor. For safe-construction through the factory only.
+ *
+ * @param store the metadata backing store.
+ */
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;
- }
-
/**
*
* Package private constructor. For safe-construction through the factory only.
@@ -225,7 +219,8 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
- criteriaToIdentifierStrategy = Constraint.isNotNull(strategy,"Criteria to identifier strategy can not be null");
+ criteriaToIdentifierStrategy =
+ Constraint.isNotNull(strategy,"Criteria to identifier strategy can not be null");
}
/**
@@ -299,7 +294,8 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
*
* @return the filtering strategy.
*/
- @NonnullAfterInit protected BiFunction<MetadataType, MetadataFilterContext, MetadataType> getMetadataFilterStrategy() {
+ @NonnullAfterInit
+ protected BiFunction<MetadataType, MetadataFilterContext, MetadataType> getMetadataFilterStrategy() {
return metadataFilterStrategy;
}
@@ -365,7 +361,8 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
if (factor <= 0 || factor >= 1) {
- throw new ConstraintViolationException("Refresh delay factor must be a number between 0.0 and 1.0, exclusive");
+ throw new
+ ConstraintViolationException("Refresh delay factor must be a number between 0.0 and 1.0, exclusive");
}
refreshDelayFactor = factor;
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/BaseMetadataCacheBuilderSpec.java
similarity index 92%
rename from oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/MetadataCacheBuilderSpec.java
rename to oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/BaseMetadataCacheBuilderSpec.java
index f8bb0a8..55e4bec 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/BaseMetadataCacheBuilderSpec.java
@@ -37,7 +37,13 @@ import net.shibboleth.utilities.java.support.logic.Constraint;
import net.shibboleth.utilities.java.support.logic.ConstraintViolationException;
import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
-public class MetadataCacheBuilderSpec<IdentifierType, MetadataType> {
+/**
+ * A based metadata cache builder specification.
+ *
+ * @param <IdentifierType> the identifier type.
+ * @param <MetadataType> the metadata type.
+ */
+public abstract class BaseMetadataCacheBuilderSpec<IdentifierType, MetadataType> {
/** Maximum cache duration. */
@Nonnull private Duration maxCacheDuration;
@@ -71,7 +77,7 @@ public class MetadataCacheBuilderSpec<IdentifierType, MetadataType> {
/** Constructor.*/
- protected MetadataCacheBuilderSpec() {
+ protected BaseMetadataCacheBuilderSpec() {
// defaults
maxCacheDuration = Duration.ofHours(8);
minCacheDuration = Duration.ofMinutes(10);
@@ -107,7 +113,8 @@ public class MetadataCacheBuilderSpec<IdentifierType, MetadataType> {
*
* @param hook the hook to run.
*/
- public void setMetadataBeforeRemovalHook(@Nullable final BiConsumer<List<MetadataType>, IdentifierType> hook) {
+ public void setMetadataBeforeRemovalHook(@Nullable final BiConsumer<List<MetadataType>,
+ IdentifierType> hook) {
metadataBeforeRemovalHook = hook;
}
@@ -127,7 +134,8 @@ public class MetadataCacheBuilderSpec<IdentifierType, MetadataType> {
*
* @param strategy the metadata filtering strategy.
*/
- public void setMetadataFilterStrategy(@Nonnull final BiFunction<MetadataType, MetadataFilterContext, MetadataType> strategy) {
+ public void setMetadataFilterStrategy(@Nonnull final BiFunction<MetadataType, MetadataFilterContext,
+ MetadataType> strategy) {
metadataFilterStrategy = Constraint.isNotNull(strategy,"Metadata filtering strategy can not be null");
}
@@ -146,7 +154,8 @@ public class MetadataCacheBuilderSpec<IdentifierType, MetadataType> {
*
* @param strategy the strategy to set.
*/
- public void setIdentifierExtractionStrategy(@Nonnull final Function<MetadataType, IdentifierType> strategy) {
+ public void setIdentifierExtractionStrategy(
+ @Nonnull final Function<MetadataType, IdentifierType> strategy) {
identifierExtractionStrategy = Constraint.isNotNull(strategy, "Strategy can not be null");
}
@@ -272,7 +281,8 @@ public class MetadataCacheBuilderSpec<IdentifierType, MetadataType> {
public void setRefreshDelayFactor(@Nonnull final Float factor) {
if (factor <= 0 || factor >= 1) {
- throw new ConstraintViolationException("Refresh delay factor must be a number between 0.0 and 1.0, exclusive");
+ throw new
+ ConstraintViolationException("Refresh delay factor must be a number between 0.0 and 1.0, exclusive");
}
refreshDelayFactor = factor;
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 7e47d73..ae168d3 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
@@ -77,6 +77,12 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
/** How to parse the loaded metadata from the loadingStrategy into a usable metadatatype.*/
@Nonnull private final Function<byte[], List<MetadataType>> parsingStrategy;
+
+ /**
+ * Is a match based on an identifier required? If not,
+ * all known metadata will be returned. Defaults to true - a match on identifier is required.
+ */
+ @Nonnull private boolean matchOnIdentifierRequired;
/**
@@ -110,6 +116,7 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
loadingStrategy =
Constraint.isNotNull(metadataLoadingStrategy, "Metadata loading strategy can not be null");
parsingStrategy = Constraint.isNotNull(parseStrategy, "Metadata Parsing strategy can not be null");
+ matchOnIdentifierRequired = true;
}
@Override
@@ -127,6 +134,18 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
}
}
+
+ /**
+ * Set if a match on identifier is required in order to return results. If false and there are no
+ * identifiers in the criteria to match on, all cached entries will be returned.
+ *
+ * @param required does the metadata lookup need to match the given criteria.
+ */
+ public void setMatchOnIdentifierRequired(final boolean required) {
+ matchOnIdentifierRequired = required;
+ }
+
+
/**
* {@inheritDoc}
*
@@ -185,9 +204,13 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
getLogPrefix(), allMetadata.size(), identifier);
return allMetadata;
}
+ } else if (!matchOnIdentifierRequired) {
+ log.debug("{} No identifier found to lookup, matchOnIdentifierRequired is false, returning all known "
+ + "metadata",getLogPrefix());
+ return Collections.unmodifiableList(getBackingStore().getOrderedValues());
} else {
// TODO: see SAML version, could resolve from criteria even if no identifier.
- log.debug("{} Identifier not resolvable from criteria, can not fetch metadata", getLogPrefix());
+ log.debug("{} No identifier found to lookup, returning empty result", getLogPrefix());
return Collections.emptyList();
}
}
@@ -263,7 +286,8 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
new AsynchronousRefreshAHeadTask()), nextRefreshDelay, TimeUnit.MILLISECONDS);
log.info("{} Next refresh cycle for metadata provider '{}' will occur on '{}' ('{}' local time)",
- getLogPrefix(), loadingStrategy.getSourceIdentifier(), nextRefresh, nextRefresh.atZone(ZoneId.systemDefault()));
+ getLogPrefix(), loadingStrategy.getSourceIdentifier(), nextRefresh,
+ nextRefresh.atZone(ZoneId.systemDefault()));
}
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
index 61e444f..f2089ef 100644
--- 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
@@ -62,7 +62,7 @@ public final class BatchMetadataCacheBuilder {
final BatchMetadataCache<IdentifierType, MetadataType> cache =
new BatchMetadataCache<>(
- new DefaultBatchBackingStore<>(), spec.getLoadingStrategy(), spec.getParsingStrategy());
+ new DefaultBatchBackingStore<>(), spec.getLoadingStrategy(), spec.getParsingStrategy());
cache.setMinCacheDuration(spec.getMinCacheDuration());
// cache.setMaxCacheDuration(getMaxCacheDuration());
cache.setMinRefreshDelay(spec.getMinRefreshDelay());
@@ -73,6 +73,7 @@ public final class BatchMetadataCacheBuilder {
cache.setCriteriaToIdentifierStrategy(spec.getCriteriaToIdentifierStrategy());
cache.setMetadataFilterStrategy(spec.getMetadataFilterStrategy());
cache.setMetadataBeforeRemovalHook(spec.getMetadataBeforeRemovalHook());
+ cache.setMatchOnIdentifierRequired(spec.isMatchOnIdentifierRequired());
cache.setId("BatchMetadataCache");
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 b301611..fd0828c 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
@@ -1,3 +1,21 @@
+/*
+ * 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 java.time.Duration;
@@ -11,8 +29,14 @@ import net.shibboleth.oidc.metadata.cache.LoadingStrategy;
import net.shibboleth.utilities.java.support.annotation.constraint.Positive;
import net.shibboleth.utilities.java.support.logic.Constraint;
+/**
+ * A specification for building a batch based read-ahead metadata cache.
+ *
+ * @param <IdentifierType> The metadata identifier type.
+ * @param <MetadataType> the metadata type.
+ */
public class BatchMetadataCacheBuilderSpec<IdentifierType, MetadataType>
- extends MetadataCacheBuilderSpec<IdentifierType, MetadataType> {
+ extends BaseMetadataCacheBuilderSpec<IdentifierType, MetadataType> {
/**
* How to parse the loaded metadata from the loadingStrategy into a usable metadatatype.
@@ -32,10 +56,37 @@ public class BatchMetadataCacheBuilderSpec<IdentifierType, MetadataType>
/** Floor, in milliseconds, for the refresh interval. Default value: 5 minutes */
@Nonnull @Positive private Duration minRefreshDelay;
+ /**
+ * Is a match based on an identifier required? If not,
+ * all known metadata will be returned. Defaults to true - a match on identifier is required.
+ */
+ @Nonnull private boolean matchOnIdentifierRequired;
+
/** Constructor.*/
public BatchMetadataCacheBuilderSpec() {
maxRefreshDelay = Duration.ofHours(4);
- minRefreshDelay = Duration.ofMinutes(5);
+ minRefreshDelay = Duration.ofMinutes(5);
+ matchOnIdentifierRequired = false;
+ }
+
+
+ /**
+ * Set if a match on identifier is required in order to return results. If false and there are no
+ * identifiers in the criteria to match on, all cached entries will be returned.
+ *
+ * @param required does the metadata lookup need to match the given criteria.
+ */
+ public void setMatchRequired(final boolean required) {
+ matchOnIdentifierRequired = required;
+ }
+
+ /**
+ * Get if an identifier criteria match is required.
+ *
+ * @return is an identifier criteria match required.
+ */
+ public boolean isMatchOnIdentifierRequired(){
+ return matchOnIdentifierRequired;
}
/**
@@ -101,7 +152,7 @@ public class BatchMetadataCacheBuilderSpec<IdentifierType, MetadataType>
*
* @param strategy the strategy to set.
*/
- public void setLoadingStrategy(@Nonnull LoadingStrategy strategy) {
+ public void setLoadingStrategy(final @Nonnull LoadingStrategy strategy) {
loadingStrategy = Constraint.isNotNull(strategy,"Batch metadata loading strategy can not be null");
}
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 ddf64c7..14b7328 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
@@ -1,3 +1,21 @@
+/*
+ * 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 java.io.File;
@@ -28,6 +46,14 @@ public class DefaultFileLoadingStrategy implements LoadingStrategy {
/** The metadata file. */
@Nonnull private final File metadataFile;
+ /**
+ *
+ * Constructor.
+ *
+ * @param metadata the metadata file resource
+ *
+ * @throws IOException if the file does not exist.
+ */
public DefaultFileLoadingStrategy(@Nonnull final Resource metadata) throws IOException {
Constraint.isNotNull(metadata, "The metadata file can not be null");
metadataFile = metadata.getFile();
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DefaultJSONMapParsingStrategy.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DefaultJSONMapParsingStrategy.java
index b9f91fd..97f0f41 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DefaultJSONMapParsingStrategy.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DefaultJSONMapParsingStrategy.java
@@ -58,14 +58,15 @@ public class DefaultJSONMapParsingStrategy<V extends Object>
objectMapper = Constraint.isNotNull(mapper, "Object mapper can not be null");
}
+ /** Constructor.*/
public DefaultJSONMapParsingStrategy() {
this(new ObjectMapper());
}
@Override
- public List<Map<String, V>> apply(byte[] rawMetadata) {
+ public List<Map<String, V>> apply(@Nonnull final byte[] rawMetadata) {
try {
- Map<String, V> parsed =
+ final Map<String, V> parsed =
objectMapper.readValue(new String(rawMetadata, StandardCharsets.UTF_8),
new TypeReference<Map<String,V>>(){});
if (parsed != null) {
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 a1905d0..85ae283 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
@@ -1,3 +1,20 @@
+/*
+ * 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;
@@ -12,9 +29,6 @@ import net.shibboleth.utilities.java.support.component.ComponentInitializationEx
*
* <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>
- *
- * @param <IdentifierType> The identifier type
- * @param <MetadataType> The metadata type
*/
public final class DynamicMetadataCacheBuilder {
@@ -31,6 +45,15 @@ public final class DynamicMetadataCacheBuilder {
*/
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 {
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 186643b..df4fdb6 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
@@ -1,3 +1,21 @@
+/*
+ * 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 java.time.Duration;
@@ -9,8 +27,14 @@ import javax.annotation.Nullable;
import net.shibboleth.utilities.java.support.logic.Constraint;
import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
+/**
+ * A specification for building a dynamic read-through metadata cache.
+ *
+ * @param <IdentifierType> The metadata identifier type.
+ * @param <MetadataType> the metadata type.
+ */
public class DynamicMetadataCacheBuilderSpec <IdentifierType, MetadataType>
- extends MetadataCacheBuilderSpec<IdentifierType, MetadataType> {
+ extends BaseMetadataCacheBuilderSpec<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/impl/AbstractDynamicHTTPFetchingStrategy.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/AbstractDynamicHTTPFetchingStrategy.java
index c4de82f..d33b306 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
@@ -63,15 +63,16 @@ import net.shibboleth.utilities.java.support.resolver.ResolverException;
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",
- "application/samlmetadata+xml", "application/xml", "text/xml"};
/** MDC attribute representing the current request URI. Will be available during the execution of the
* configured {@link ResponseHandler}. */
public static final String MDC_ATTRIB_CURRENT_REQUEST_URI =
AbstractDynamicHTTPFetchingStrategy.class.getName() + ".currentRequestURI";
+ /** Default list of supported content MIME types. */
+ private static final String[] DEFAULT_CONTENT_TYPES = new String[] {"application/json",
+ "application/samlmetadata+xml", "application/xml", "text/xml"};
+
/** Class logger. */
@Nonnull private final Logger log = LoggerFactory.getLogger(AbstractDynamicHTTPFetchingStrategy.class);
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/AbstractFileOIDCEntityResolver.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/AbstractFileOIDCEntityResolver.java
index b8015bc..19a621b 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/AbstractFileOIDCEntityResolver.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/AbstractFileOIDCEntityResolver.java
@@ -36,22 +36,6 @@ import net.shibboleth.utilities.java.support.component.ComponentSupport;
import net.shibboleth.utilities.java.support.logic.Constraint;
import net.shibboleth.utilities.java.support.resolver.ResolverException;
-/*
- * 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.
- */
/**
* Based on {@link org.opensaml.saml.metadata.resolver.impl.FilesystemMetadataResolver}.
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/ChainingProviderMetadataResolver.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/ChainingProviderMetadataResolver.java
index c79a56d..831bbc7 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/ChainingProviderMetadataResolver.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/ChainingProviderMetadataResolver.java
@@ -1,3 +1,20 @@
+/*
+ * 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.impl;
import java.time.Instant;
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/FilesystemProviderMetadataResolver.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/FilesystemProviderMetadataResolver.java
index 32321df..c34f75a 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/FilesystemProviderMetadataResolver.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/FilesystemProviderMetadataResolver.java
@@ -114,7 +114,7 @@ public class FilesystemProviderMetadataResolver extends AbstractFileOIDCEntityRe
return new ArrayList<>(getBackingStore().getOrderedInformation());
}
// TODO: support other criterion
- return new ArrayList<>((lookupIdentifier(issuerIdCriterion.getIssuerID())));
+ return new ArrayList<>(lookupIdentifier(issuerIdCriterion.getIssuerID()));
}
/** {@inheritDoc} */
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/ReloadingProviderMetadataProvider.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/ReloadingProviderMetadataProvider.java
index f23f19c..0514180 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/ReloadingProviderMetadataProvider.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/ReloadingProviderMetadataProvider.java
@@ -1,3 +1,20 @@
+/*
+ * 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.impl;
import java.util.Collections;
@@ -38,7 +55,7 @@ public class ReloadingProviderMetadataProvider extends AbstractIdentifiableIniti
*/
public ReloadingProviderMetadataProvider(
@Nonnull final ReloadableService<ProviderMetadataResolver> resolverService) {
- service = Constraint.isNotNull(resolverService, "IssuerMetadataResolver Service cannot be null");
+ service = Constraint.isNotNull(resolverService, "ProviderMetadataResolver Service cannot be null");
}
@Override
@@ -48,14 +65,14 @@ public class ReloadingProviderMetadataProvider extends AbstractIdentifiableIniti
try {
component = service.getServiceableComponent();
if (null == component) {
- log.error("ReloadingIssuerMetadataProvider '{}': Error accessing underlying source: "
+ log.error("ReloadingProviderMetadataProvider '{}': Error accessing underlying source: "
+ "Invalid configuration.", getId());
} else {
final ProviderMetadataResolver resolver = component.getComponent();
return resolver.resolve(criteria);
}
} catch (final ResolverException e) {
- log.error("IssuerMetadataResolver '{}': Error during resolution", getId(), e);
+ log.error("ProviderMetadataResolver '{}': Error during resolution", getId(), e);
} finally {
if (null != component) {
component.unpinComponent();
@@ -71,14 +88,14 @@ public class ReloadingProviderMetadataProvider extends AbstractIdentifiableIniti
try {
component = service.getServiceableComponent();
if (null == component) {
- log.error("ReloadingIssuerMetadataProvider '{}': Error accessing underlying source: "
+ log.error("ReloadingProviderMetadataProvider '{}': Error accessing underlying source: "
+ "Invalid configuration.", getId());
} else {
final ProviderMetadataResolver resolver = component.getComponent();
return resolver.resolveSingle(criteria);
}
} catch (final ResolverException e) {
- log.error("IssuerMetadataResolver '{}': Error during resolution", getId(), e);
+ log.error("ProviderMetadataResolver '{}': Error during resolution", getId(), e);
} finally {
if (null != component) {
component.unpinComponent();
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 4acf467..ff35478 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
@@ -18,6 +18,7 @@
package net.shibboleth.oidc.metadata.cache.impl;
+import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.io.UnsupportedEncodingException;
@@ -33,6 +34,7 @@ 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;
import org.testng.annotations.Test;
@@ -156,6 +158,84 @@ public class BatchMetadatCacheTest {
Thread.sleep(2000);
}
+
+ @Test
+ public void testFetchAllNoDirectMatch() throws ComponentInitializationException,
+ InterruptedException, MetadataCacheException {
+
+ // create a loading strategy that does nothing. We are going to fake the parsing strategy
+ // to return two provider metadata entries.
+ var simpleLoadingStrategy = new LoadingStrategy() {
+
+ @Override
+ public byte[] apply(CacheLoadingContext t) {
+ return "".getBytes();
+ }
+
+ @Override
+ public String getSourceIdentifier() {
+ return "Mock loading source";
+ }
+ };
+
+ //create a parsing strategy that loads two provider metadatas
+ Function<byte[], List<OIDCProviderMetadata>> simpleParsingStrategy = in -> {
+ try {
+ return List.of(
+ new OIDCProviderMetadata(new Issuer("http://www.example.one.org"), List.of(SubjectType.PUBLIC),
+ new URI("http://example.one.oidc.op.org")),
+ new OIDCProviderMetadata(new Issuer("http://www.example.two.org"), List.of(SubjectType.PUBLIC),
+ new URI("http://example.two.oidc.op.org"))
+ );
+ } catch (final URISyntaxException e) {
+ return null;
+ }
+ };
+
+ final BatchMetadataCache<Issuer, OIDCProviderMetadata> localCache =
+ new BatchMetadataCache<Issuer, OIDCProviderMetadata>(
+ new DefaultBatchBackingStore<Issuer, OIDCProviderMetadata>(), simpleLoadingStrategy,
+ simpleParsingStrategy, scheduler);
+
+ localCache.setIdentifierExtractionStrategy(m -> m.getIssuer());
+ localCache.setMinRefreshDelay(Duration.ofMillis(100));
+ localCache.setMaxRefreshDelay(Duration.ofMillis(200));
+ localCache.setMetadataExpirationTimeStrategy((m, time) -> time.plus(Duration.ofMinutes(5)));
+ localCache.setCriteriaToIdentifierStrategy(crit -> {
+ final IssuerIDCriterion issuerId = crit.get(IssuerIDCriterion.class);
+ if (issuerId != null) {
+ return issuerId.getIssuerID();
+ }
+ return null;
+ });
+
+ localCache.setRefreshDelayFactor(0.75f);
+ localCache.setMinCacheDuration(Duration.ofMinutes(10));
+ localCache.setMetadataFilterStrategy((metadata, context) -> metadata);
+ localCache.setId("MockLocalRefreshableCache");
+ //If no match, return all
+ localCache.setMatchOnIdentifierRequired(false);
+ localCache.initialize();
+
+ // The criteria is not supported, so no metadata will be found.
+ // However, match required is false, so all metadata will be returned.
+ List<OIDCProviderMetadata> allMetadata =
+ localCache.get(new CriteriaSet(new EntityIdCriterion("http://entityid.com")));
+ assertEquals(allMetadata.size(), 2);
+
+ }
+
+ @Test
+ public void testNoUsableIdentifierInCriteria_EmptyList() throws ComponentInitializationException,
+ InterruptedException, MetadataCacheException {
+ cache.initialize();
+ // Strategy does not accept entityID criterion, so no identifier returned. Hence
+ // no results
+ List<OIDCProviderMetadata> metadata =
+ cache.get(new CriteriaSet(new EntityIdCriterion("http://entityid.com")));
+ assertTrue(metadata.isEmpty() == true);
+
+ }
@Test
public void testGetNotCached_Success() throws MetadataCacheException, ComponentInitializationException {
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list