[java-oidc-common] branch main updated: Nonnull cleanup
Phil Smart
philip.smart at jisc.ac.uk
Fri Apr 5 11:03:22 UTC 2024
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=6b22edb06170887e329068995f0d16202486fe35
The following commit(s) were added to refs/heads/main by this push:
new 6b22edb Nonnull cleanup
6b22edb is described below
commit 6b22edb06170887e329068995f0d16202486fe35
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Fri Apr 5 12:03:18 2024 +0100
Nonnull cleanup
---
.../oidc/metadata/MetadataManagementData.java | 6 +-
.../oidc/metadata/cache/ExpirationTimeContext.java | 2 +-
.../metadata/cache/impl/AbstractMetadataCache.java | 42 ++++---
.../metadata/cache/impl/BatchMetadataCache.java | 21 ++--
.../cache/impl/BatchMetadataCacheBuilderSpec.java | 4 +-
.../metadata/cache/impl/DynamicMetadataCache.java | 123 +++++++++++++--------
.../impl/DynamicMetadataCacheBuilderSpec.java | 10 +-
.../cache/impl/FetchThroughMetadataCache.java | 10 +-
.../metadata/cache/impl/MetadataCacheBuilder.java | 37 ++++---
.../impl/AbstractDynamicHTTPFetchingStrategy.java | 7 +-
.../impl/AbstractFileOIDCEntityResolver.java | 6 +-
.../metadata/impl/AbstractOIDCEntityResolver.java | 8 +-
.../impl/AbstractOIDCMetadataResolver.java | 20 ++--
.../impl/AbstractReloadingOIDCEntityResolver.java | 15 ++-
...seStorageServiceClientInformationComponent.java | 3 +-
.../impl/ClientInformationNodeProcessor.java | 7 +-
.../metadata/impl/DefaultDynamicBackingStore.java | 13 ++-
.../oidc/metadata/impl/EmptyBackingStore.java | 43 +++++++
.../impl/FilesystemClientInformationResolver.java | 11 +-
.../impl/FilesystemProviderMetadataResolver.java | 8 +-
.../HTTPProviderConfigurationFetchingStrategy.java | 6 +-
.../ResolverServiceClientSecretValueResolver.java | 7 +-
.../StorageServiceClientInformationManager.java | 7 +-
.../StorageServiceClientInformationResolver.java | 1 +
24 files changed, 263 insertions(+), 154 deletions(-)
diff --git a/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/MetadataManagementData.java b/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/MetadataManagementData.java
index b29a883..9631de8 100644
--- a/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/MetadataManagementData.java
+++ b/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/MetadataManagementData.java
@@ -40,13 +40,13 @@ public class MetadataManagementData<MetadataIdentifier> {
@Nullable private Instant lastUpdateTime;
/** Expiration time of the associated metadata. */
- private Instant expirationTime;
+ @Nullable private Instant expirationTime;
/** Time at which should start attempting to refresh the metadata. */
- private Instant refreshTriggerTime;
+ @Nullable private Instant refreshTriggerTime;
/** The last time at which the entity's backing store data was accessed. */
- private Instant lastAccessedTime;
+ @Nullable private Instant lastAccessedTime;
/** Read-write stamped lock which governs access to the metadata's backing store data. */
@Nonnull private final StampedLock stmpLock;
diff --git a/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/cache/ExpirationTimeContext.java b/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/cache/ExpirationTimeContext.java
index b98bb8b..16a863f 100644
--- a/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/cache/ExpirationTimeContext.java
+++ b/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/cache/ExpirationTimeContext.java
@@ -47,7 +47,7 @@ public class ExpirationTimeContext<T> {
*
* @param metadataIn the metadata to base the expiry time off.
* @param minimumCacheDuration minimum cache duration.
- * @param maximumCacheDuration maximum cache duration. *
+ * @param maximumCacheDuration maximum cache duration.
* @param timeNow the now time to base computation off.
*/
public ExpirationTimeContext(@Nonnull final T metadataIn,
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 79e07e9..cbb82db 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
@@ -77,7 +77,7 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
@NonnullAfterInit @Positive private Float refreshDelayFactor;
/** Backing store for runtime metadata.*/
- @Nullable private final BackingStore<IdentifierType, MetadataType> backingStore;
+ @Nonnull private final BackingStore<IdentifierType, MetadataType> backingStore;
/**
* A hook that is executed just before a cache entry will been removed/invalidated/evicted.
@@ -108,7 +108,7 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
*
* @param store the metadata backing store.
*/
- AbstractMetadataCache(@Nullable final BackingStore<IdentifierType, MetadataType> store) {
+ AbstractMetadataCache(@Nonnull final BackingStore<IdentifierType, MetadataType> store) {
this(store, null);
}
@@ -122,9 +122,9 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
* @param store the backing store.
* @param executor the scheduled executor
*/
- AbstractMetadataCache(@Nullable final BackingStore<IdentifierType, MetadataType> store,
+ AbstractMetadataCache(@Nonnull final BackingStore<IdentifierType, MetadataType> store,
@Nullable final ScheduledExecutorService executor) {
- backingStore = store;
+ backingStore = Constraint.isNotNull(store, "Backing store can not be null");
if (executor != null) {
executorService = executor;
createOwnSchedular = false;
@@ -198,8 +198,7 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
* @param predicate the predicate.
*/
public void setMetadataValidPredicate(@Nonnull final Predicate<MetadataType> predicate) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
metadataValidPredicate = Constraint.isNotNull(predicate, "Is metadata valid predicate can not be null");
}
@@ -209,7 +208,7 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
*
* @return the predicate.
*/
- @Nonnull protected Predicate<MetadataType> getMetadataValidPredicate() {
+ @NonnullAfterInit protected Predicate<MetadataType> getMetadataValidPredicate() {
return metadataValidPredicate;
}
@@ -219,8 +218,7 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
* @param strategy the strategy.
*/
public void setCriteriaToIdentifierStrategy(@Nonnull final Function<CriteriaSet, IdentifierType> strategy) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
criteriaToIdentifierStrategy =
Constraint.isNotNull(strategy,"Criteria to identifier strategy can not be null");
@@ -241,8 +239,7 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
* @param strategy the strategy.
*/
public void setIdentifierExtractionStrategy(@Nonnull final Function<MetadataType, IdentifierType> strategy) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
identifierExtractionStrategy = Constraint.isNotNull(strategy, "Identifier extraction strategy can not be null");
}
@@ -263,8 +260,7 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
*/
public void setMetadataFilterStrategy(
@Nonnull final BiFunction<MetadataType, MetadataFilterContext, MetadataType> strategy) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
metadataFilterStrategy = Constraint.isNotNull(strategy, "Metadata filter strategy can not be null");
}
@@ -287,8 +283,7 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
*/
public void setMetadataBeforeRemovalHook(
@Nullable final BiConsumer<List<MetadataType>, IdentifierType> hook) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
metadataBeforeRemovalHook = hook;
}
@@ -302,8 +297,7 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
* @param factor delay factor used to compute the next refresh time
*/
public void setRefreshDelayFactor(@Nonnull final Float factor) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
if (factor <= 0 || factor >= 1) {
throw new
@@ -384,7 +378,7 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
*
* @return the backing store. Can be {@literal null}.
*/
- @Nullable protected BackingStore<IdentifierType, MetadataType> getBackingStore() {
+ @Nonnull protected BackingStore<IdentifierType, MetadataType> getBackingStore() {
return backingStore;
}
@@ -396,8 +390,10 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
*/
protected void freshLoad(@Nonnull final List<MetadataType> metadataToStore) {
invalidateAll();
- for (final MetadataType metadata : metadataToStore) {
- writeToBackingStore(metadata);
+ for (final MetadataType metadata : metadataToStore) {
+ if (metadata != null) {
+ writeToBackingStore(metadata);
+ }
}
}
@@ -421,12 +417,12 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
// by this point
invalidate(extractedIdentifier);
- backingStore.getOrderedValues().add(metadata);
+ getBackingStore().getOrderedValues().add(metadata);
// add new metadata to index
- List<MetadataType> existingMetadata = backingStore.getIndexedValues().get(extractedIdentifier);
+ List<MetadataType> existingMetadata = getBackingStore().getIndexedValues().get(extractedIdentifier);
if (existingMetadata == null) {
existingMetadata = new ArrayList<>();
- backingStore.getIndexedValues().put(extractedIdentifier, existingMetadata);
+ getBackingStore().getIndexedValues().put(extractedIdentifier, existingMetadata);
} else if (!existingMetadata.isEmpty()) {
log.warn("{} Detected duplicate metadata for identifier: {}", getLogPrefix(), extractedIdentifier);
}
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 2b16f83..8c91f31 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
@@ -167,8 +167,7 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
* @param predicate the predicate.
*/
public void setSourceMetadataValidPredicate(@Nonnull final Predicate<byte[]> predicate) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
sourceMetadataValidPredicate =
Constraint.isNotNull(predicate, "Is source metadata valid predicate can not be null");
@@ -189,8 +188,7 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
* @param strategy the loading strategy.
*/
public void setLoadingStrategy(@Nonnull final LoadingStrategy strategy) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
loadingStrategy = Constraint.isNotNull(strategy, "Loading strategy can not be null");
}
@@ -210,8 +208,7 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
* @param strategy the parsing strategy.
*/
public void setParsingStrategy(@Nonnull final Function<byte[], List<MetadataType>> strategy) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
parsingStrategy = Constraint.isNotNull(strategy, "Parsing strategy can not be null");
}
@@ -231,8 +228,7 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
* @param strategy the strategy.
*/
public void setSourceMetadataExpiryStrategy(@Nonnull final Function<byte[], Instant> strategy) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
sourceMetadataExpiryStrategy =
Constraint.isNotNull(strategy, "Source metadata expiry strategy can not be null");
@@ -254,8 +250,7 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
* @param required does the metadata lookup need to match the given criteria.
*/
public void setMatchOnIdentifierRequired(final boolean required) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
matchOnIdentifierRequired = required;
}
@@ -285,8 +280,7 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
* @param delay minimum amount of time between refreshes
*/
public void setMinRefreshDelay(@Positive @Nonnull final Duration delay) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
Constraint.isFalse(delay == null || delay.isNegative(), "Minimum refresh delay must be greater than 0");
minRefreshDelay = delay;
@@ -307,8 +301,7 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
* @param delay maximum amount of time, in milliseconds, between refresh intervals
*/
public void setMaxRefreshDelay(@Positive @Nonnull final Duration delay) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
Constraint.isFalse(delay == null || delay.isNegative(), "Maximum refresh delay must be greater than 0");
maxRefreshDelay = delay;
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 649cea8..83eeabb 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
@@ -72,8 +72,8 @@ public class BatchMetadataCacheBuilderSpec<IdentifierType, MetadataType>
/** Constructor.*/
public BatchMetadataCacheBuilderSpec() {
super();
- maxRefreshDelay = Duration.ofHours(4);
- minRefreshDelay = Duration.ofMinutes(5);
+ maxRefreshDelay = Constraint.isNotNull(Duration.ofHours(4), "Duration can not be null");
+ minRefreshDelay = Constraint.isNotNull(Duration.ofMinutes(5), "Duration can not be null");
matchOnIdentifierRequired = false;
sourceMetadataValidPredicate = PredicateSupport.alwaysTrue();
}
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 88d7612..dc0de28 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
@@ -46,6 +46,7 @@ import net.shibboleth.oidc.metadata.cache.MetadataCacheException;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.annotation.constraint.NonnullElements;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
@@ -150,10 +151,12 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
@Nullable final ScheduledExecutorService executor) {
super(store, executor);
mgmtMappingFunction = id -> {
+ assert id != null;
final Instant now = Instant.now();
final MetadataManagementData<IdentifierType> mgmt = new MetadataManagementData<>(id);
- mgmt.setRefreshTriggerTime(now.plus(maxCacheDuration));
- mgmt.setExpirationTime(now.plus(maxCacheDuration));
+ mgmt.setRefreshTriggerTime(Constraint.isNotNull(now.plus(maxCacheDuration),
+ "Refresh Trigger cannot be null"));
+ mgmt.setExpirationTime(Constraint.isNotNull(now.plus(maxCacheDuration),"Refresh Trigger cannot be null"));
return mgmt;
};
@@ -166,8 +169,7 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
* @param duration the minimum cache duration
*/
public void setMinCacheDuration(@Nonnull final Duration duration) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
Constraint.isNotNull(duration, "Duration cannot be null");
Constraint.isFalse(duration.isNegative(), "Duration cannot be negative");
@@ -180,7 +182,9 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
*
* @param duration the maximum cache duration
*/
- public void setMaxCacheDuration(@Nonnull final Duration duration) {
+ public void setMaxCacheDuration(@Nonnull final Duration duration) {
+ checkSetterPreconditions();
+
Constraint.isNotNull(duration, "Duration cannot be null");
Constraint.isFalse(duration.isNegative(), "Duration cannot be negative");
@@ -193,8 +197,7 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
* @param strategy the strategy used to fetch metadata using a 'read-through' semantic.
*/
public void setFetchStrategy(@Nonnull final Function<CriteriaSet, MetadataType> strategy) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
fetchStrategy = Constraint.isNotNull(strategy, "Dynamic Metadata fetch strategy can not be null");
}
@@ -205,8 +208,7 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
* @param delay The initialCleanupTaskDelay to set.
*/
public void setInitialCleanupTaskDelay(@Nonnull final Duration delay) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
Constraint.isNotNull(delay, "Cleanup task delay can not be null");
Constraint.isFalse(delay.isNegative() || delay.isZero(), "Cleanup task delay must be positive");
@@ -219,12 +221,16 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
protected void doDestroy() {
if (ratioGaugeFetchToGet != null) {
- MetricsSupport.remove(MetricRegistry.name(metricsBaseName, METRIC_RATIOGAUGE_FETCH_TO_GET),
- ratioGaugeFetchToGet);
+ final String name = MetricRegistry.name(metricsBaseName, METRIC_RATIOGAUGE_FETCH_TO_GET);
+ if (name != null) {
+ MetricsSupport.remove(name, ratioGaugeFetchToGet);
+ }
}
if (gaugeNumLiveIndexedMetadata != null) {
- MetricsSupport.remove(MetricRegistry.name(metricsBaseName, METRIC_GAUGE_NUM_LIVE_INDEX_METADATA),
- gaugeNumLiveIndexedMetadata);
+ final String name = MetricRegistry.name(metricsBaseName, METRIC_GAUGE_NUM_LIVE_INDEX_METADATA);
+ if (name != null) {
+ MetricsSupport.remove(name, gaugeNumLiveIndexedMetadata);
+ }
}
ratioGaugeFetchToGet = null;
gaugeNumLiveIndexedMetadata = null;
@@ -243,8 +249,7 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
* @param interval the interval to set
*/
public void setCleanupTaskInterval(@Nonnull final Duration interval) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
Constraint.isNotNull(interval, "Cleanup task interval may not be null");
Constraint.isFalse(interval.isNegative() || interval.isZero(), "Cleanup task interval must be positive");
@@ -258,8 +263,8 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
* @param flag true if idle entity data should be removed, false otherwise
*/
public void setRemoveIdleEntityData(final boolean flag) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
+
removeIdleEntityData = flag;
}
@@ -272,8 +277,7 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
* @param max the maximum entity data idle time
*/
public void setMaxIdleEntityData(@Nonnull final Duration max) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
Constraint.isNotNull(max, "Max idle time cannot be null");
Constraint.isFalse(max.isNegative(), "Max idle time cannot be negative");
@@ -288,8 +292,7 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
*/
public void setMetadataExpirationTimeStrategy(
@Nonnull final Function<ExpirationTimeContext<MetadataType>, Instant> strategy) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
metadataExpirationTimeStrategy = Constraint.isNotNull(strategy, "Metadata expiration strategy can not be null");
}
@@ -343,23 +346,28 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
MetricRegistry.name(metricsBaseName, METRIC_TIMER_GET));
timerFetchFromSource = metricRegistry.timer(
MetricRegistry.name(metricsBaseName, METRIC_TIMER_FETCH_FROM_ORIGIN_SOURCE));
+ final var localTimeFromSource = timerFetchFromSource;
+ final var localTimeGet = timerGet;
- // Note that these gauges must use the support method to register in a synchronized fashion,
- // and also must store off the instances for later use in destroy.
- ratioGaugeFetchToGet = MetricsSupport.register(
- MetricRegistry.name(metricsBaseName, METRIC_RATIOGAUGE_FETCH_TO_GET),
- new RatioGauge() {
- @Override
- protected Ratio getRatio() {
- return Ratio.of(timerFetchFromSource.getCount(),
- timerGet.getCount());
- }},
- true);
-
- gaugeNumLiveIndexedMetadata = MetricsSupport.register(
- MetricRegistry.name(metricsBaseName, METRIC_GAUGE_NUM_LIVE_INDEX_METADATA),
- () -> getBackingStore().getIndexedValues().keySet().size(),
- true);
+ if (localTimeFromSource != null && localTimeGet != null) {
+ // Note that these gauges must use the support method to register in a synchronized fashion,
+ // and also must store off the instances for later use in destroy.
+ ratioGaugeFetchToGet = MetricsSupport.register(
+ Constraint.isNotNull(MetricRegistry.name(metricsBaseName,
+ METRIC_RATIOGAUGE_FETCH_TO_GET),"Metric value can not be null"),
+ new RatioGauge() {
+ @Override
+ protected Ratio getRatio() {
+ return Ratio.of(localTimeFromSource.getCount(), localTimeGet.getCount());
+ }},
+ true);
+
+ gaugeNumLiveIndexedMetadata = MetricsSupport.register(
+ Constraint.isNotNull(MetricRegistry.name(metricsBaseName, METRIC_GAUGE_NUM_LIVE_INDEX_METADATA),
+ "Metric value can not be null"),
+ () -> getBackingStore().getIndexedValues().keySet().size(),
+ true);
+ }
}
}
@@ -370,8 +378,7 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
* @param baseName the Metrics base name
*/
public synchronized void setMetricsBaseName(@Nullable final String baseName) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
metricsBaseName = StringSupport.trimOrNull(baseName);
}
@@ -424,7 +431,7 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
} else {
//TODO: see SAML version, could resolve from criteria even if no identifier.
log.debug("Identifier not resolvable from criteria, can not fetch metadata");
- return Collections.emptyList();
+ return CollectionSupport.emptyList();
}
} finally {
MetricsSupport.stopTimer(contextResolve);
@@ -445,6 +452,8 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
@Nonnull final IdentifierType identifier,
@Nonnull @NotEmpty final CriteriaSet criteria) throws MetadataCacheException{
+ checkComponentActive();
+
final StampedLock sl = mgmtData.getStampLock();
final long stamp = sl.writeLock();
@@ -496,6 +505,7 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
private void storeNewMetadata(@Nonnull final MetadataManagementData<IdentifierType> mgmtData,
@Nonnull final MetadataType metadata,
@Nonnull final IdentifierType expectedIdentifier) {
+ checkComponentActive();
final MetadataType filteredMetadata = getMetadataFilterStrategy().apply(metadata, newFilterContext());
@@ -523,13 +533,16 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
writeToBackingStore(filteredMetadata);
final Instant now = Instant.now();
+ assert now != null;
log.debug("{} For metadata '{}' expiration and refresh computation, 'now' is : {}",
getLogPrefix(), extractedIdentifier, now);
mgmtData.setLastUpdateTime(now);
- mgmtData.setExpirationTime(getMetadataExpirationTimeStrategy()
- .apply(createExpirationTimeContext(filteredMetadata, now)));
+ final Instant expiryTime =
+ getMetadataExpirationTimeStrategy().apply(createExpirationTimeContext(filteredMetadata, now));
+ assert expiryTime != null;
+ mgmtData.setExpirationTime(expiryTime);
log.debug("{} Computed metadata '{}' expiration time: {}", getLogPrefix(),
extractedIdentifier, mgmtData.getExpirationTime());
@@ -549,10 +562,14 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
*
* @return an expiration time context.
*/
- protected ExpirationTimeContext<MetadataType> createExpirationTimeContext(
+ @Nonnull protected ExpirationTimeContext<MetadataType> createExpirationTimeContext(
@Nonnull final MetadataType metadata,
@Nonnull final Instant now){
- return new ExpirationTimeContext<>(metadata, minCacheDuration, maxCacheDuration, now);
+ checkComponentActive();
+ final Duration localMinCacheDuration = minCacheDuration;
+ final Duration localMaxCacheDuration = maxCacheDuration;
+ assert localMaxCacheDuration != null && localMinCacheDuration != null;
+ return new ExpirationTimeContext<>(metadata, localMinCacheDuration, localMaxCacheDuration, now);
}
/**
@@ -580,7 +597,9 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
refreshDelay = minCacheDuration.toMillis();
}
- return nowDateTime.plusMillis(refreshDelay);
+ final Instant refreshTiggerTime = nowDateTime.plusMillis(refreshDelay);
+ assert refreshTiggerTime != null;
+ return refreshTiggerTime;
}
/**
@@ -598,13 +617,14 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
*
* @throws MetadataCacheException on error.
*/
- @Nonnull private List<MetadataType> read(@Nonnull final MetadataManagementData<IdentifierType> mgmtData,
+ @Nonnull @NonnullElements private List<MetadataType> read(
+ @Nonnull final MetadataManagementData<IdentifierType> mgmtData,
@Nonnull final IdentifierType identifier) throws MetadataCacheException {
// Do not read if expired.
if (hasExpired(mgmtData)) {
log.trace("{} Metadata has expired for '{}'", getLogPrefix(), identifier);
- return Collections.emptyList();
+ return CollectionSupport.emptyList();
}
// record access attempt.
@@ -660,6 +680,7 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
private void removeExpiredAndIdleMetadata() {
final Instant now = Instant.now();
final Instant earliestValidLastAccessed = now.minus(maxIdleEntityData);
+ assert earliestValidLastAccessed != null;
final DynamicBackingStore<IdentifierType, MetadataType> store = getBackingStore();
final Set<IdentifierType> ids = new HashSet<>();
@@ -667,6 +688,9 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
ids.addAll(store.getManagementDataIdentifiers());
for (final IdentifierType identifier : ids) {
+ if (identifier == null) {
+ continue;
+ }
final MetadataManagementData<IdentifierType> mgmtData =
store.computeManagementDataIfAbsent(identifier, mgmtMappingFunction);
@@ -695,7 +719,10 @@ public class DynamicMetadataCache<IdentifierType, MetadataType>
*/
private boolean isRemoveData(@Nonnull final MetadataManagementData<IdentifierType> mgmtData,
@Nonnull final Instant now, @Nonnull final Instant earliestValidLastAccessed) {
- if (removeIdleEntityData && mgmtData.getLastAccessedTime().isBefore(earliestValidLastAccessed)) {
+
+ final Instant lastAccessedTime = mgmtData.getLastAccessedTime();
+ if (removeIdleEntityData && lastAccessedTime != null &&
+ lastAccessedTime.isBefore(earliestValidLastAccessed)) {
log.debug("{} Metadata exceeds maximum idle time, removing: {}", getLogPrefix(), mgmtData.getID());
return true;
} else if (now.isAfter(mgmtData.getExpirationTime())) {
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 4fcbce7..e1f9ac0 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
@@ -63,11 +63,11 @@ public class DynamicMetadataCacheBuilderSpec <IdentifierType, MetadataType>
/** Constructor. */
protected DynamicMetadataCacheBuilderSpec() {
- maxCacheDuration = Duration.ofHours(8);
- minCacheDuration = Duration.ofMinutes(10);
- maxIdleEntityData = Duration.ofHours(8);
- cleanupTaskInterval = Duration.ofMinutes(30);
- initialCleanupTaskDelay = Duration.ofMinutes(1);
+ maxCacheDuration = Constraint.isNotNull(Duration.ofHours(8), "Duration can not be null");
+ minCacheDuration = Constraint.isNotNull(Duration.ofMinutes(10), "Duration can not be null");
+ maxIdleEntityData = Constraint.isNotNull(Duration.ofHours(8), "Duration can not be null");
+ cleanupTaskInterval = Constraint.isNotNull(Duration.ofMinutes(30), "Duration can not be null");
+ initialCleanupTaskDelay = Constraint.isNotNull(Duration.ofMinutes(1), "Duration can not be null");
removeIdleEntityData = true;
}
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/FetchThroughMetadataCache.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/FetchThroughMetadataCache.java
index 7133c59..b4f9d2d 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/FetchThroughMetadataCache.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/FetchThroughMetadataCache.java
@@ -26,6 +26,7 @@ import org.slf4j.Logger;
import net.shibboleth.oidc.metadata.cache.MetadataCache;
import net.shibboleth.oidc.metadata.cache.MetadataCacheException;
+import net.shibboleth.oidc.metadata.impl.EmptyBackingStore;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.annotation.constraint.NonnullElements;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
@@ -58,8 +59,8 @@ public class FetchThroughMetadataCache <IdentifierType, MetadataType>
/** Constructor. */
protected FetchThroughMetadataCache() {
- // Does not require a backingstore.
- super(null);
+ // Does not require a backingstore, so use the empty type.
+ super(new EmptyBackingStore<>());
}
/** {@inheritDoc} */
@@ -79,8 +80,7 @@ public class FetchThroughMetadataCache <IdentifierType, MetadataType>
* @param strategy the strategy used to fetch metadata using a 'read-through' semantic.
*/
public void setFetchStrategy(@Nonnull final Function<CriteriaSet, MetadataType> strategy) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
fetchStrategy = Constraint.isNotNull(strategy, "Dynamic Metadata fetch strategy can not be null");
}
@@ -89,7 +89,7 @@ public class FetchThroughMetadataCache <IdentifierType, MetadataType>
@Override
@Nonnull @NonnullElements @NotLive public List<MetadataType> get(
@Nonnull @NotEmpty final CriteriaSet criteria) throws MetadataCacheException {
-
+
if (!isInitialized()) {
throw new MetadataCacheException("Metadata cache has not been initialized");
}
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
index 007544b..5a5532f 100644
--- 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
@@ -22,6 +22,7 @@ import net.shibboleth.oidc.metadata.cache.MetadataCache;
import net.shibboleth.oidc.metadata.impl.DefaultBatchBackingStore;
import net.shibboleth.oidc.metadata.impl.DefaultDynamicBackingStore;
import net.shibboleth.shared.component.ComponentInitializationException;
+import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
/**
@@ -56,7 +57,7 @@ public final class MetadataCacheBuilder {
*
* @throws ComponentInitializationException on error.
*/
- public MetadataCache<MetadataType> build(
+ @Nonnull public MetadataCache<MetadataType> build(
@Nonnull final MetadataCacheBuilderSpec<IdentifierType, MetadataType> specification)
throws ComponentInitializationException {
@@ -66,14 +67,19 @@ public final class MetadataCacheBuilder {
final BatchMetadataCache<IdentifierType, MetadataType> cache =
new BatchMetadataCache<>(
new DefaultBatchBackingStore<>());
- cache.setSourceMetadataExpiryStrategy(spec.getSourceMetadataExpiryStrategy());
- cache.setLoadingStrategy(spec.getLoadingStrategy());
- cache.setParsingStrategy(spec.getParsingStrategy());
+ cache.setSourceMetadataExpiryStrategy(Constraint.isNotNull(spec.getSourceMetadataExpiryStrategy(),
+ "Metadata expiry strategy can not be null"));
+ cache.setLoadingStrategy(Constraint.isNotNull(spec.getLoadingStrategy(),
+ "Loading strategy can not be null"));
+ cache.setParsingStrategy(Constraint.isNotNull(spec.getParsingStrategy(),
+ "Parsing strategy can not be null"));
cache.setMinRefreshDelay(spec.getMinRefreshDelay());
cache.setMaxRefreshDelay(spec.getMaxRefreshDelay());
cache.setRefreshDelayFactor(spec.getRefreshDelayFactor());
- cache.setIdentifierExtractionStrategy(spec.getIdentifierExtractionStrategy());
- cache.setCriteriaToIdentifierStrategy(spec.getCriteriaToIdentifierStrategy());
+ cache.setIdentifierExtractionStrategy(Constraint.isNotNull(spec.getIdentifierExtractionStrategy(),
+ "Identifier extraction strategy can not be null"));
+ cache.setCriteriaToIdentifierStrategy(Constraint.isNotNull(spec.getCriteriaToIdentifierStrategy(),
+ "Criteria to identifier strategy can not be null"));
cache.setMetadataFilterStrategy(spec.getMetadataFilterStrategy());
cache.setMetadataBeforeRemovalHook(spec.getMetadataBeforeRemovalHook());
cache.setMatchOnIdentifierRequired(spec.isMatchOnIdentifierRequired());
@@ -87,14 +93,17 @@ public final class MetadataCacheBuilder {
(DynamicMetadataCacheBuilderSpec<IdentifierType, MetadataType>) specification;
final DynamicMetadataCache<IdentifierType, MetadataType> cache = new DynamicMetadataCache<>(
new DefaultDynamicBackingStore<>());
- cache.setFetchStrategy(spec.getFetchStrategy());
+ cache.setFetchStrategy(Constraint.isNotNull(spec.getFetchStrategy(),"Fetch strategy can not be null"));
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.setMetadataExpirationTimeStrategy(Constraint.isNotNull(spec.getMetadataExpirationTimeStrategy(),
+ "Metadata expiry strategy can not be null"));
+ cache.setIdentifierExtractionStrategy(Constraint.isNotNull(spec.getIdentifierExtractionStrategy(),
+ "Identifier extraction strategy can not be null"));
+ cache.setCriteriaToIdentifierStrategy(Constraint.isNotNull(spec.getCriteriaToIdentifierStrategy(),
+ "Criteria to identifier strategy can not be null"));
cache.setCleanupTaskInterval(spec.getCleanupTaskInterval());
cache.setRemoveIdleEntityData(spec.isRemoveIdleEntityData());
cache.setInitialCleanupTaskDelay(spec.getInitialCleanupTaskDelay());
@@ -108,11 +117,13 @@ public final class MetadataCacheBuilder {
final FetchThroughMetadataCacheBuilderSpec<IdentifierType, MetadataType> spec =
(FetchThroughMetadataCacheBuilderSpec<IdentifierType, MetadataType>) specification;
final FetchThroughMetadataCache<IdentifierType, MetadataType> cache = new FetchThroughMetadataCache<>();
- cache.setFetchStrategy(spec.getFetchStrategy());
+ cache.setFetchStrategy(Constraint.isNotNull(spec.getFetchStrategy(),"Fetch strategy can not be null"));
//TODO refresh delay is not really needed here.
cache.setRefreshDelayFactor(spec.getRefreshDelayFactor());
- cache.setIdentifierExtractionStrategy(spec.getIdentifierExtractionStrategy());
- cache.setCriteriaToIdentifierStrategy(spec.getCriteriaToIdentifierStrategy());
+ cache.setIdentifierExtractionStrategy(Constraint.isNotNull(spec.getIdentifierExtractionStrategy(),
+ "Identifier extraction strategy can not be null"));
+ cache.setCriteriaToIdentifierStrategy(Constraint.isNotNull(spec.getCriteriaToIdentifierStrategy(),
+ "Criteria to identifier strategy can not be null"));
cache.setMetadataFilterStrategy(spec.getMetadataFilterStrategy());
cache.setMetadataBeforeRemovalHook(spec.getMetadataBeforeRemovalHook());
cache.setMetadataValidPredicate(spec.getMetadataValidPredicate());
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 d869f09..86bf04d 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
@@ -109,13 +109,16 @@ public abstract class AbstractDynamicHTTPFetchingStrategy<MetadataType>
@Override
protected void doInitialize() throws ComponentInitializationException {
super.doInitialize();
-
+
if (getSupportedContentTypes() == null) {
setSupportedContentTypes(Arrays.asList(DEFAULT_CONTENT_TYPES));
}
+ final List<String> localSupportedContentTypes = getSupportedContentTypes();
+ // Can not be null by this point
+ assert localSupportedContentTypes != null;
if (! getSupportedContentTypes().isEmpty()) {
- supportedContentTypesValue = StringSupport.listToStringValue(getSupportedContentTypes(), ", ");
+ supportedContentTypesValue = StringSupport.listToStringValue(localSupportedContentTypes, ", ");
supportedMediaTypes = new LazySet<>();
for (final String contentType : getSupportedContentTypes()) {
supportedMediaTypes.add(MediaType.parse(contentType));
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 9c52851..b3ee9aa 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
@@ -88,7 +88,11 @@ public abstract class AbstractFileOIDCEntityResolver<Key extends Identifier, Val
/** {@inheritDoc} */
@Override
protected String getMetadataIdentifier() {
- return metadataFile.getAbsolutePath();
+ final String path = metadataFile.getAbsolutePath();
+ if (path == null) {
+ return "unknown";
+ }
+ return path;
}
/**
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/AbstractOIDCEntityResolver.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/AbstractOIDCEntityResolver.java
index 6707cfa..00d3ac4 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/AbstractOIDCEntityResolver.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/AbstractOIDCEntityResolver.java
@@ -26,6 +26,7 @@ import org.slf4j.Logger;
import com.google.common.base.Strings;
import com.nimbusds.oauth2.sdk.id.Identifier;
+import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.annotation.constraint.NonnullElements;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
import net.shibboleth.shared.collection.CollectionSupport;
@@ -49,7 +50,7 @@ public abstract class AbstractOIDCEntityResolver<Key extends Identifier, Value>
@Nonnull private final Logger log = LoggerFactory.getLogger(AbstractOIDCEntityResolver.class);
/** Backing store for runtime JSON data. */
- private JsonBackingStore jsonBackingStore;
+ @NonnullAfterInit private JsonBackingStore jsonBackingStore;
/** Logging prefix. */
private String logPrefix;
@@ -97,8 +98,7 @@ public abstract class AbstractOIDCEntityResolver<Key extends Identifier, Value>
* @param failFast whether problems during initialization should cause the provider to fail
*/
public void setFailFastInitialization(final boolean failFast) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkSetterPreconditions();
failFastInitialization = failFast;
}
@@ -239,7 +239,7 @@ public abstract class AbstractOIDCEntityResolver<Key extends Identifier, Value>
*
* @return the current effective entity backing store
*/
- @Nonnull protected JsonBackingStore getBackingStore() {
+ @NonnullAfterInit protected JsonBackingStore getBackingStore() {
return jsonBackingStore;
}
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/AbstractOIDCMetadataResolver.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/AbstractOIDCMetadataResolver.java
index 56fe456..b85f780 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/AbstractOIDCMetadataResolver.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/AbstractOIDCMetadataResolver.java
@@ -14,7 +14,6 @@
package net.shibboleth.oidc.metadata.impl;
-import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -34,6 +33,7 @@ import net.shibboleth.oidc.metadata.cache.MetadataCache;
import net.shibboleth.oidc.metadata.cache.MetadataCacheException;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.component.DestructableComponent;
@@ -104,8 +104,7 @@ public abstract class AbstractOIDCMetadataResolver<MetadataIdentifier, MetadataT
/** {@inheritDoc} */
@Override
@Nullable public MetadataType resolveSingle(@Nullable final CriteriaSet criteria) throws ResolverException {
- ifNotInitializedThrowUninitializedComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkComponentActive();
final Iterable<MetadataType> iterable = resolve(criteria);
if (iterable != null) {
@@ -120,11 +119,10 @@ public abstract class AbstractOIDCMetadataResolver<MetadataIdentifier, MetadataT
/** {@inheritDoc} */
@Override
@Nonnull public Iterable<MetadataType> resolve(@Nullable final CriteriaSet criteria) throws ResolverException {
- ifNotInitializedThrowUninitializedComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkComponentActive();
- try {
- final List<MetadataType> metadata = getCache().get(criteria);
+ try {
+ final List<MetadataType> metadata = getCache().get(criteria != null ? criteria : new CriteriaSet());
return predicateFilterCandidates(metadata, criteria, false);
} catch (final MetadataCacheException e) {
@@ -145,13 +143,14 @@ public abstract class AbstractOIDCMetadataResolver<MetadataIdentifier, MetadataT
*
* @throws ResolverException if there is a fatal error during resolution
*/
- protected Iterable<MetadataType> predicateFilterCandidates(@Nonnull final Iterable<MetadataType> candidates,
+ @Nonnull protected Iterable<MetadataType> predicateFilterCandidates(
+ @Nonnull final Iterable<MetadataType> candidates,
@Nullable final CriteriaSet criteria, final boolean onEmptyPredicatesReturnEmpty)
throws ResolverException {
if (!candidates.iterator().hasNext()) {
log.debug("{} Candidates iteration was empty, nothing to filter via predicates", getLogPrefix());
- return Collections.emptySet();
+ return CollectionSupport.emptySet();
}
log.debug("{} Attempting to filter candidate metadata via resolved Predicates", getLogPrefix());
@@ -164,7 +163,8 @@ public abstract class AbstractOIDCMetadataResolver<MetadataIdentifier, MetadataT
log.trace("{} Resolved {} Predicates: {}", getLogPrefix(), predicates.size(), predicates);
final boolean satisfyAny;
- final SatisfyAnyCriterion satisfyAnyCriterion = criteria.get(SatisfyAnyCriterion.class);
+ final SatisfyAnyCriterion satisfyAnyCriterion =
+ criteria != null ? criteria.get(SatisfyAnyCriterion.class) : null;
if (satisfyAnyCriterion != null) {
log.trace("{} CriteriaSet contained SatisfyAnyCriterion", getLogPrefix());
satisfyAny = satisfyAnyCriterion.isSatisfyAny();
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/AbstractReloadingOIDCEntityResolver.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/AbstractReloadingOIDCEntityResolver.java
index f372571..484f5f2 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/AbstractReloadingOIDCEntityResolver.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/AbstractReloadingOIDCEntityResolver.java
@@ -62,10 +62,10 @@ public abstract class AbstractReloadingOIDCEntityResolver<Key extends Identifier
* Refresh interval used when metadata does not contain any validUntil or cacheDuration information. Default value:
* 4 hours
*/
- @Nonnull @Positive private Duration maxRefreshDelay = Duration.ofHours(4);
+ @Nonnull @Positive private Duration maxRefreshDelay;
/** Floor, in milliseconds, for the refresh interval. Default value: 5 minutes */
- @Nonnull @Positive private Duration minRefreshDelay = Duration.ofMinutes(5);
+ @Nonnull @Positive private Duration minRefreshDelay;
/** Last time the metadata was updated. */
@Nullable private Instant lastUpdate;
@@ -79,6 +79,8 @@ public abstract class AbstractReloadingOIDCEntityResolver<Key extends Identifier
/** Constructor. */
protected AbstractReloadingOIDCEntityResolver() {
this(null);
+ maxRefreshDelay = Constraint.isNotNull(Duration.ofHours(4),"Duration can not be null");
+ minRefreshDelay = Constraint.isNotNull(Duration.ofMinutes(5),"Duration can not be null");
}
/**
@@ -94,6 +96,8 @@ public abstract class AbstractReloadingOIDCEntityResolver<Key extends Identifier
taskTimer = backgroundTaskTimer;
createdOwnTaskTimer = false;
}
+ maxRefreshDelay = Constraint.isNotNull(Duration.ofHours(4),"Duration can not be null");
+ minRefreshDelay = Constraint.isNotNull(Duration.ofMinutes(5),"Duration can not be null");
}
@Override
@@ -207,11 +211,14 @@ public abstract class AbstractReloadingOIDCEntityResolver<Key extends Identifier
refreshDelay = maxRefreshDelay;
}
nextRefresh = Instant.now().plus(refreshDelay);
- final long nextRefreshDelay = nextRefresh.toEpochMilli() - System.currentTimeMillis();
+ final Instant localNextRefresh = nextRefresh;
+ assert localNextRefresh != null;
+ final long nextRefreshDelay = localNextRefresh.toEpochMilli() - System.currentTimeMillis();
taskTimer.schedule(refreshMetadataTask, nextRefreshDelay);
log.info("Next refresh cycle for metadata provider '{}' will occur on '{}' ('{}' local time)",
- new Object[] {getMetadataIdentifier(), nextRefresh, nextRefresh.atZone(ZoneId.systemDefault()),});
+ new Object[] {getMetadataIdentifier(), localNextRefresh,
+ localNextRefresh.atZone(ZoneId.systemDefault()),});
}
/**
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/BaseStorageServiceClientInformationComponent.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/BaseStorageServiceClientInformationComponent.java
index 9c6c6c9..213b49b 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/BaseStorageServiceClientInformationComponent.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/BaseStorageServiceClientInformationComponent.java
@@ -43,6 +43,7 @@ public abstract class BaseStorageServiceClientInformationComponent extends Abstr
*
* {@inheritDoc}
*/
+ @Override
protected void doInitialize() throws ComponentInitializationException {
super.doInitialize();
@@ -66,7 +67,7 @@ public abstract class BaseStorageServiceClientInformationComponent extends Abstr
* @param storage the back-end to use
*/
public void setStorageService(@Nonnull final StorageService storage) {
- ifInitializedThrowUnmodifiabledComponentException();
+ checkSetterPreconditions();
storageService = Constraint.isNotNull(storage, "StorageService cannot be null");
}
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/ClientInformationNodeProcessor.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/ClientInformationNodeProcessor.java
index f381543..c1f1748 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/ClientInformationNodeProcessor.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/ClientInformationNodeProcessor.java
@@ -124,7 +124,9 @@ public class ClientInformationNodeProcessor implements MetadataNodeProcessor {
return;
}
final Iterable<Credential> credentials = resolveCredentials(roleDescriptor);
- final OIDCClientMetadata metadata = populateMetadata(roleDescriptor, credentials, clientId.getValue());
+ final String clientIdValue = clientId.getValue();
+ assert clientIdValue != null;
+ final OIDCClientMetadata metadata = populateMetadata(roleDescriptor, credentials, clientIdValue);
final Secret clientSecret = parseClientSecret(credentials);
final OIDCClientInformation clientInformation =
new OIDCClientInformation(clientId, null, metadata, clientSecret);
@@ -542,6 +544,9 @@ public class ClientInformationNodeProcessor implements MetadataNodeProcessor {
@Nonnull protected Set<URI> parseUris(final @Nonnull List<? extends MetadataValueSAMLObject> listOfValues) {
final Set<URI> uris = new HashSet<>();
for (final MetadataValueSAMLObject value : listOfValues) {
+ if (value == null) {
+ continue;
+ }
final URI uri = getSingleURIValue(value);
if (uri != null) {
uris.add(uri);
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/DefaultDynamicBackingStore.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/DefaultDynamicBackingStore.java
index 6d5e682..26254a7 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/DefaultDynamicBackingStore.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/DefaultDynamicBackingStore.java
@@ -54,9 +54,13 @@ public class DefaultDynamicBackingStore<I,T> extends AbstractBackingStore<I,T> i
/** {@inheritDoc} */
@Nonnull public MetadataManagementData<I> computeManagementDataIfAbsent(@Nonnull final I identifier,
@Nonnull final Function<I, MetadataManagementData<I>> mappingFunction) {
- Constraint.isNotNull(identifier, "identifier may not be null");
+ Constraint.isNotNull(identifier, "identifier cannot be null");
+ Constraint.isNotNull(mappingFunction, "Mapping function cannot be null");
- return mgmtDataMap.computeIfAbsent(identifier, mappingFunction);
+ // As parameters are nonnull, computeIfAbsent should always return a value
+ final MetadataManagementData<I> data = mgmtDataMap.computeIfAbsent(identifier, mappingFunction);
+ assert data != null;
+ return data;
}
/** {@inheritDoc} */
@@ -69,7 +73,7 @@ public class DefaultDynamicBackingStore<I,T> extends AbstractBackingStore<I,T> i
/** {@inheritDoc} */
public synchronized void removeManagementData(@Nonnull final I identifier) {
//TODO is concurrent hashmap threadsafe for remove and get - do we need the synchronized
- Constraint.isNotNull(identifier, "Identifier may not be null");
+ Constraint.isNotNull(identifier, "Identifier may not be null");
mgmtDataMap.remove(identifier);
}
@@ -77,7 +81,8 @@ public class DefaultDynamicBackingStore<I,T> extends AbstractBackingStore<I,T> i
/** {@inheritDoc} */
@Nonnull @NonnullElements @Unmodifiable @NotLive
public synchronized Set<I> getManagementDataIdentifiers() {
- return CollectionSupport.copyToSet(mgmtDataMap.keySet());
+ final Set<I> keySet = mgmtDataMap.keySet();
+ return keySet == null ? CollectionSupport.emptySet() : CollectionSupport.copyToSet(keySet);
}
}
\ No newline at end of file
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/EmptyBackingStore.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/EmptyBackingStore.java
new file mode 100644
index 0000000..5a5fb38
--- /dev/null
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/EmptyBackingStore.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed 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.List;
+import java.util.Map;
+
+import javax.annotation.Nonnull;
+
+import net.shibboleth.shared.annotation.constraint.NotLive;
+import net.shibboleth.shared.annotation.constraint.Unmodifiable;
+import net.shibboleth.shared.collection.CollectionSupport;
+
+/**
+ * A backing store which provides no functionality other than to return empty unmodifiable lists.
+ *
+ * @since 3.1.0
+ */
+public final class EmptyBackingStore<I,T> extends AbstractBackingStore<I, T> {
+
+ @Override
+ @Nonnull @Unmodifiable @NotLive public Map<I, List<T>> getIndexedValues() {
+ return CollectionSupport.copyToMap(super.getIndexedValues());
+ }
+
+ @Override
+ @Nonnull @Unmodifiable @NotLive public List<T> getOrderedValues() {
+ return CollectionSupport.copyToList(super.getOrderedValues());
+ }
+
+}
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/FilesystemClientInformationResolver.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/FilesystemClientInformationResolver.java
index c2490a7..658dee5 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/FilesystemClientInformationResolver.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/FilesystemClientInformationResolver.java
@@ -85,8 +85,7 @@ public class FilesystemClientInformationResolver extends AbstractFileOIDCEntityR
@Override
@Nonnull public Iterable<OIDCClientInformation> resolve(@Nullable final CriteriaSet criteria)
throws ResolverException {
- ifNotInitializedThrowUninitializedComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkComponentActive();
final ClientIDCriterion clientIdCriterion = criteria != null ? criteria.get(ClientIDCriterion.class) : null;
if (clientIdCriterion == null || clientIdCriterion.getClientID() == null) {
@@ -105,7 +104,8 @@ public class FilesystemClientInformationResolver extends AbstractFileOIDCEntityR
*
* @return The OIDC client informations, containing contents of getJWKSetURI() in getJWKSet().
*/
- protected List<OIDCClientInformation> updateKeys(final List<OIDCClientInformation> clientInformations) {
+ @Nonnull protected List<OIDCClientInformation> updateKeys(
+ @Nonnull final List<OIDCClientInformation> clientInformations) {
final List<OIDCClientInformation> result = new ArrayList<>();
for (final OIDCClientInformation clientInformation : clientInformations) {
result.add(clientInformation);
@@ -134,6 +134,7 @@ public class FilesystemClientInformationResolver extends AbstractFileOIDCEntityR
final String rawString = new String(bytes);
try {
final OIDCClientInformation single = OIDCClientInformation.parse(JSONObjectUtils.parse(rawString));
+ assert single != null;
log.debug("Found single client information from the file");
return CollectionSupport.singletonList(single);
} catch (final ParseException e) {
@@ -155,7 +156,9 @@ public class FilesystemClientInformationResolver extends AbstractFileOIDCEntityR
/** {@inheritDoc} */
@Override
@Nonnull protected ClientID getKey(@Nonnull final OIDCClientInformation value) {
- return value.getID();
+ final ClientID id = value.getID();
+ assert id != null;
+ return id;
}
}
\ No newline at end of file
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 68391be..13ea32b 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
@@ -106,12 +106,16 @@ public class FilesystemProviderMetadataResolver extends AbstractFileOIDCEntityRe
/** {@inheritDoc} */
@Override
@Nonnull protected List<OIDCProviderMetadata> parse(@Nonnull final byte[] bytes) throws ParseException {
- return CollectionSupport.singletonList(OIDCProviderMetadata.parse(JSONObjectUtils.parse(new String(bytes))));
+ final OIDCProviderMetadata metadata = OIDCProviderMetadata.parse(JSONObjectUtils.parse(new String(bytes)));
+ assert metadata != null;
+ return CollectionSupport.singletonList(metadata);
}
/** {@inheritDoc} */
@Override
@Nonnull protected Issuer getKey(@Nonnull final OIDCProviderMetadata value) {
- return value.getIssuer();
+ final Issuer iss = value.getIssuer();
+ assert iss != null;
+ return iss;
}
}
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 55a1489..0bb3988 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
@@ -15,7 +15,6 @@
package net.shibboleth.oidc.metadata.impl;
import java.io.IOException;
-import java.util.Set;
import java.util.function.BiFunction;
import javax.annotation.Nonnull;
@@ -38,6 +37,7 @@ import com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata;
import net.shibboleth.oidc.metadata.criterion.IssuerIDCriterion;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.net.MediaTypeSupport;
import net.shibboleth.shared.primitive.LoggerFactory;
@@ -184,6 +184,7 @@ public class HTTPProviderConfigurationFetchingStrategy
// this should convert the entity with the character set from the entity.
final String jsonDocument = EntityUtils.toString(response.getEntity());
final OIDCProviderMetadata metadata = OIDCProviderMetadata.parse(jsonDocument);
+ assert metadata != null;
if (!metadataValid(metadata, currentRequestURI)) {
return null;
}
@@ -231,7 +232,8 @@ public class HTTPProviderConfigurationFetchingStrategy
final String contentTypeValue = response.getEntity().getContentType();
log.debug("Saw raw Content-Type from response header '{}'", contentTypeValue);
- if (!MediaTypeSupport.validateContentType(contentTypeValue, Set.of(CONTENT_TYPE), true, false)) {
+ if (!MediaTypeSupport.validateContentType(contentTypeValue,
+ CollectionSupport.setOf(CONTENT_TYPE), true, false)) {
throw new ResolverException("HTTP response specified an unsupported Content-Type MIME type: "
+ contentTypeValue);
}
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/ResolverServiceClientSecretValueResolver.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/ResolverServiceClientSecretValueResolver.java
index fa4d6c2..76fa639 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/ResolverServiceClientSecretValueResolver.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/ResolverServiceClientSecretValueResolver.java
@@ -108,8 +108,7 @@ public class ResolverServiceClientSecretValueResolver extends AbstractClientSecr
/** {@inheritDoc} */
@Override
@Nonnull public Iterable<String> resolve(@Nullable final CriteriaSet criteria) throws ResolverException {
- ifNotInitializedThrowUninitializedComponentException();
- ifDestroyedThrowDestroyedComponentException();
+ checkComponentActive();
final ClientSecretReferenceCriterion referenceCriterion =
criteria != null ? criteria.get(ClientSecretReferenceCriterion.class) : null;
@@ -128,7 +127,9 @@ public class ResolverServiceClientSecretValueResolver extends AbstractClientSecr
resolutionContext.setAttributeRecipientID(entityIdCrit.getEntityId());
}
- resolutionContext.resolveAttributes(service);
+ final var localService = getAttributeResolver();
+ assert localService != null;
+ resolutionContext.resolveAttributes(localService);
final Map<String, IdPAttribute> resolvedAttributes = resolutionContext.getResolvedIdPAttributes();
final LazySet<String> result = new LazySet<>();
for (final String attributeId : attributeIds) {
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/StorageServiceClientInformationManager.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/StorageServiceClientInformationManager.java
index a82365d..ab52590 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/StorageServiceClientInformationManager.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/StorageServiceClientInformationManager.java
@@ -45,9 +45,10 @@ public class StorageServiceClientInformationManager extends BaseStorageServiceCl
@Nullable final Instant expiration, final boolean replace) throws ClientInformationManagerException {
log.debug("Attempting to store client information (replace={})", replace ? "true" : "false");
- final String clientId = clientInformation.getID().getValue();
+ final String clientId = clientInformation.getID().getValue();
//TODO: configurable serialization
final String serialized = clientInformation.toJSONObject().toJSONString();
+ assert clientId != null && serialized != null;
try {
if (getStorageService().create(CONTEXT_NAME, clientId, serialized,
expiration != null ? expiration.toEpochMilli() : null)) {
@@ -80,7 +81,9 @@ public class StorageServiceClientInformationManager extends BaseStorageServiceCl
return;
}
try {
- getStorageService().delete(CONTEXT_NAME, clientId.getValue());
+ final String clientIdValue = clientId.getValue();
+ assert clientIdValue != null;
+ getStorageService().delete(CONTEXT_NAME, clientIdValue);
} catch (final IOException e) {
log.error("Could not delete the client ID {}", clientId.getValue(), e);
}
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/StorageServiceClientInformationResolver.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/StorageServiceClientInformationResolver.java
index 47af830..f9dbfab 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/StorageServiceClientInformationResolver.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/StorageServiceClientInformationResolver.java
@@ -59,6 +59,7 @@ public class StorageServiceClientInformationResolver extends BaseStorageServiceC
}
// TODO: support other criterion
final String clientId = clientIdCriterion.getClientID().getValue();
+ assert clientId != null;
final List<OIDCClientInformation> result = new ArrayList<>();
try {
final StorageRecord<?> record = getStorageService().read(CONTEXT_NAME, clientId);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list