[java-identity-provider] branch master updated: IDP-1389 Handle mapping to null and empty strings

Rod Widdowson rdw at steadingsoftware.com
Sat Jan 12 09:12:14 EST 2019


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

rdw 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=7e8436c5729cc33e718235a8e0cee2765d315836

The following commit(s) were added to refs/heads/master by this push:
       new  7e8436c   IDP-1389 Handle mapping to null and empty strings
7e8436c is described below

commit 7e8436c5729cc33e718235a8e0cee2765d315836
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sat Jan 12 14:10:53 2019 +0000

    IDP-1389 Handle mapping to null and empty strings
    
    https://issues.shibboleth.net/jira/browse/IDP-1389
---
 .../resolver/ad/mapped/impl/ValueMap.java          | 28 +++++++++++---------
 .../ad/mapped/impl/MappedAttributeTest.java        | 30 ++++++++++++++++++++++
 2 files changed, 46 insertions(+), 12 deletions(-)

diff --git a/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/mapped/impl/ValueMap.java b/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/mapped/impl/ValueMap.java
index be6d4c5..a53cbe7 100644
--- a/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/mapped/impl/ValueMap.java
+++ b/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/mapped/impl/ValueMap.java
@@ -27,14 +27,6 @@ import java.util.regex.PatternSyntaxException;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
-import net.shibboleth.idp.attribute.StringAttributeValue;
-import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
-import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
-import net.shibboleth.utilities.java.support.annotation.constraint.NullableElements;
-import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
-import net.shibboleth.utilities.java.support.logic.Constraint;
-import net.shibboleth.utilities.java.support.primitive.StringSupport;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -43,6 +35,14 @@ import com.google.common.base.Predicates;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 
+import net.shibboleth.idp.attribute.StringAttributeValue;
+import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+import net.shibboleth.utilities.java.support.annotation.constraint.NullableElements;
+import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
+
 /**
  * Performs many to one mapping of source values to a return value. SourceValue strings may include regular expressions
  * and the ReturnValue may include back references to capturing groups as supported by {@link java.util.regex.Pattern}.
@@ -108,8 +108,8 @@ public class ValueMap implements Function<String, Set<StringAttributeValue>> {
      * @return set of new values the incoming value mapped to
      */
     /** {@inheritDoc} */
-    @Override
-    @Nullable public Set<StringAttributeValue> apply(@Nullable final String attributeValue) {
+    // CheckStyle: CyclomaticComplexity OFF
+    @Override @Nullable public Set<StringAttributeValue> apply(@Nullable final String attributeValue) {
         
         if (attributeValue == null) {
             log.debug("Input value was null, returning empty set");
@@ -145,12 +145,16 @@ public class ValueMap implements Function<String, Set<StringAttributeValue>> {
                 }
             }
 
-            if (newValue != null) {
+            if (newValue == null) {
+                log.debug("Value {} yielded a null value", attributeValue);
+            } else if ("".equals(newValue)) {
+                log.debug("Value {} yielded an empty value", attributeValue);
+            } else {
                 mappedValues.add(new StringAttributeValue(newValue));
             }
         }
 
         return mappedValues;
     }
-
+    // CheckStyle: CyclomaticComplexity ON
 }
\ No newline at end of file
diff --git a/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/ad/mapped/impl/MappedAttributeTest.java b/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/ad/mapped/impl/MappedAttributeTest.java
index b38d62a..696d004 100644
--- a/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/ad/mapped/impl/MappedAttributeTest.java
+++ b/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/ad/mapped/impl/MappedAttributeTest.java
@@ -261,4 +261,34 @@ public class MappedAttributeTest {
         return retVal;
     }
     
+    @Test public void IdP1389() throws Exception {
+        final SourceValue source = new SourceValue();
+        source.setValue(".*(.*)");
+        source.setPartialMatch(false);
+        source.initialize();
+
+        final ValueMap valueMap = new ValueMap();
+        valueMap.setReturnValue("$1");
+        valueMap.setSourceValues(Collections.singleton(source));
+        
+        final MappedAttributeDefinition definition = new MappedAttributeDefinition();
+        definition.setId(TEST_ATTRIBUTE_NAME);
+        definition.setDependencies(Collections.singleton(TestSources.makeResolverPluginDependency("connector1",
+                ResolverTestSupport.EPA_ATTRIB_ID)));
+        
+        definition.setValueMaps(Collections.singleton(valueMap));
+        definition.initialize();
+
+        final AttributeResolutionContext resolutionContext =
+                ResolverTestSupport.buildResolutionContext(ResolverTestSupport.buildDataConnector("connector1",
+                        ResolverTestSupport.buildAttribute(ResolverTestSupport.EPE_ATTRIB_ID,
+                                ResolverTestSupport.EPE1_VALUES), ResolverTestSupport.buildAttribute(
+                                ResolverTestSupport.EPA_ATTRIB_ID, "Val", "val")));
+        
+        final IdPAttribute result = definition.resolve(resolutionContext);
+        
+        
+
+    }
+    
 }
\ No newline at end of file

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


More information about the commits mailing list