[java-oidc-common] branch main updated: JCOMOIDC-23 - Add OpenID Provider Configuration Document Resolver

Phil Smart philip.smart at jisc.ac.uk
Wed Feb 23 10:45:33 UTC 2022


This is an automated email from the git hooks/post-receive script.

philsmart pushed a commit to branch main
in repository java-oidc-common.

View the commit online:
http://git.shibboleth.net/view/?p=java-oidc-common.git;a=commit;h=d870dd9a564189799872014c71093d5f42a8e3e9

The following commit(s) were added to refs/heads/main by this push:
     new d870dd9  JCOMOIDC-23 - Add OpenID Provider Configuration Document Resolver
d870dd9 is described below

commit d870dd9a564189799872014c71093d5f42a8e3e9
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Wed Feb 23 10:45:19 2022 +0000

    JCOMOIDC-23 - Add OpenID Provider Configuration Document Resolver
    
    Remove functional interface from loading strategy. Be clearer on
    contract and semantics, including throwing a checked exception on error.
    
    Fix tests.
    
    https://shibboleth.atlassian.net/browse/JCOMOIDC-23
---
 .../oidc/metadata/cache/CacheLoadingException.java | 46 ++++++++++++++
 .../oidc/metadata/cache/LoadingStrategy.java       | 20 +++++-
 .../metadata/cache/impl/AbstractMetadataCache.java |  4 +-
 .../metadata/cache/impl/BatchMetadataCache.java    |  2 +-
 .../cache/impl/DefaultFileLoadingStrategy.java     | 11 ++--
 .../MetadataPolicyViaLocationFetchingStrategy.java | 22 ++++---
 .../cache/impl/BatchMetadataCacheBuilderTest.java  |  8 +--
 .../cache/impl/BatchMetadataCacheTest.java         | 73 +++++++++++++++-------
 .../impl/DefaultFileLoadingStrategyTest.java       | 12 ++--
 .../metadata/impl/OIDCMapMetadataResolverTest.java |  3 +-
 .../impl/OIDCProviderMetadataResolverTest.java     | 32 +++++-----
 11 files changed, 165 insertions(+), 68 deletions(-)

diff --git a/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/cache/CacheLoadingException.java b/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/cache/CacheLoadingException.java
new file mode 100644
index 0000000..af14681
--- /dev/null
+++ b/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/cache/CacheLoadingException.java
@@ -0,0 +1,46 @@
+package net.shibboleth.oidc.metadata.cache;
+
+import javax.annotation.Nullable;
+
+/** Exception to catch cache loading errors.*/
+public class CacheLoadingException extends Exception {
+    
+    /** Generated serial UID.*/
+    private static final long serialVersionUID = -4360477274108849496L;
+
+    /**
+     * Constructor.
+     */
+    public CacheLoadingException() {
+        super();
+    }
+
+    /**
+     * Constructor.
+     * 
+     * @param message exception message
+     */
+    public CacheLoadingException(@Nullable final String message) {
+        super(message);
+    }
+
+    /**
+     * Constructor.
+     * 
+     * @param wrappedException exception to be wrapped by this one
+     */
+    public CacheLoadingException(@Nullable final Exception wrappedException) {
+        super(wrappedException);
+    }
+
+    /**
+     * Constructor.
+     * 
+     * @param message exception message
+     * @param wrappedException exception to be wrapped by this one
+     */
+    public CacheLoadingException(@Nullable final String message, @Nullable final Exception wrappedException) {
+        super(message, wrappedException);
+    }
+
+}
diff --git a/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/cache/LoadingStrategy.java b/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/cache/LoadingStrategy.java
index b2037bd..a6afa69 100644
--- a/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/cache/LoadingStrategy.java
+++ b/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/cache/LoadingStrategy.java
@@ -1,11 +1,10 @@
 package net.shibboleth.oidc.metadata.cache;
 
-import java.util.function.Function;
-
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 
 /** A strategy that loads binary information from a configured source.*/
-public interface LoadingStrategy extends Function<CacheLoadingContext, byte[]> {
+public interface LoadingStrategy {
     
     /**
      * Get a friendly name source identifier to use in log statements.
@@ -13,5 +12,20 @@ public interface LoadingStrategy extends Function<CacheLoadingContext, byte[]> {
      * @return the source identifier friendly name.
      */
     @Nonnull String getSourceIdentifier();
+    
+    /**
+     * Load cache data from a source. If the source data has not
+     * changed from the last time it was loaded (as specified in the cache loading context) a
+     * {@literal null} should be returned. If source data can not be loaded for a known
+     * and accepted reason, a {@literal null} should be returned. For any other error in 
+     * loading cache data, the {@link CacheLoadingException} should be thrown.
+     * 
+     * @param context the cache loading context
+     * 
+     * @return the cache information as bytes.
+     * 
+     * @throws CacheLoadingException if there is an error loading the cache.
+     */
+    @Nullable byte[] load(@Nonnull final CacheLoadingContext context) throws CacheLoadingException;
 
 }
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 e145ae5..4c6abee 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
@@ -345,7 +345,7 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
         final List<MetadataType> metadata = lookupIndexedIdentifier(identifier);
        
         if (metadata.isEmpty()) {
-            log.debug("{} Metadata cache does not contain entry with the identifier: {}", 
+            log.debug("{} Metadata cache does not contain an entry for '{}'", 
                     getLogPrefix(), identifier);
             return metadata;
         }
@@ -354,7 +354,7 @@ public abstract class AbstractMetadataCache<IdentifierType, MetadataType>
         while (metadataIter.hasNext()) {
             final MetadataType individualMetadata = metadataIter.next();
             if (!metadataValidPredicate.test(individualMetadata)) {
-                log.warn("{} Metadata cache contained an entry with the identifier: {}, " 
+                log.warn("{} Metadata cache contained an entry with the identifier '{}', " 
                         + " but it was no longer valid", getLogPrefix(), identifier);
                 metadataIter.remove();
             }
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 06baff7..e831c8b 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
@@ -370,7 +370,7 @@ public class BatchMetadataCache<IdentifierType, MetadataType>
             }
             
             // Any exception here is caught
-            final byte[] rawFetchedMetadata = loadingStrategy.apply(createLoadingContext());
+            final byte[] rawFetchedMetadata = loadingStrategy.load(createLoadingContext());
             if (rawFetchedMetadata != null) {
                 if (sourceMetadataValidPredicate.test(rawFetchedMetadata)) {           
                     
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 8292643..64c1668 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
@@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.core.io.Resource;
 
 import net.shibboleth.oidc.metadata.cache.CacheLoadingContext;
+import net.shibboleth.oidc.metadata.cache.CacheLoadingException;
 import net.shibboleth.oidc.metadata.cache.LoadingStrategy;
 import net.shibboleth.oidc.metadata.impl.ResolverHelper;
 import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
@@ -56,7 +57,7 @@ public class DefaultFileLoadingStrategy implements LoadingStrategy {
      *
      * @param metadata the metadata file resource. Can be {@literal null}.
      * 
-     * @throws IOException if the file does not exist.
+     * @throws IOException if the file is not null put does not exist.
      */
     public DefaultFileLoadingStrategy(@Nullable final Resource metadata) throws IOException {
        if (metadata == null) {
@@ -78,7 +79,7 @@ public class DefaultFileLoadingStrategy implements LoadingStrategy {
     }
 
     @Override
-    @Nullable public byte[] apply(@Nonnull final CacheLoadingContext context) {
+    @Nullable public byte[] load(@Nonnull final CacheLoadingContext context) throws CacheLoadingException {
         if (metadataFile == null) {
             return null;
         }
@@ -93,10 +94,8 @@ public class DefaultFileLoadingStrategy implements LoadingStrategy {
             return null;
         } catch (final IOException | ResolverException e) {
             final String errMsg = "Unable to read metadata file " + metadataFile.getAbsolutePath();
-            log.error(errMsg, e);
-            // FIXME we need an exception really.
-            //throw new MetadataCacheException(errMsg, e);
-            return null;
+            log.error(errMsg, e.getMessage());
+            throw new CacheLoadingException(errMsg, e);
         }
     }
 
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/policy/impl/MetadataPolicyViaLocationFetchingStrategy.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/policy/impl/MetadataPolicyViaLocationFetchingStrategy.java
index f15a7b5..50e7e92 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/policy/impl/MetadataPolicyViaLocationFetchingStrategy.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/policy/impl/MetadataPolicyViaLocationFetchingStrategy.java
@@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.core.io.FileSystemResource;
 
 import net.shibboleth.oidc.metadata.cache.CacheLoadingContext;
+import net.shibboleth.oidc.metadata.cache.CacheLoadingException;
 import net.shibboleth.oidc.metadata.cache.LoadingStrategy;
 import net.shibboleth.oidc.metadata.cache.impl.DefaultFileLoadingStrategy;
 import net.shibboleth.oidc.metadata.criterion.ResourceLocationCriterion;
@@ -59,13 +60,13 @@ public class MetadataPolicyViaLocationFetchingStrategy
      * @param client the instance of {@link HttpClient} used to fetch remote metadata policy.
      * @param handler the response handler used to convert the HTTP response to the metadata policy.
      */
-    public MetadataPolicyViaLocationFetchingStrategy(HttpClient client,
-            ResponseHandler<Map<String, MetadataPolicy>> handler) {
+    public MetadataPolicyViaLocationFetchingStrategy(final HttpClient client,
+            final ResponseHandler<Map<String, MetadataPolicy>> handler) {
         super(client, handler);
     }
 
     /** Class logger. */
-    @Nonnull private Logger log = LoggerFactory.getLogger(MetadataPolicyViaLocationFetchingStrategy.class);
+    @Nonnull private final Logger log = LoggerFactory.getLogger(MetadataPolicyViaLocationFetchingStrategy.class);
 
     /** The parsing strategy used for parsing metadata policies. */
     @NonnullAfterInit private Function<byte[], List<Map<String, MetadataPolicy>>> parsingStrategy;
@@ -105,14 +106,19 @@ public class MetadataPolicyViaLocationFetchingStrategy
         final String fileLocation = requestURL.startsWith("file:") ? requestURL.substring(5) : requestURL;
         final CacheLoadingContext context = new CacheLoadingContext(null, null);
         final FileSystemResource resource = new FileSystemResource(fileLocation);
-        final LoadingStrategy loadingStrategy;
+        final byte[] loadedPolicy;
         try {
-            loadingStrategy = new DefaultFileLoadingStrategy(resource);
-        } catch (final IOException e) {
+            final LoadingStrategy loadingStrategy = new DefaultFileLoadingStrategy(resource);
+            loadedPolicy = loadingStrategy.load(context);
+            if (loadedPolicy == null) {
+                log.error("Could not load any entries via loading strategy");
+                return null;
+            }
+        } catch (final IOException | CacheLoadingException e) {
             log.error("Could not load a metadata policy from file {}", fileLocation, e);
             return null;
-        }
-        final List<Map<String, MetadataPolicy>> result = parsingStrategy.apply(loadingStrategy.apply(context));
+        }        
+        final List<Map<String, MetadataPolicy>> result = parsingStrategy.apply(loadedPolicy);
         if (result == null || result.isEmpty()) {
             log.warn("Could not find any entries via parsing strategy");
             return null;
diff --git a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheBuilderTest.java b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheBuilderTest.java
index 349c849..08d327e 100644
--- a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheBuilderTest.java
+++ b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheBuilderTest.java
@@ -57,10 +57,10 @@ public class BatchMetadataCacheBuilderTest {
     
     @Test
     public void testBatchCacheBuilder_Success() throws ComponentInitializationException {
-        var builder = new BatchMetadataCacheBuilder.Builder<Issuer, OIDCProviderMetadata>();
+        final var builder = new BatchMetadataCacheBuilder.Builder<Issuer, OIDCProviderMetadata>();
         
         final BatchMetadataCacheBuilderSpec<Issuer, OIDCProviderMetadata> spec = new BatchMetadataCacheBuilderSpec<>();
-        spec.setIdentifierExtractionStrategy(m -> m.getIssuer());
+        spec.setIdentifierExtractionStrategy(OIDCProviderMetadata::getIssuer);
         spec.setMinRefreshDelay(Duration.ofMinutes(5));
         spec.setMaxRefreshDelay(Duration.ofMinutes(10));
         spec.setSourceMetadataExpiryStrategy(b -> Instant.now().plus(Duration.ofMinutes(5)));
@@ -77,7 +77,7 @@ public class BatchMetadataCacheBuilderTest {
         spec.setLoadingStrategy(new LoadingStrategy() {
             
             @Override
-            public byte[] apply(CacheLoadingContext t) {
+            public byte[] load(final CacheLoadingContext t) {
                 return "test".getBytes();
             }
             
@@ -91,7 +91,7 @@ public class BatchMetadataCacheBuilderTest {
                 return List.of(new OIDCProviderMetadata(new Issuer("http://www.example.org"), 
                         List.of(SubjectType.PUBLIC),
                         new URI("http://example.oidc.op.org")));
-            } catch (URISyntaxException e) {
+            } catch (final URISyntaxException e) {
                 return Collections.emptyList();
             }
         });
diff --git a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheTest.java b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheTest.java
index de06c83..44a57ca 100644
--- a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheTest.java
+++ b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/BatchMetadataCacheTest.java
@@ -76,7 +76,7 @@ public class BatchMetadataCacheTest {
         defaultLoadingStrategy = new LoadingStrategy() {
             
             @Override
-            public byte[] apply(final CacheLoadingContext t) {
+            public byte[] load(final CacheLoadingContext t) {
                 try {
                     return new OIDCProviderMetadata(new Issuer("http://www.example.org"), List.of(SubjectType.PUBLIC),
                             new URI("http://example.oidc.op.org")).toJSONObject().toJSONString().getBytes();
@@ -106,7 +106,7 @@ public class BatchMetadataCacheTest {
         cache.setSourceMetadataExpiryStrategy(b -> Instant.now().plus(Duration.ofMinutes(5)));
         cache.setParsingStrategy(defaultParsingStrategy);
         cache.setLoadingStrategy(defaultLoadingStrategy);
-        cache.setIdentifierExtractionStrategy(m -> m.getIssuer());
+        cache.setIdentifierExtractionStrategy(OIDCProviderMetadata::getIssuer);
         cache.setMinRefreshDelay(Duration.ofMinutes(5));
         cache.setMaxRefreshDelay(Duration.ofMinutes(10));
         cache.setCriteriaToIdentifierStrategy(crit -> {
@@ -145,7 +145,7 @@ public class BatchMetadataCacheTest {
         localCache.setParsingStrategy(defaultParsingStrategy);
         localCache.setLoadingStrategy(defaultLoadingStrategy);
         localCache.setSourceMetadataExpiryStrategy(b -> Instant.now().plus(Duration.ofMinutes(5)));
-        localCache.setIdentifierExtractionStrategy(m -> m.getIssuer());
+        localCache.setIdentifierExtractionStrategy(OIDCProviderMetadata::getIssuer);
         localCache.setMinRefreshDelay(Duration.ofMillis(100));
         localCache.setMaxRefreshDelay(Duration.ofMillis(200));
         localCache.setSourceMetadataValidPredicate(Predicates.alwaysTrue());
@@ -166,16 +166,47 @@ public class BatchMetadataCacheTest {
         Thread.sleep(2000);
     }
     
+    @Test
+    public void testGetWithNullReturnFromLoadingStrategy() throws Exception {        
+        
+        // create a loading strategy that return null bytes. 
+        final var simpleLoadingStrategy = new LoadingStrategy() {
+            
+            @Override
+            public byte[] load(final CacheLoadingContext t) {
+               return null;
+            }
+            
+            @Override
+            public String getSourceIdentifier() {
+                return "Mock loading source";
+            }
+        };
+        
+        // A parsing strategy that does nothing, but should not be needed as null returned from loading strategy
+        final Function<byte[], List<OIDCProviderMetadata>> simpleParsingStrategy = in -> null;
+        
+        cache.setParsingStrategy(simpleParsingStrategy);
+        cache.setLoadingStrategy(simpleLoadingStrategy);      
+        cache.initialize();
+        
+        // nothing will be returned as the loading strategy is always null
+        final List<OIDCProviderMetadata> allMetadata = 
+                cache.get(new CriteriaSet(new IssuerIDCriterion(new Issuer("http://entityid.com"))));
+        assertEquals(allMetadata.size(), 0);
+        
+    }
+    
     @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() {
+        final var simpleLoadingStrategy = new LoadingStrategy() {
             
             @Override
-            public byte[] apply(CacheLoadingContext t) {
+            public byte[] load(final CacheLoadingContext t) {
                return "".getBytes();
             }
             
@@ -186,7 +217,7 @@ public class BatchMetadataCacheTest {
         };
         
         //create a parsing strategy that loads two provider metadatas
-        Function<byte[], List<OIDCProviderMetadata>> simpleParsingStrategy = in -> {
+        final Function<byte[], List<OIDCProviderMetadata>> simpleParsingStrategy = in -> {
             try {
                 return List.of(
                         new OIDCProviderMetadata(new Issuer("http://www.example.one.org"), List.of(SubjectType.PUBLIC),
@@ -206,7 +237,7 @@ public class BatchMetadataCacheTest {
         localCache.setParsingStrategy(simpleParsingStrategy);
         localCache.setLoadingStrategy(simpleLoadingStrategy);
         localCache.setSourceMetadataExpiryStrategy(b -> Instant.now().plus(Duration.ofMinutes(5)));
-        localCache.setIdentifierExtractionStrategy(m -> m.getIssuer());
+        localCache.setIdentifierExtractionStrategy(OIDCProviderMetadata::getIssuer);
         localCache.setMinRefreshDelay(Duration.ofMillis(100));
         localCache.setMaxRefreshDelay(Duration.ofMillis(200));        
         localCache.setCriteriaToIdentifierStrategy(crit -> {
@@ -228,7 +259,7 @@ public class BatchMetadataCacheTest {
         
         // 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 = 
+        final List<OIDCProviderMetadata> allMetadata = 
                 localCache.get(new CriteriaSet(new EntityIdCriterion("http://entityid.com")));
         assertEquals(allMetadata.size(), 2);
 
@@ -242,7 +273,7 @@ public class BatchMetadataCacheTest {
         cache.setLoadingStrategy(new LoadingStrategy() {
             
             @Override
-            public byte[] apply(final CacheLoadingContext t) {
+            public byte[] load(final CacheLoadingContext t) {
                throw new RuntimeException("Could not load metadata");
             }
             
@@ -269,10 +300,10 @@ public class BatchMetadataCacheTest {
         cache.setRefreshDelayFactor(.99f);
         cache.initialize();
         assertTrue(cache.getExecutorService() instanceof ManuallyTriggeredScheduledExecutorService);
-        var manSchedular = (ManuallyTriggeredScheduledExecutorService)cache.getExecutorService();
+        final var manSchedular = (ManuallyTriggeredScheduledExecutorService)cache.getExecutorService();
         assertNotNull(manSchedular.getAllScheduledTasks());
         assertEquals(manSchedular.getAllScheduledTasks().size(),1);
-        long delay = manSchedular.getAllScheduledTasks().get(0).getDelay(TimeUnit.SECONDS);
+        final long delay = manSchedular.getAllScheduledTasks().get(0).getDelay(TimeUnit.SECONDS);
         // Delay should be close to the min of 10 minutes, not of the metadata 1 minute
         if (delay > 590 && delay < 610) {
             // Is close to 10 minutes
@@ -292,10 +323,10 @@ public class BatchMetadataCacheTest {
         cache.setSourceMetadataExpiryStrategy(b -> Instant.now().plus(Duration.ofMinutes(20)));
         cache.initialize();
         assertTrue(cache.getExecutorService() instanceof ManuallyTriggeredScheduledExecutorService);
-        var manSchedular = (ManuallyTriggeredScheduledExecutorService)cache.getExecutorService();
+        final var manSchedular = (ManuallyTriggeredScheduledExecutorService)cache.getExecutorService();
         assertNotNull(manSchedular.getAllScheduledTasks());
         assertEquals(manSchedular.getAllScheduledTasks().size(),1);
-        long delay = manSchedular.getAllScheduledTasks().get(0).getDelay(TimeUnit.SECONDS);
+        final long delay = manSchedular.getAllScheduledTasks().get(0).getDelay(TimeUnit.SECONDS);
         // Delay should be close to the metadata value of 20 minutes, not of min delay
         if (delay > 1100 && delay < 1300) {
             // Is close to 20 minutes
@@ -315,10 +346,10 @@ public class BatchMetadataCacheTest {
         cache.setSourceMetadataExpiryStrategy(b -> Instant.now().minus(Duration.ofMinutes(20)));
         cache.initialize();
         assertTrue(cache.getExecutorService() instanceof ManuallyTriggeredScheduledExecutorService);
-        var manSchedular = (ManuallyTriggeredScheduledExecutorService)cache.getExecutorService();
+        final var manSchedular = (ManuallyTriggeredScheduledExecutorService)cache.getExecutorService();
         assertNotNull(manSchedular.getAllScheduledTasks());
         assertEquals(manSchedular.getAllScheduledTasks().size(),1);
-        long delay = manSchedular.getAllScheduledTasks().get(0).getDelay(TimeUnit.SECONDS);
+        final long delay = manSchedular.getAllScheduledTasks().get(0).getDelay(TimeUnit.SECONDS);
         // Delay should be close to the metadata value of 20 minutes, not of min delay
         if (delay > 590 && delay < 610) {
             // Is close to 10 minutes
@@ -333,7 +364,7 @@ public class BatchMetadataCacheTest {
         cache.initialize();
         // Strategy does not accept entityID criterion, so no identifier returned. Hence
         // no results
-        List<OIDCProviderMetadata> metadata =
+        final List<OIDCProviderMetadata> metadata =
                 cache.get(new CriteriaSet(new EntityIdCriterion("http://entityid.com")));
         assertTrue(metadata.isEmpty() == true);
         
@@ -342,7 +373,7 @@ public class BatchMetadataCacheTest {
     @Test
     public void testGetNotCached_Success() throws MetadataCacheException, ComponentInitializationException {
         cache.initialize();
-        List<OIDCProviderMetadata> metadata =
+        final List<OIDCProviderMetadata> metadata =
                 cache.get(new CriteriaSet(new IssuerIDCriterion(new Issuer("http://www.example.org"))));
         assertTrue(metadata.isEmpty() == false);
 
@@ -353,7 +384,7 @@ public class BatchMetadataCacheTest {
             throws MetadataCacheException, ComponentInitializationException {
         cache.initialize();
         scheduler.triggerScheduledTasks();
-        List<OIDCProviderMetadata> metadata =
+        final List<OIDCProviderMetadata> metadata =
                 cache.get(new CriteriaSet(new IssuerIDCriterion(new Issuer("http://www.example.org"))));
         assertTrue(metadata.isEmpty() == false);
 
@@ -365,12 +396,10 @@ public class BatchMetadataCacheTest {
         cache.initialize();
 
         final ExecutorService service = Executors.newFixedThreadPool(3);
-        Future<?> futureOne = service.submit(() -> {
-            return cache.get(new CriteriaSet(new IssuerIDCriterion(new Issuer("http://www.example.org"))));
-        });
+        final Future<?> futureOne = service.submit(() -> cache.get(new CriteriaSet(new IssuerIDCriterion(new Issuer("http://www.example.org")))));
         scheduler.triggerScheduledTasks();
 
-        List<?> firstMetadata = (List<?>) futureOne.get();
+        final List<?> firstMetadata = (List<?>) futureOne.get();
         assertTrue(firstMetadata.size() == 1);
     }
 
diff --git a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/DefaultFileLoadingStrategyTest.java b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/DefaultFileLoadingStrategyTest.java
index 9cd618b..4c2e080 100644
--- a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/DefaultFileLoadingStrategyTest.java
+++ b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/DefaultFileLoadingStrategyTest.java
@@ -23,11 +23,11 @@ public class DefaultFileLoadingStrategyTest {
     private final static String EXAMPLE_FILE_CONTENT = "test";
     
     @Test
-    public void testFileLoads() throws IOException {
+    public void testFileLoads() throws Exception {
         final Resource resource = 
                 new ClassPathResource("/net/shibboleth/oidc/metadata/impl/file-loading-strategy-test.txt");
         strategy = new DefaultFileLoadingStrategy(resource);
-        final byte[] loaded = strategy.apply(new CacheLoadingContext(null, null));
+        final byte[] loaded = strategy.load(new CacheLoadingContext(null, null));
         assertEquals(loaded, EXAMPLE_FILE_CONTENT.getBytes(StandardCharsets.UTF_8));
     }
     
@@ -39,18 +39,18 @@ public class DefaultFileLoadingStrategyTest {
     }
     
     @Test
-    public void testNullFile_NullResponse() throws IOException {
+    public void testNullFile_NullResponse() throws Exception {
         strategy = new DefaultFileLoadingStrategy(null);
-        final byte[] loaded = strategy.apply(new CacheLoadingContext(null, null));
+        final byte[] loaded = strategy.load(new CacheLoadingContext(null, null));
         assertNull(loaded);
     }
     
     @Test
-    public void testNullResponse_FileNotUpdatedSinceLastLoad() throws IOException {
+    public void testNullResponse_FileNotUpdatedSinceLastLoad() throws Exception {
         final Resource resource = 
                 new ClassPathResource("/net/shibboleth/oidc/metadata/impl/file-loading-strategy-test.txt");
         strategy = new DefaultFileLoadingStrategy(resource);
-        final byte[] loaded = strategy.apply(new CacheLoadingContext(Instant.MAX, Instant.MAX));
+        final byte[] loaded = strategy.load(new CacheLoadingContext(Instant.MAX, Instant.MAX));
         assertNull(loaded);
     }
     
diff --git a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/OIDCMapMetadataResolverTest.java b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/OIDCMapMetadataResolverTest.java
index 1302699..0028534 100644
--- a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/OIDCMapMetadataResolverTest.java
+++ b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/OIDCMapMetadataResolverTest.java
@@ -129,7 +129,7 @@ public class OIDCMapMetadataResolverTest {
         final LoadingStrategy metadataLoadingStrat = new LoadingStrategy() {
             
             @Override
-            public byte[] apply(CacheLoadingContext t) {
+            public byte[] load(final CacheLoadingContext t) {
                 return GOOD_PROVIDER_CONFIGURATION_INFO.getBytes();
             }
             
@@ -201,6 +201,7 @@ public class OIDCMapMetadataResolverTest {
         }
         
         /* Expose the backing store with a public method.*/
+        @Override
         public BatchBackingStore<IdentifierType, MetadataType> getBackingStore(){
             return super.getBackingStore();
         }
diff --git a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/OIDCProviderMetadataResolverTest.java b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/OIDCProviderMetadataResolverTest.java
index d75be90..c29e72f 100644
--- a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/OIDCProviderMetadataResolverTest.java
+++ b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/OIDCProviderMetadataResolverTest.java
@@ -179,7 +179,7 @@ public class OIDCProviderMetadataResolverTest {
         final LoadingStrategy metadataLoadingStrat = new LoadingStrategy() {
             
             @Override
-            public byte[] apply(CacheLoadingContext t) {
+            public byte[] load(final CacheLoadingContext t) {
                 return GOOD_PROVIDER_CONFIGURATION_INFO.getBytes();
             }
             
@@ -198,14 +198,14 @@ public class OIDCProviderMetadataResolverTest {
                     }
                 };
         
-        ManuallyTriggeredScheduledExecutorService scheduler = new ManuallyTriggeredScheduledExecutorService();
+        final ManuallyTriggeredScheduledExecutorService scheduler = new ManuallyTriggeredScheduledExecutorService();
         batchCache = new TestableBatchMetadataCache<Issuer, OIDCProviderMetadata>(new DefaultBatchBackingStore<>(), 
                 scheduler);
         
         batchCache.setParsingStrategy(parsingStrat);
         batchCache.setLoadingStrategy(metadataLoadingStrat);
         batchCache.setId("MockBatchCache");
-        batchCache.setIdentifierExtractionStrategy(m -> m.getIssuer());
+        batchCache.setIdentifierExtractionStrategy(OIDCProviderMetadata::getIssuer);
         batchCache.setCriteriaToIdentifierStrategy(crit -> {
             final IssuerIDCriterion issuerId = crit.get(IssuerIDCriterion.class);
             if (issuerId != null) {
@@ -243,11 +243,11 @@ public class OIDCProviderMetadataResolverTest {
         fetchingStrategy.initialize();
         
         // Give our own executor, so we can manually handle the cleanup task
-        ManuallyTriggeredScheduledExecutorService scheduler = new ManuallyTriggeredScheduledExecutorService();
+        final ManuallyTriggeredScheduledExecutorService scheduler = new ManuallyTriggeredScheduledExecutorService();
         dynCache = new TestableDynamicMetadataCache<Issuer, OIDCProviderMetadata>
                         (new DefaultDynamicBackingStore<>(), scheduler);
         dynCache.setFetchStrategy(fetchingStrategy);
-        dynCache.setIdentifierExtractionStrategy(m -> m.getIssuer());
+        dynCache.setIdentifierExtractionStrategy(OIDCProviderMetadata::getIssuer);
         dynCache.setMetadataExpirationTimeStrategy(ctx -> ctx.getNow().plus(Duration.ofMinutes(5)));
         dynCache.setCriteriaToIdentifierStrategy(crit -> {
             final IssuerIDCriterion issuerId = crit.get(IssuerIDCriterion.class);
@@ -283,7 +283,7 @@ public class OIDCProviderMetadataResolverTest {
     void testBatchResolve() throws Exception {
         batchCache.initialize();
         
-        Iterable<OIDCProviderMetadata> found = 
+        final Iterable<OIDCProviderMetadata> found = 
                 batchResolver.resolve(new CriteriaSet(new IssuerIDCriterion(new Issuer("https://example.oidc.op.org"))));
         assertNotNull(found);
         assertTrue(found.iterator().hasNext());
@@ -370,7 +370,7 @@ public class OIDCProviderMetadataResolverTest {
     void testDynResolve() throws ResolverException, IOException, ComponentInitializationException {
         dynCache.initialize();
         
-        Iterable<OIDCProviderMetadata> found = 
+        final Iterable<OIDCProviderMetadata> found = 
                 dynResolver.resolve(new CriteriaSet(new IssuerIDCriterion(new Issuer("https://example.oidc.op.org"))));
         assertNotNull(found);
         assertTrue(found.iterator().hasNext());
@@ -380,7 +380,7 @@ public class OIDCProviderMetadataResolverTest {
     void testDynResolve_Filter() throws ResolverException, IOException, ComponentInitializationException {
         dynCache.initialize();
         
-        Iterable<OIDCProviderMetadata> found = 
+        final Iterable<OIDCProviderMetadata> found = 
                 dynResolver.resolve(new CriteriaSet(
                         new IssuerIDCriterion(new Issuer("https://example.oidc.op.org")),
                         new AlwaysFilterEvaluableMetadataCriterion(OIDCProviderMetadata.class, true)));
@@ -420,11 +420,11 @@ public class OIDCProviderMetadataResolverTest {
         mgmtData.setRefreshTriggerTime(now.minus(Duration.ofMinutes(1)));
         
         //create some metadata to add - probably ignored as needs refereshing
-        OIDCProviderMetadata metadata = OIDCProviderMetadata.parse(GOOD_PROVIDER_CONFIGURATION_INFO);
+        final OIDCProviderMetadata metadata = OIDCProviderMetadata.parse(GOOD_PROVIDER_CONFIGURATION_INFO);
         dynCache.getBackingStore().getOrderedValues().add(metadata);
         dynCache.getBackingStore().getIndexedValues().put(iss, List.of(metadata));
         
-        Iterable<OIDCProviderMetadata> found = 
+        final Iterable<OIDCProviderMetadata> found = 
                 dynResolver.resolve(new CriteriaSet(
                         new IssuerIDCriterion(iss)));
         assertNotNull(found);
@@ -436,7 +436,7 @@ public class OIDCProviderMetadataResolverTest {
             throws ResolverException, IOException, ComponentInitializationException {
         dynCache.initialize();
         
-        Iterable<OIDCProviderMetadata> found = 
+        final Iterable<OIDCProviderMetadata> found = 
                 dynResolver.resolve(new CriteriaSet(
                         new IssuerIDCriterion(new Issuer("https://example.oidc.op.org")),
                         new WrongTypeEvaluableMetadataCriterion(EntityDescriptor.class, true)));
@@ -466,7 +466,7 @@ public class OIDCProviderMetadataResolverTest {
             throws ResolverException, IOException, ComponentInitializationException {
         dynCache.initialize();
         
-        Iterable<OIDCProviderMetadata> found = 
+        final Iterable<OIDCProviderMetadata> found = 
                 dynResolver.resolve(new CriteriaSet(
                         new IssuerIDCriterion(new Issuer("https://example.oidc.op.org")),
                         new WrongTypeOfCriterion()));
@@ -519,7 +519,7 @@ public class OIDCProviderMetadataResolverTest {
                 .containsKey(new Issuer("https://example.oidc.op.org")));
         
         // find and cache
-        Iterable<OIDCProviderMetadata> found = 
+        final Iterable<OIDCProviderMetadata> found = 
                 dynResolver.resolve(new CriteriaSet(new IssuerIDCriterion(new Issuer("https://example.oidc.op.org"))));
         assertNotNull(found);
         assertTrue(found.iterator().hasNext());        
@@ -534,7 +534,7 @@ public class OIDCProviderMetadataResolverTest {
                 execute(any(HttpUriRequest.class),any(ResponseHandler.class),any(HttpContext.class)))
                 .thenReturn(null);
         
-        Iterable<OIDCProviderMetadata> foundFromCache = 
+        final Iterable<OIDCProviderMetadata> foundFromCache = 
                 dynResolver.resolve(new CriteriaSet(new IssuerIDCriterion(new Issuer("https://example.oidc.op.org"))));
         assertNotNull(foundFromCache);
         assertTrue(foundFromCache.iterator().hasNext());
@@ -547,7 +547,7 @@ public class OIDCProviderMetadataResolverTest {
         when(httpClient.
                 execute(any(HttpUriRequest.class),any(ResponseHandler.class),any(HttpContext.class)))
                 .thenReturn(null);
-        Iterable<OIDCProviderMetadata> found = 
+        final Iterable<OIDCProviderMetadata> found = 
                 dynResolver.resolve(new CriteriaSet(new IssuerIDCriterion(new Issuer("https://example.oidc.op.org"))));
         assertNotNull(found);
         assertFalse(found.iterator().hasNext());
@@ -563,6 +563,7 @@ public class OIDCProviderMetadataResolverTest {
         }
         
         /* Expose the backing store with a public method.*/
+        @Override
         public DynamicBackingStore<IdentifierType, MetadataType> getBackingStore(){
             return super.getBackingStore();
         }
@@ -579,6 +580,7 @@ public class OIDCProviderMetadataResolverTest {
         }
         
         /* Expose the backing store with a public method.*/
+        @Override
         public BatchBackingStore<IdentifierType, MetadataType> getBackingStore(){
             return super.getBackingStore();
         }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list