[java-identity-provider] 02/04: IdP-1206 IdPAttribute: Don't silently filter null values
Rod Widdowson
rdw at steadingsoftware.com
Tue Apr 17 11:14:34 EDT 2018
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=9b83c02171ed1cec6d645ce02bd46961604b0243
commit 9b83c02171ed1cec6d645ce02bd46961604b0243
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Apr 17 11:36:15 2018 +0100
IdP-1206 IdPAttribute: Don't silently filter null values
https://issues.shibboleth.net/jira/browse/IDP-1206
Note that this entails changing the scripted tests which created garbage input.
---
.../net/shibboleth/idp/attribute/IdPAttribute.java | 35 ++++++++++++++++------
.../resolver/impl/dc/scriptedConnector.js | 3 --
.../resolver/impl/dc/v8/scriptedConnector.js | 3 --
.../spring/dc/resolver/scriptedAttributes.xml | 1 -
.../resolver/spring/dc/scriptedAttributes.xml | 2 --
.../resolver/spring/dc/scriptedConnector.8.js | 3 --
6 files changed, 26 insertions(+), 21 deletions(-)
diff --git a/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/IdPAttribute.java b/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/IdPAttribute.java
index c136776..ba41d56 100644
--- a/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/IdPAttribute.java
+++ b/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/IdPAttribute.java
@@ -29,6 +29,16 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
+import com.google.common.base.Function;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+
+import net.shibboleth.idp.attribute.EmptyAttributeValue.EmptyType;
import net.shibboleth.utilities.java.support.annotation.ParameterName;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
@@ -38,14 +48,6 @@ 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 com.google.common.base.MoreObjects;
-import com.google.common.base.Objects;
-import com.google.common.base.Predicates;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-
/**
* Each attribute represents one piece of information about a user and has associated encoders used to turn that
* information in to protocol-specific formats.
@@ -55,6 +57,20 @@ import com.google.common.collect.ImmutableSet;
*/
@NotThreadSafe
public class IdPAttribute implements Comparable<IdPAttribute>, Cloneable {
+
+ /** helper {@link Function} to convert null to {@link EmptyAttributeValue}. */
+ private static Function<IdPAttributeValue<?>, IdPAttributeValue<?>> convertNullValues
+ = new Function<IdPAttributeValue<?>, IdPAttributeValue<?>>() {
+
+ @Override
+ public IdPAttributeValue<?> apply(final IdPAttributeValue<?> input) {
+ if (null == input) {
+ return new EmptyAttributeValue(EmptyType.NULL_VALUE);
+ } else {
+ return input;
+ }
+ }
+ };
/** ID of this attribute. */
@Nonnull private final String id;
@@ -173,7 +189,7 @@ public class IdPAttribute implements Comparable<IdPAttribute>, Cloneable {
*/
public void setValues(@Nullable @NullableElements final Collection<? extends IdPAttributeValue<?>> newValues) {
if (newValues != null) {
- values = ImmutableList.copyOf(Collections2.filter(newValues, Predicates.notNull()));
+ values = ImmutableList.copyOf(Collections2.transform(newValues, convertNullValues));
} else {
values = ImmutableList.of();
}
@@ -255,4 +271,5 @@ public class IdPAttribute implements Comparable<IdPAttribute>, Cloneable {
.add("displayDescriptions", displayDescriptions).add("encoders", encoders).add("values", values)
.toString();
}
+
}
\ No newline at end of file
diff --git a/idp-attribute-resolver-impl/src/test/resources/net/shibboleth/idp/attribute/resolver/impl/dc/scriptedConnector.js b/idp-attribute-resolver-impl/src/test/resources/net/shibboleth/idp/attribute/resolver/impl/dc/scriptedConnector.js
index 2e7a07f..e9dee04 100644
--- a/idp-attribute-resolver-impl/src/test/resources/net/shibboleth/idp/attribute/resolver/impl/dc/scriptedConnector.js
+++ b/idp-attribute-resolver-impl/src/test/resources/net/shibboleth/idp/attribute/resolver/impl/dc/scriptedConnector.js
@@ -13,7 +13,6 @@ attr = new IdPAttribute("TwoScripted");
set = new HashSet(4);
set.add(new StringAttributeValue("1Value"));
set.add(new StringAttributeValue("2Value"));
-set.add(new Integer(4));
set.add(new StringAttributeValue("3Value"));
attr.setValues(set);
connectorResults.add(attr);
@@ -32,8 +31,6 @@ attr.setValues(set);
connectorResults.add(attr);
-connectorResults.add(new Integer(4));
-
child = profileContext.getSubcontext("net.shibboleth.idp.attribute.resolver.context.AttributeResolutionContext");
attr = new IdPAttribute("ThreeScripted");
diff --git a/idp-attribute-resolver-impl/src/test/resources/net/shibboleth/idp/attribute/resolver/impl/dc/v8/scriptedConnector.js b/idp-attribute-resolver-impl/src/test/resources/net/shibboleth/idp/attribute/resolver/impl/dc/v8/scriptedConnector.js
index 12e5891..00478bb 100644
--- a/idp-attribute-resolver-impl/src/test/resources/net/shibboleth/idp/attribute/resolver/impl/dc/v8/scriptedConnector.js
+++ b/idp-attribute-resolver-impl/src/test/resources/net/shibboleth/idp/attribute/resolver/impl/dc/v8/scriptedConnector.js
@@ -1,7 +1,6 @@
IdPAttribute = Java.type("net.shibboleth.idp.attribute.IdPAttribute");
StringAttributeValue = Java.type("net.shibboleth.idp.attribute.StringAttributeValue");
HashSet = Java.type("java.util.HashSet");
-Integer = Java.type("java.lang.Integer");
attr = new IdPAttribute("ScriptedOne");
set = new HashSet(2);
@@ -18,7 +17,6 @@ attr = new IdPAttribute("TwoScripted");
set = new HashSet(4);
set.add(new StringAttributeValue("1Value"));
set.add(new StringAttributeValue("2Value"));
-set.add(new Integer(4));
set.add(new StringAttributeValue("3Value"));
attr.setValues(set);
connectorResults.add(attr);
@@ -36,7 +34,6 @@ while (x.hasNext()){
attr.setValues(set);
connectorResults.add(attr);
-connectorResults.add(new Integer(4));
child = profileContext.getSubcontext("net.shibboleth.idp.attribute.resolver.context.AttributeResolutionContext");
attr = new IdPAttribute("ThreeScripted");
diff --git a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/dc/resolver/scriptedAttributes.xml b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/dc/resolver/scriptedAttributes.xml
index 21d52aa..2ede7e7 100644
--- a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/dc/resolver/scriptedAttributes.xml
+++ b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/dc/resolver/scriptedAttributes.xml
@@ -22,7 +22,6 @@ attr = new IdPAttribute("TwoScripted");
set = new HashSet(4);
set.add(new StringAttributeValue("1Value"));
set.add(new StringAttributeValue("2Value"));
-set.add(new Integer(4));
set.add(new StringAttributeValue("3Value"));
attr.setValues(set);
connectorResults.add(attr);
diff --git a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/dc/scriptedAttributes.xml b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/dc/scriptedAttributes.xml
index 6d77164..788aad1 100644
--- a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/dc/scriptedAttributes.xml
+++ b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/dc/scriptedAttributes.xml
@@ -28,11 +28,9 @@ attr = new IdPAttribute("TwoScripted");
set = new HashSet(4);
set.add(new StringAttributeValue("1Value"));
set.add(new StringAttributeValue("2Value"));
-set.add(new Integer(4));
set.add(new StringAttributeValue("3Value"));
attr.setValues(set);
connectorResults.add(attr);
-connectorResults.add(new Integer(4));
]]></dc:Script>
</resolver:DataConnector>
diff --git a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/dc/scriptedConnector.8.js b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/dc/scriptedConnector.8.js
index 2e722da..a3358da 100644
--- a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/dc/scriptedConnector.8.js
+++ b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/dc/scriptedConnector.8.js
@@ -1,7 +1,6 @@
IdPAttribute = Java.type("net.shibboleth.idp.attribute.IdPAttribute");
StringAttributeValue = Java.type("net.shibboleth.idp.attribute.StringAttributeValue");
HashSet = Java.type("java.util.HashSet");
-Integer = Java.type("java.lang.Integer");
attr = new IdPAttribute("ScriptedOne");
set = new HashSet(2);
@@ -14,9 +13,7 @@ attr = new IdPAttribute("TwoScripted");
set = new HashSet(4);
set.add(new StringAttributeValue("1Value"));
set.add(new StringAttributeValue("2Value"));
-set.add(new Integer(4));
set.add(new StringAttributeValue("3Value"));
attr.setValues(set);
connectorResults.add(attr);
-connectorResults.add(new Integer(4));
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list