[java-identity-provider] branch main updated: Replace inline hash function with delegation to flow descriptor.

Scott Cantor cantor.2 at osu.edu
Fri Jan 15 00:11:08 UTC 2021


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

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

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

The following commit(s) were added to refs/heads/main by this push:
       new  8b09cbb89 Replace inline hash function with delegation to flow descriptor.
8b09cbb89 is described below

commit 8b09cbb89da18e93ba5a03f65fa8715f985f0fbb
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Jan 14 19:11:05 2021 -0500

    Replace inline hash function with delegation to flow descriptor.
---
 .../impl/AttributeReleaseConsentFunction.java      | 29 ++++++++--------------
 .../impl/AttributeReleaseConsentFunctionTest.java  | 25 +++++++++----------
 2 files changed, 22 insertions(+), 32 deletions(-)

diff --git a/idp-consent-impl/src/main/java/net/shibboleth/idp/consent/logic/impl/AttributeReleaseConsentFunction.java b/idp-consent-impl/src/main/java/net/shibboleth/idp/consent/logic/impl/AttributeReleaseConsentFunction.java
index f91b3ee51..b33974b59 100644
--- a/idp-consent-impl/src/main/java/net/shibboleth/idp/consent/logic/impl/AttributeReleaseConsentFunction.java
+++ b/idp-consent-impl/src/main/java/net/shibboleth/idp/consent/logic/impl/AttributeReleaseConsentFunction.java
@@ -18,7 +18,6 @@
 package net.shibboleth.idp.consent.logic.impl;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -34,6 +33,7 @@ import net.shibboleth.idp.attribute.IdPAttributeValue;
 import net.shibboleth.idp.consent.Consent;
 import net.shibboleth.idp.consent.context.AttributeReleaseContext;
 import net.shibboleth.idp.consent.context.ConsentContext;
+import net.shibboleth.idp.consent.flow.ar.impl.AttributeReleaseFlowDescriptor;
 import net.shibboleth.idp.consent.flow.impl.ConsentFlowDescriptor;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 
@@ -57,15 +57,11 @@ public class AttributeReleaseConsentFunction implements Function<ProfileRequestC
     /** Strategy used to find the {@link AttributeReleaseContext} from the {@link ProfileRequestContext}. */
     @Nonnull private Function<ProfileRequestContext,AttributeReleaseContext> attributeReleaseContextLookupStrategy;
 
-    /** Function used to compute the hash of an attribute's values. */
-    @Nonnull private Function<Collection<IdPAttributeValue>, String> attributeValuesHashFunction;
-
     /** Constructor. */
     public AttributeReleaseConsentFunction() {
         consentContextLookupStrategy = new ChildContextLookup<>(ConsentContext.class);
         consentFlowDescriptorLookupStrategy = new FlowDescriptorLookupFunction<>(ConsentFlowDescriptor.class);
         attributeReleaseContextLookupStrategy = new ChildContextLookup<>(AttributeReleaseContext.class);
-        attributeValuesHashFunction = new AttributeValuesHashFunction();
     }
 
     /**
@@ -100,16 +96,6 @@ public class AttributeReleaseConsentFunction implements Function<ProfileRequestC
                 Constraint.isNotNull(strategy, "Attribute release context lookup strategy cannot be null");
     }
 
-    /**
-     * Set the function used to compute the hash of an attribute's values.
-     * 
-     * @param function the function used to compute the hash of an attribute's values
-     */
-    public void setAttributeValuesHashFunction(
-            @Nonnull final Function<Collection<IdPAttributeValue>, String> function) {
-        attributeValuesHashFunction = Constraint.isNotNull(function, "Hash function cannot be null");
-    }
-
     /** {@inheritDoc} */
     /// CheckStyle: CyclomaticComplexity OFF
     @Override @Nullable public Map<String, Consent> apply(@Nullable final ProfileRequestContext input) {
@@ -118,7 +104,7 @@ public class AttributeReleaseConsentFunction implements Function<ProfileRequestC
         }
 
         final ConsentFlowDescriptor consentFlowDescriptor = consentFlowDescriptorLookupStrategy.apply(input);
-        if (consentFlowDescriptor == null) {
+        if (consentFlowDescriptor == null || !(consentFlowDescriptor instanceof AttributeReleaseFlowDescriptor)) {
             return null;
         }
 
@@ -142,10 +128,14 @@ public class AttributeReleaseConsentFunction implements Function<ProfileRequestC
             consent.setId(attribute.getId());
 
             if (consentFlowDescriptor.compareValues()) {
-                unsortedConsent.setValue(attributeValuesHashFunction.apply(attribute.getValues()));
+                unsortedConsent.setValue(
+                        ((AttributeReleaseFlowDescriptor) consentFlowDescriptor).getAttributeValuesHashFunction().apply(
+                                attribute.getValues()));
                 final List<IdPAttributeValue> sorted = new ArrayList<>(attribute.getValues());
                 Collections.sort(sorted);
-                consent.setValue(attributeValuesHashFunction.apply(sorted));
+                consent.setValue(
+                        ((AttributeReleaseFlowDescriptor) consentFlowDescriptor).getAttributeValuesHashFunction().apply(
+                                sorted));
             }
 
             // Remember previous choice.
@@ -168,4 +158,5 @@ public class AttributeReleaseConsentFunction implements Function<ProfileRequestC
         return currentConsents;
     }
     // CheckStyle: CyclomaticComplexity ON
-}
+
+}
\ No newline at end of file
diff --git a/idp-consent-impl/src/test/java/net/shibboleth/idp/consent/logic/impl/AttributeReleaseConsentFunctionTest.java b/idp-consent-impl/src/test/java/net/shibboleth/idp/consent/logic/impl/AttributeReleaseConsentFunctionTest.java
index 912df7dde..f7589ace2 100644
--- a/idp-consent-impl/src/test/java/net/shibboleth/idp/consent/logic/impl/AttributeReleaseConsentFunctionTest.java
+++ b/idp-consent-impl/src/test/java/net/shibboleth/idp/consent/logic/impl/AttributeReleaseConsentFunctionTest.java
@@ -26,6 +26,7 @@ import net.shibboleth.idp.attribute.IdPAttribute;
 import net.shibboleth.idp.consent.Consent;
 import net.shibboleth.idp.consent.context.AttributeReleaseContext;
 import net.shibboleth.idp.consent.context.ConsentContext;
+import net.shibboleth.idp.consent.flow.ar.impl.AttributeReleaseFlowDescriptor;
 import net.shibboleth.idp.consent.flow.impl.ConsentFlowDescriptor;
 import net.shibboleth.idp.consent.impl.ConsentTestingSupport;
 import net.shibboleth.idp.consent.impl.ConsentTestingSupport.MapType;
@@ -47,16 +48,14 @@ public class AttributeReleaseConsentFunctionTest {
 
     private ProfileRequestContext prc;
 
-    private AttributeValuesHashFunction attributeValuesHashFunction;
-
+    private AttributeReleaseFlowDescriptor flowDescriptor;
+    
     private AttributeReleaseConsentFunction function;
 
     @BeforeMethod public void setUp() throws Exception {
         src = new RequestContextBuilder().buildRequestContext();
         prc = new WebflowRequestContextProfileRequestContextLookup().apply(src);
 
-        attributeValuesHashFunction = new AttributeValuesHashFunction();
-
         function = new AttributeReleaseConsentFunction();
     }
 
@@ -66,12 +65,12 @@ public class AttributeReleaseConsentFunctionTest {
      * @param compareValues whether consent equality includes comparing consent values
      */
     private void setUpDescriptor(final boolean compareValues) {
-        final ConsentFlowDescriptor descriptor = new ConsentFlowDescriptor();
-        descriptor.setId("test");
-        descriptor.setCompareValues(compareValues);
+        flowDescriptor = new AttributeReleaseFlowDescriptor();
+        flowDescriptor.setId("test");
+        flowDescriptor.setCompareValues(compareValues);
 
         final ProfileInterceptorContext pic = new ProfileInterceptorContext();
-        pic.setAttemptedFlow(descriptor);
+        pic.setAttemptedFlow(flowDescriptor);
         prc.addSubcontext(pic);
 
         Assert.assertNotNull(prc.getSubcontext(ProfileInterceptorContext.class));
@@ -150,7 +149,7 @@ public class AttributeReleaseConsentFunctionTest {
         for (final IdPAttribute attr : ConsentTestingSupport.newAttributeMap().values()) {
             final Consent consent = new Consent();
             consent.setId(attr.getId());
-            consent.setValue(attributeValuesHashFunction.apply(attr.getValues()));
+            consent.setValue(flowDescriptor.getAttributeValuesHashFunction().apply(attr.getValues()));
             expected.put(consent.getId(), consent);
         }
 
@@ -188,7 +187,7 @@ public class AttributeReleaseConsentFunctionTest {
     @Test public void testRememberPreviousConsentsCompareValues() {
         final Consent previousConsent = new Consent();
         previousConsent.setId("attribute1");
-        previousConsent.setValue(attributeValuesHashFunction.apply(ConsentTestingSupport.newAttributeMap()
+        previousConsent.setValue(flowDescriptor.getAttributeValuesHashFunction().apply(ConsentTestingSupport.newAttributeMap()
                 .get("attribute1").getValues()));
         previousConsent.setApproved(true);
         final ConsentContext consentCtx = new ConsentContext();
@@ -206,7 +205,7 @@ public class AttributeReleaseConsentFunctionTest {
         for (final IdPAttribute attr : ConsentTestingSupport.newAttributeMap().values()) {
             final Consent consent = new Consent();
             consent.setId(attr.getId());
-            consent.setValue(attributeValuesHashFunction.apply(attr.getValues()));
+            consent.setValue(flowDescriptor.getAttributeValuesHashFunction().apply(attr.getValues()));
             if (attr.getId().equals("attribute1")) {
                 consent.setApproved(true);
             }
@@ -220,7 +219,7 @@ public class AttributeReleaseConsentFunctionTest {
         // Setup unsorted previous
         final Consent previousConsent = new Consent();
         previousConsent.setId("attribute1");
-        previousConsent.setValue(attributeValuesHashFunction.apply(ConsentTestingSupport.newAttributeMap(MapType.ORDER1)
+        previousConsent.setValue(flowDescriptor.getAttributeValuesHashFunction().apply(ConsentTestingSupport.newAttributeMap(MapType.ORDER1)
                 .get("attribute1").getValues()));
         previousConsent.setApproved(true);
         ConsentContext consentCtx = new ConsentContext();
@@ -274,7 +273,7 @@ public class AttributeReleaseConsentFunctionTest {
         for (final IdPAttribute attr : ConsentTestingSupport.newAttributeMap().values()) {
             final Consent consent = new Consent();
             consent.setId(attr.getId());
-            consent.setValue(attributeValuesHashFunction.apply(attr.getValues()));
+            consent.setValue(flowDescriptor.getAttributeValuesHashFunction().apply(attr.getValues()));
             expected.put(consent.getId(), consent);
         }
 

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


More information about the commits mailing list