[java-identity-provider] branch master updated: Reapply IDP-1235 change without logback update.

Scott Cantor cantor.2 at osu.edu
Wed Sep 25 10:05:24 EDT 2019


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

scantor pushed a commit to branch master
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=6d27772dbba4407c7328cf0d704e1dce89cf4491

The following commit(s) were added to refs/heads/master by this push:
       new  6d27772   Reapply IDP-1235 change without logback update.
6d27772 is described below

commit 6d27772dbba4407c7328cf0d704e1dce89cf4491
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Sep 25 10:05:22 2019 -0400

    Reapply IDP-1235 change without logback update.
---
 .../resolver/AbstractAttributeDefinition.java      | 18 ++++++++++++++++++
 .../attribute/resolver/AttributeDefinition.java    |  6 ++++++
 .../resolver/AbstractAttributeDefinitionTest.java  | 13 ++++++++-----
 .../resolver/impl/AttributeResolverImpl.java       | 22 +++++-----------------
 .../resolver/impl/AttributeResolverImplTest.java   |  6 ++++--
 5 files changed, 41 insertions(+), 24 deletions(-)

diff --git a/idp-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/AbstractAttributeDefinition.java b/idp-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/AbstractAttributeDefinition.java
index 38d707c..741dc09 100644
--- a/idp-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/AbstractAttributeDefinition.java
+++ b/idp-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/AbstractAttributeDefinition.java
@@ -46,6 +46,9 @@ public abstract class AbstractAttributeDefinition extends AbstractResolverPlugin
     /** Whether this attribute definition is only a dependency and thus its values should never be released. */
     private boolean dependencyOnly;
 
+    /** Whether this attribute definition is to be pre-resolved. */
+    private boolean preRequested;
+
     /** cache for the log prefix - to save multiple recalculations. */
     @Nullable private String logPrefix;
 
@@ -75,6 +78,21 @@ public abstract class AbstractAttributeDefinition extends AbstractResolverPlugin
 
     /** {@inheritDoc} */
     @Override
+    public boolean isPreRequested() {
+        return preRequested;
+    }
+
+    /** Sets whether this definition (and its dependencies) are to be pre-resolved.
+     * @param value what to set
+     */
+    public void setPreRequested(final boolean value) {
+        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
+        preRequested = value;
+    }
+
+    /** {@inheritDoc} */
+    @Override
     protected void doInitialize() throws ComponentInitializationException {
 
         // Set up the dependencies first. Then the initialize in the parent
diff --git a/idp-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/AttributeDefinition.java b/idp-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/AttributeDefinition.java
index f49e296..c2d1228 100644
--- a/idp-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/AttributeDefinition.java
+++ b/idp-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/AttributeDefinition.java
@@ -33,4 +33,10 @@ public interface AttributeDefinition extends ResolverPlugin<IdPAttribute> {
      */
     boolean isDependencyOnly();
 
+    /**
+     * Gets whether this attribute definition has to be resolved prior in a first pass (in order to prime
+     * contexts which can be used in the "main pass").
+     * @return true if this is a definition to be done "first"
+     */
+    boolean isPreRequested();
 }
\ No newline at end of file
diff --git a/idp-attribute-resolver-api/src/test/java/net/shibboleth/idp/attribute/resolver/AbstractAttributeDefinitionTest.java b/idp-attribute-resolver-api/src/test/java/net/shibboleth/idp/attribute/resolver/AbstractAttributeDefinitionTest.java
index ecf5796..5323348 100644
--- a/idp-attribute-resolver-api/src/test/java/net/shibboleth/idp/attribute/resolver/AbstractAttributeDefinitionTest.java
+++ b/idp-attribute-resolver-api/src/test/java/net/shibboleth/idp/attribute/resolver/AbstractAttributeDefinitionTest.java
@@ -44,25 +44,28 @@ public class AbstractAttributeDefinitionTest {
 
         Assert.assertEquals(definition.getId(), "foo");
         Assert.assertFalse(definition.isDependencyOnly());
+        Assert.assertFalse(definition.isPreRequested());
     }
 
     /** Tests setting and retrieving the dependency only option. */
     @Test
-    public void dependencyOnly() {
+    public void booleanTests() {
         MockAttributeDefinition definition = new MockAttributeDefinition("foo", null);
         Assert.assertFalse(definition.isDependencyOnly());
 
+        Assert.assertFalse(definition.isDependencyOnly());
         definition.setDependencyOnly(true);
         Assert.assertTrue(definition.isDependencyOnly());
 
-        definition.setDependencyOnly(true);
-        Assert.assertTrue(definition.isDependencyOnly());
+        Assert.assertFalse(definition.isPreRequested());
+        definition.setPreRequested(true);
+        Assert.assertTrue(definition.isPreRequested());
 
         definition.setDependencyOnly(false);
         Assert.assertFalse(definition.isDependencyOnly());
 
-        definition.setDependencyOnly(false);
-        Assert.assertFalse(definition.isDependencyOnly());
+        definition.setPreRequested(false);
+        Assert.assertFalse(definition.isPreRequested());
     }
 
     /** Test resolve an attribute. */
diff --git a/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverImpl.java b/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverImpl.java
index e96eb9e..6e02ddd 100644
--- a/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverImpl.java
+++ b/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverImpl.java
@@ -29,6 +29,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.function.Function;
+import java.util.stream.Collectors;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -132,13 +133,6 @@ public class AttributeResolverImpl extends AbstractServiceableComponent<Attribut
         attributeDefinitions = ImmutableMap.copyOf(checkedDefinitions);
     }
 
-    /** Sets the Attributes to be resolved "first" for this resolver.
-     * @param attrs what to set.
-     */
-    public void setPreRequestedAttributes(final List<String> attrs) {
-        preRequestedAttributes = Collections.unmodifiableList(attrs);
-    }
-
     /**
      * Gets the collection of attribute definitions for this resolver.
      * 
@@ -661,16 +655,10 @@ public class AttributeResolverImpl extends AbstractServiceableComponent<Attribut
             throw new ComponentInitializationException("No Data Connectors provided");
         }
 
-        if (null == preRequestedAttributes) {
-            preRequestedAttributes = Collections.emptyList();
-        } else {
-            for (final String requested : preRequestedAttributes) {
-                if (!attributeDefinitions.containsKey(requested)) {
-                    throw new ComponentInitializationException("Definition for prerequested attribute '"
-                            + requested + "' not present");
-                }
-            }
-        }
+        preRequestedAttributes = attributeDefinitions.entrySet().stream().
+                filter(e -> e.getValue().isPreRequested()).
+                map(Entry::getKey).
+                collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));
 
         final HashSet<String> dependencyVerifiedPlugins = new HashSet<>();
         for (final DataConnector plugin : dataConnectors.values()) {
diff --git a/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverImplTest.java b/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverImplTest.java
index 5b095a9..40a77dd 100644
--- a/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverImplTest.java
+++ b/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverImplTest.java
@@ -253,14 +253,16 @@ public class AttributeResolverImplTest {
         attribute2.setValues(Collections.singletonList(new StringAttributeValue("value2")));
 
         final LazySet<AttributeDefinition> definitions = new LazySet<>();
-        definitions.add(new MockAttributeDefinition("ad1", attribute));
+        final AbstractAttributeDefinition ad1 = new MockAttributeDefinition("ad1", attribute);
+        ad1.setPreRequested(true);
+        definitions.add(ad1);
         definitions.add(new PreDefinedCheckingMockAttributeDefinition("ad2", attribute2, "ad1"));
+
         for (AttributeDefinition defn:definitions) {
             defn.initialize();
         }
 
         final AttributeResolverImpl resolver = newAttributeResolverImpl("foo", definitions, null);
-        resolver.setPreRequestedAttributes(List.of("ad1"));
         resolver.initialize();
 
         AttributeResolutionContext context = new AttributeResolutionContext();

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


More information about the commits mailing list