[java-oidc-common] branch main updated: Fix general evaluable metadata criterion

Phil Smart philip.smart at jisc.ac.uk
Fri Nov 12 17:48:43 UTC 2021


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

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

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

The following commit(s) were added to refs/heads/main by this push:
     new 45c385c  Fix general evaluable metadata criterion
45c385c is described below

commit 45c385ce067a820b28abc7dad307e987b557aa8b
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Fri Nov 12 17:48:37 2021 +0000

    Fix general evaluable metadata criterion
    
    Make evaluable metadata criterion all types of abstract metadata
    criterion - which is an abstract class and not an interface.
---
 .../AbstractEvaluableMetadataCriterion.java        |  5 +-
 .../oidc/metadata/EvaluableMetadataCriterion.java  | 34 ------------
 .../impl/AbstractOIDCMetadataResolver.java         |  6 +--
 .../impl/OIDCProviderMetadataResolverTest.java     | 63 ++++++++++++++--------
 4 files changed, 48 insertions(+), 60 deletions(-)

diff --git a/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/AbstractEvaluableMetadataCriterion.java b/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/AbstractEvaluableMetadataCriterion.java
index f7c071f..632bbdd 100644
--- a/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/AbstractEvaluableMetadataCriterion.java
+++ b/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/AbstractEvaluableMetadataCriterion.java
@@ -1,8 +1,11 @@
 package net.shibboleth.oidc.metadata;
 
+import java.util.function.Predicate;
+
 import javax.annotation.Nonnull;
 
 import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.resolver.Criterion;
 
 /**
  * Base class for all metadata criterion classes. If the correct object type this criterion accepts is not provided, 
@@ -10,7 +13,7 @@ import net.shibboleth.utilities.java.support.logic.Constraint;
  *
  * @param <T> The metadata type this criterion accepts.
  */
-public abstract class AbstractEvaluableMetadataCriterion<T> implements EvaluableMetadataCriterion<T> {
+public abstract class AbstractEvaluableMetadataCriterion<T> implements Predicate<T>, Criterion {
     
     /** Object type. */
     @Nonnull private final Class<T> objectType;
diff --git a/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/EvaluableMetadataCriterion.java b/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/EvaluableMetadataCriterion.java
deleted file mode 100644
index 2a0b963..0000000
--- a/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/EvaluableMetadataCriterion.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the University Corporation for Advanced Internet Development,
- * Inc. (UCAID) under one or more contributor license agreements.  See the
- * NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The UCAID licenses this file to You under the Apache
- * License, Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package net.shibboleth.oidc.metadata;
-
-import java.util.function.Predicate;
-
-import net.shibboleth.utilities.java.support.resolver.Criterion;
-
-/**
- * Marker interface for evaluable metadata criteria. 
- *
- * @param <T> The metadata type this criterion applies to. 
- */
-public interface EvaluableMetadataCriterion<T> extends Predicate<T>, Criterion {    
-    
-}
-
-
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 3c6c1f9..7607029 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
@@ -32,7 +32,7 @@ import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.Iterables;
 
-import net.shibboleth.oidc.metadata.EvaluableMetadataCriterion;
+import net.shibboleth.oidc.metadata.AbstractEvaluableMetadataCriterion;
 import net.shibboleth.oidc.metadata.OIDCMetadataResolver;
 import net.shibboleth.oidc.metadata.cache.MetadataCache;
 import net.shibboleth.oidc.metadata.cache.MetadataCacheException;
@@ -162,9 +162,9 @@ public abstract class AbstractOIDCMetadataResolver<MetadataIdentifier, MetadataT
         
         log.debug("{} Attempting to filter candidate metadata via resolved Predicates", getLogPrefix());
         
-        // TODO: The criterion should be a subtype of AbstractEvaluableMetadataCriterion to avoid errors.
+        // The criterion has to be a subtype of AbstractEvaluableMetadataCriterion to avoid errors.
         @SuppressWarnings("unchecked") final Set<Predicate<MetadataType>> predicates = 
-                ResolverSupport.getPredicates(criteria, EvaluableMetadataCriterion.class, 
+                ResolverSupport.getPredicates(criteria, AbstractEvaluableMetadataCriterion.class, 
                         getCriterionPredicateRegistry());
         
         log.trace("{} Resolved {} Predicates: {}", getLogPrefix(), predicates.size(), predicates);
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 a0785ab..91b957c 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
@@ -69,6 +69,7 @@ import net.shibboleth.oidc.metadata.criterion.IssuerIDCriterion;
 import net.shibboleth.oidc.metadata.impl.HTTPProviderConfigurationFetchingStrategy.OIDCProviderMetadataResponseHandler;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
+import net.shibboleth.utilities.java.support.resolver.Criterion;
 import net.shibboleth.utilities.java.support.resolver.ResolverException;
 
 /** Tests for the {@link OIDCProviderMetadataResolver} .*/
@@ -275,7 +276,7 @@ public class OIDCProviderMetadataResolverTest {
     }
     
     @Test
-    void testBatchResolve_Success() throws ResolverException, IOException {
+    void testBatchResolve() throws ResolverException, IOException {
         Iterable<OIDCProviderMetadata> found = 
                 batchResolver.resolve(new CriteriaSet(new IssuerIDCriterion(new Issuer("https://example.oidc.op.org"))));
         assertNotNull(found);
@@ -285,7 +286,7 @@ public class OIDCProviderMetadataResolverTest {
     
     
     @Test
-    void testDynResolve_Success() throws ResolverException, IOException {
+    void testDynResolve() throws ResolverException, IOException {
         Iterable<OIDCProviderMetadata> found = 
                 dynResolver.resolve(new CriteriaSet(new IssuerIDCriterion(new Issuer("https://example.oidc.op.org"))));
         assertNotNull(found);
@@ -293,7 +294,7 @@ public class OIDCProviderMetadataResolverTest {
     }
     
     @Test
-    void testDynResolve_Filter_Success() throws ResolverException, IOException {
+    void testDynResolve_Filter() throws ResolverException, IOException {
         Iterable<OIDCProviderMetadata> found = 
                 dynResolver.resolve(new CriteriaSet(
                         new IssuerIDCriterion(new Issuer("https://example.oidc.op.org")),
@@ -303,8 +304,23 @@ public class OIDCProviderMetadataResolverTest {
         assertTrue(found.iterator().hasNext() == false);
     }
     
+    /* Supports OIDCProviderMetadata, so will filter it.*/
+    class AlwaysFilterEvaluableMetadataCriterion extends AbstractEvaluableMetadataCriterion<OIDCProviderMetadata> {
+
+        protected AlwaysFilterEvaluableMetadataCriterion(final Class<OIDCProviderMetadata> claz,
+                final boolean defaultResult) {
+            super(claz, defaultResult);            
+        }
+
+        @Override
+        public boolean doTest(final OIDCProviderMetadata metadata) {
+            return false;
+        }
+        
+    }
+    
     @Test
-    void testDynResolve_MetadataNeedsRefresh_Success() throws ResolverException, IOException, ParseException {
+    void testDynResolve_MetadataNeedsRefresh() throws ResolverException, IOException, ParseException {
         
         final Issuer iss = new Issuer("https://example.oidc.op.org");
         final MetadataManagementData<Issuer> mgmtData = dynCache.getBackingStore()
@@ -329,7 +345,7 @@ public class OIDCProviderMetadataResolverTest {
     }
     
     @Test
-    void testDynResolve_Filter_WrongType_Fail() throws ResolverException, IOException {
+    void testDynResolve_Filter_WrongMetadataType() throws ResolverException, IOException {
         Iterable<OIDCProviderMetadata> found = 
                 dynResolver.resolve(new CriteriaSet(
                         new IssuerIDCriterion(new Issuer("https://example.oidc.op.org")),
@@ -339,21 +355,6 @@ public class OIDCProviderMetadataResolverTest {
         assertTrue(found.iterator().hasNext());
     }
     
-    /* Supports OIDCProviderMetadata, so will filter it.*/
-    class AlwaysFilterEvaluableMetadataCriterion extends AbstractEvaluableMetadataCriterion<OIDCProviderMetadata> {
-
-        protected AlwaysFilterEvaluableMetadataCriterion(final Class<OIDCProviderMetadata> claz,
-                final boolean defaultResult) {
-            super(claz, defaultResult);            
-        }
-
-        @Override
-        public boolean doTest(final OIDCProviderMetadata metadata) {
-            return false;
-        }
-        
-    }
-    
     /* Does not support OIDCProviderMetadata, should just return the default.*/
     class WrongTypeEvaluableMetadataCriterion extends AbstractEvaluableMetadataCriterion<EntityDescriptor> {
 
@@ -368,9 +369,27 @@ public class OIDCProviderMetadataResolverTest {
         }
         
     }
+
+    
+    @Test
+    void testDynResolve_Filter_WrongClassType() throws ResolverException, IOException {
+        Iterable<OIDCProviderMetadata> found = 
+                dynResolver.resolve(new CriteriaSet(
+                        new IssuerIDCriterion(new Issuer("https://example.oidc.op.org")),
+                        new WrongTypeOfCriterion()));
+        assertNotNull(found);
+        //was filtered
+        assertTrue(found.iterator().hasNext());
+    }
+
+    /* This should be a type of AbstractEvaluableMetadataCriterion, and so should be ignored.*/
+    class WrongTypeOfCriterion implements Criterion {       
+        
+    }
+    
     
     @Test
-    void testResponseHandler_Success() throws IOException {
+    void testResponseHandler() throws IOException {
         final OIDCProviderMetadataResponseHandler handler = new OIDCProviderMetadataResponseHandler();
         final BasicHttpResponse httpResponse = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_OK, "OK");
         final ByteArrayEntity entity = new ByteArrayEntity(GOOD_PROVIDER_CONFIGURATION_INFO.getBytes());
@@ -397,7 +416,7 @@ public class OIDCProviderMetadataResolverTest {
     /* Run it twice, so the second is resolved from cache.*/
     @SuppressWarnings("unchecked")
     @Test
-    void testResolve_FromCache_Success() throws ResolverException, IOException {
+    void testResolve_FromCache() throws ResolverException, IOException {
         
         // test not in cache
         assertFalse(dynCache.getBackingStore().getIndexedValues().containsKey(new Issuer("https://example.oidc.op.org")));

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


More information about the commits mailing list