[java-identity-provider] 21/51: IDP-1121 Disallow attribute names with spaces

Rod Widdowson rdw at steadingsoftware.com
Wed Feb 6 08:42:52 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=2cf20b4210c533a9f36933e6b8ee22ce1c1ef978

commit 2cf20b4210c533a9f36933e6b8ee22ce1c1ef978
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Mon Jan 21 16:07:01 2019 +0000

    IDP-1121 Disallow attribute names with spaces
    
    https://issues.shibboleth.net/jira/browse/IDP-1121
    
    In addition to the attribute definition we also ligature off the
    Attribute itself - just in case something sneak in on a wild card
    from an DataConnector.
---
 .../net/shibboleth/idp/attribute/IdPAttribute.java     |  3 ++-
 .../net/shibboleth/idp/attribute/AttributeTest.java    |  9 +++++++++
 .../resolver/AbstractAttributeDefinition.java          |  8 ++------
 .../resolver/AbstractAttributeDefinitionTest.java      | 18 +++++++++++++-----
 4 files changed, 26 insertions(+), 12 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 4f0e508..452b741 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
@@ -95,7 +95,8 @@ public class IdPAttribute implements Comparable<IdPAttribute>, Cloneable {
     public IdPAttribute(@Nonnull @NotEmpty @ParameterName(name="attributeId") final String attributeId) {
 
         id = Constraint.isNotNull(StringSupport.trimOrNull(attributeId), "Attribute ID may not be null");
-
+        Constraint.isTrue(id.indexOf(' ') < 0, "Attribute ID must not have spaces");
+        
         displayNames = Collections.emptyMap();
         displayDescriptions = Collections.emptyMap();
 
diff --git a/idp-attribute-api/src/test/java/net/shibboleth/idp/attribute/AttributeTest.java b/idp-attribute-api/src/test/java/net/shibboleth/idp/attribute/AttributeTest.java
index d987358..edc88a3 100644
--- a/idp-attribute-api/src/test/java/net/shibboleth/idp/attribute/AttributeTest.java
+++ b/idp-attribute-api/src/test/java/net/shibboleth/idp/attribute/AttributeTest.java
@@ -80,6 +80,15 @@ public class AttributeTest {
         } catch (ConstraintViolationException e) {
             // expected this
         }
+        
+        try {
+            new IdPAttribute("a b");
+            Assert.fail("able to create attribute ID with spaces");
+        } catch (ConstraintViolationException e) {
+            // expected this
+        }
+
+        
     }
 
     /** Tests that display names are properly added and modified. */
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 7c476c9..7d9856b 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
@@ -41,8 +41,6 @@ import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
 import net.shibboleth.utilities.java.support.collection.CollectionSupport;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 import net.shibboleth.utilities.java.support.component.ComponentSupport;
-import net.shibboleth.utilities.java.support.primitive.DeprecationSupport;
-import net.shibboleth.utilities.java.support.primitive.DeprecationSupport.ObjectType;
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
 
 import org.slf4j.Logger;
@@ -230,10 +228,8 @@ public abstract class AbstractAttributeDefinition extends AbstractResolverPlugin
         logPrefix = null;
         
         if (!Pattern.matches("\\S*", getId())) {
-            DeprecationSupport.warn(ObjectType.CONFIGURATION, 
-                    "Use of IdP Attributes names with spaces in them", 
-                    getLogPrefix(), 
-                    null);
+            throw new ComponentInitializationException(
+                    "Attributes Definitions must not have spaces in them (" + getId() + ")");
             
         }
     }
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 43a6f0a..ca59f71 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
@@ -215,11 +215,19 @@ public class AbstractAttributeDefinitionTest {
         Assert.assertEquals(depends.iterator().next().getDependencyAttributeId(), "source");
     }
     
-    @Test public void invalidName() throws ComponentInitializationException {
-        MockAttributeDefinition definition = new MockAttributeDefinition("Name With Space", (IdPAttribute) null);
-        definition.initialize();
-        definition = new MockAttributeDefinition("Name\rWith\tnonprinters", (IdPAttribute) null);
-        definition.initialize();
+    private void testInvalidName(@Nonnull MockAttributeDefinition attrdef) {
+        try {
+            attrdef.initialize();
+            Assert.fail(attrdef.getId() +  "' Should not have initialized OK");
+        }
+        catch (ComponentInitializationException e) {
+            // OK No actions
+        }
+    }
+    
+    @Test public void invalidName() {
+        testInvalidName(new MockAttributeDefinition("Name With Space", (IdPAttribute) null));
+        testInvalidName(new MockAttributeDefinition("Name\rWith\tnonprinters", (IdPAttribute) null));
     }
     
     @Test public void initDestroyValidate() throws ComponentInitializationException {

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


More information about the commits mailing list