[java-identity-provider] 06/06: IDP-1121 Attribute Values are no longer generic. Final stage

Rod Widdowson rdw at steadingsoftware.com
Fri May 17 09:10:04 EDT 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=31fdb969d3a8928115e3fb6d302c7ee0294309d1

commit 31fdb969d3a8928115e3fb6d302c7ee0294309d1
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri May 17 14:09:12 2019 +0100

    IDP-1121 Attribute Values are no longer generic.  Final stage
    
    https://issues.shibboleth.net/jira/browse/IDP-1121
    
    Templated attribute definitions cna now take non strins attribute values
---
 .../ad/impl/TemplateAttributeDefinition.java       |  8 +++---
 .../resolver/ad/impl/TemplateAttributeTest.java    | 31 +++++++++++++++-------
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/impl/TemplateAttributeDefinition.java b/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/impl/TemplateAttributeDefinition.java
index db906b8..db46d17 100644
--- a/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/impl/TemplateAttributeDefinition.java
+++ b/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/impl/TemplateAttributeDefinition.java
@@ -203,7 +203,7 @@ public class TemplateAttributeDefinition extends AbstractAttributeDefinition {
             // Build velocity context.
             for (final String attributeId : sourceValues.keySet()) {
                 final IdPAttributeValue value = sourceValues.get(attributeId).next();
-                final String velocityValue;
+                final Object velocityValue;
                 if (value instanceof EmptyAttributeValue) {
                     switch (((EmptyAttributeValue) value).getValue()) {
                         case NULL_VALUE:
@@ -219,10 +219,8 @@ public class TemplateAttributeDefinition extends AbstractAttributeDefinition {
                 } else if (value instanceof StringAttributeValue) {
                     velocityValue = ((StringAttributeValue) value).getValue();
                 } else {
-                    throw new ResolutionException(new UnsupportedAttributeTypeException(getLogPrefix()
-                            + "This attribute definition only supports attribute value types of "
-                            + StringAttributeValue.class.getName() + " not values of type "
-                            + value.getClass().getName()));
+                    log.debug("{} Adding non string Attribute value : {}", getLogPrefix(), value.getNativeValue());
+                    velocityValue =value.getNativeValue(); 
                 }
                 log.debug("{} Adding value '{}' for attribute '{}' to the template context", new Object[] {
                         getLogPrefix(), velocityValue, attributeId,});
diff --git a/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/ad/impl/TemplateAttributeTest.java b/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/ad/impl/TemplateAttributeTest.java
index e4309ad..c7dba46 100644
--- a/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/ad/impl/TemplateAttributeTest.java
+++ b/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/ad/impl/TemplateAttributeTest.java
@@ -35,7 +35,6 @@ import javax.annotation.concurrent.ThreadSafe;
 import org.apache.velocity.app.VelocityEngine;
 import org.testng.annotations.Test;
 
-import net.shibboleth.idp.attribute.ByteAttributeValue;
 import net.shibboleth.idp.attribute.EmptyAttributeValue;
 import net.shibboleth.idp.attribute.IdPAttribute;
 import net.shibboleth.idp.attribute.IdPAttributeValue;
@@ -407,13 +406,14 @@ public class TemplateAttributeTest {
         resolver.resolveAttributes(context);
     }
 
-    @Test public void wrongType() throws ResolutionException, ComponentInitializationException {
+    @Test public void complexType() throws ResolutionException, ComponentInitializationException {
         final String name = TEST_ATTRIBUTE_BASE_NAME + "3";
 
         final TemplateAttributeDefinition templateDef = new TemplateAttributeDefinition();
         templateDef.setId(name);
         templateDef.setVelocityEngine(getEngine());
-        templateDef.setTemplateText(TEST_ATTRIBUTES_TEMPLATE_ATTR);
+        // call the getValue() method on the object
+        templateDef.setTemplateText("Result: ${at1.getValue()}");
 
         final Set<ResolverAttributeDefinitionDependency> ds = new LazySet<>();
         ds.add(TestSources.makeAttributeDefinitionDependency(TestSources.DEPENDS_ON_ATTRIBUTE_NAME_ATTR));
@@ -422,7 +422,19 @@ public class TemplateAttributeTest {
         templateDef.initialize();
 
         final IdPAttribute attr = new IdPAttribute(TestSources.DEPENDS_ON_ATTRIBUTE_NAME_ATTR);
-        attr.setValues(Collections.singletonList(new ByteAttributeValue(new byte[] {1, 2, 3})));
+        attr.setValues(Collections.singletonList(
+                // An attribute value whose native value is a string attribute value
+                // (to show that a non string object gets injected)
+                new IdPAttributeValue() {
+                    
+                    public Object getNativeValue() {
+                        return new StringAttributeValue("NativeValue");
+                    }
+                    
+                    public String getDisplayValue() {
+                        return null;
+                    }
+                }));
         final StaticAttributeDefinition simple = new StaticAttributeDefinition();
         simple.setId(TestSources.DEPENDS_ON_ATTRIBUTE_NAME_ATTR);
         simple.setValue(attr);
@@ -435,12 +447,11 @@ public class TemplateAttributeTest {
         resolver.initialize();
 
         final AttributeResolutionContext context = new AttributeResolutionContext();
-        try {
-            resolver.resolveAttributes(context);
-            fail();
-        } catch (final ResolutionException ex) {
-            // OK
-        }
+        resolver.resolveAttributes(context);
+        
+        final String result = ((StringAttributeValue)context.getResolvedIdPAttributes().get(name).getValues().get(0)).getValue();
+        assertEquals(result, "Result: NativeValue");
+        
     }
 
 }

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


More information about the commits mailing list