[java-identity-provider] branch master updated: OSJ-218: Replace deprecated URL encoder in TemplateRequestURLBuilder

Brent Putman putmanb at georgetown.edu
Wed Sep 12 21:11:49 EDT 2018


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

putmanb 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=d3ad8a0f4f429a9cbe1c86d49ad1ceda3e898e5f

The following commit(s) were added to refs/heads/master by this push:
       new  d3ad8a0   OSJ-218: Replace deprecated URL encoder in TemplateRequestURLBuilder
d3ad8a0 is described below

commit d3ad8a0f4f429a9cbe1c86d49ad1ceda3e898e5f
Author: Brent Putman <putmanb at georgetown.edu>
AuthorDate: Wed Sep 12 20:47:49 2018 -0400

    OSJ-218: Replace deprecated URL encoder in TemplateRequestURLBuilder
    
    Spring parser and tests for new 'encodingStyle' attribute on
    dynamic HTTP provider of type Template.
---
 .../impl/DynamicHTTPMetadataProviderParser.java    | 48 ++++++++++++++++------
 .../DynamicHTTPMetadataProviderParserTest.java     | 17 ++++++++
 .../relyingparty/metadata/dynamicTemplate.xml      |  2 +-
 ...te.xml => dynamicTemplateWithLegacyEncoded.xml} |  2 +-
 .../main/resources/schema/shibboleth-metadata.xsd  | 12 +++++-
 5 files changed, 65 insertions(+), 16 deletions(-)

diff --git a/idp-profile-spring/src/main/java/net/shibboleth/idp/profile/spring/relyingparty/metadata/impl/DynamicHTTPMetadataProviderParser.java b/idp-profile-spring/src/main/java/net/shibboleth/idp/profile/spring/relyingparty/metadata/impl/DynamicHTTPMetadataProviderParser.java
index beac1cd..785942b 100644
--- a/idp-profile-spring/src/main/java/net/shibboleth/idp/profile/spring/relyingparty/metadata/impl/DynamicHTTPMetadataProviderParser.java
+++ b/idp-profile-spring/src/main/java/net/shibboleth/idp/profile/spring/relyingparty/metadata/impl/DynamicHTTPMetadataProviderParser.java
@@ -19,11 +19,6 @@ package net.shibboleth.idp.profile.spring.relyingparty.metadata.impl;
 
 import javax.xml.namespace.QName;
 
-import net.shibboleth.idp.profile.spring.relyingparty.metadata.AbstractMetadataProviderParser;
-import net.shibboleth.utilities.java.support.primitive.StringSupport;
-import net.shibboleth.utilities.java.support.xml.AttributeSupport;
-import net.shibboleth.utilities.java.support.xml.ElementSupport;
-
 import org.opensaml.saml.metadata.resolver.MetadataResolver;
 import org.opensaml.saml.metadata.resolver.impl.FunctionDrivenDynamicHTTPMetadataResolver;
 import org.opensaml.saml.metadata.resolver.impl.HTTPEntityIDRequestURLBuilder;
@@ -35,6 +30,13 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
 import org.springframework.beans.factory.xml.ParserContext;
 import org.w3c.dom.Element;
 
+import net.shibboleth.idp.profile.spring.relyingparty.metadata.AbstractMetadataProviderParser;
+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 net.shibboleth.utilities.java.support.xml.AttributeSupport;
+import net.shibboleth.utilities.java.support.xml.ElementSupport;
+
 /**
  * Parser for concrete dynamic HTTP metadata resolvers, based on {@link FunctionDrivenDynamicHTTPMetadataResolver}.
  */
@@ -86,13 +88,7 @@ public class DynamicHTTPMetadataProviderParser extends AbstractDynamicHTTPMetada
         final Element template = ElementSupport.getFirstChildElement(element, TEMPLATE);
         if (template != null) {
             final String templateString = StringSupport.trimOrNull(ElementSupport.getElementContentAsString(template));
-            Boolean encoded = null;
-            if (template.hasAttributeNS(null, "encoded")) {
-                encoded = AttributeSupport.getAttributeValueAsBoolean(template.getAttributeNodeNS(null, "encoded"));
-            }
-            if (encoded == null) {
-                encoded = true;
-            }
+            final String encodingStyle = parseTemplateEncodingStyle(template);
             String velocityEngineRef =
                     StringSupport.trimOrNull(StringSupport.trimOrNull(template.getAttributeNS(null, "velocityEngine")));
             if (null == velocityEngineRef) {
@@ -105,7 +101,7 @@ public class DynamicHTTPMetadataProviderParser extends AbstractDynamicHTTPMetada
                     BeanDefinitionBuilder.genericBeanDefinition(TemplateRequestURLBuilder.class);
             builder.addConstructorArgReference(velocityEngineRef);
             builder.addConstructorArgValue(templateString);
-            builder.addConstructorArgValue(encoded);
+            builder.addConstructorArgValue(encodingStyle);
             if (transformRef != null) {
                 builder.addConstructorArgReference(transformRef);
             }
@@ -148,4 +144,30 @@ public class DynamicHTTPMetadataProviderParser extends AbstractDynamicHTTPMetada
         return builder.getBeanDefinition();
     }
 
+    /**
+     * Parse the 'encodingStyle' and 'encoded' attributes for Template element types.
+     * @param template the Template element
+     * 
+     * @return the encoding style as a string
+     */
+    private String parseTemplateEncodingStyle(final Element template) {
+        String encodingStyle = null;
+        if (template.hasAttributeNS(null, "encodingStyle")) {
+            encodingStyle = StringSupport.trimOrNull(template.getAttributeNS(null, "encodingStyle"));
+        } else if (template.hasAttributeNS(null, "encoded")) {
+            DeprecationSupport.warnOnce(ObjectType.ATTRIBUTE, "encoded", null, "'encodingStyle'");
+            final Boolean encoded = 
+                    AttributeSupport.getAttributeValueAsBoolean(template.getAttributeNodeNS(null, "encoded"));
+            if (encoded != null && encoded) {
+                encodingStyle = "form";
+            } else {
+                encodingStyle = "none";
+            }
+        }
+        if (encodingStyle == null) {
+            encodingStyle = "form";
+        }
+        return encodingStyle;
+    }
+
 }
diff --git a/idp-profile-spring/src/test/java/net/shibboleth/idp/profile/spring/relyingparty/metadata/DynamicHTTPMetadataProviderParserTest.java b/idp-profile-spring/src/test/java/net/shibboleth/idp/profile/spring/relyingparty/metadata/DynamicHTTPMetadataProviderParserTest.java
index cf3d86c..48d891b 100644
--- a/idp-profile-spring/src/test/java/net/shibboleth/idp/profile/spring/relyingparty/metadata/DynamicHTTPMetadataProviderParserTest.java
+++ b/idp-profile-spring/src/test/java/net/shibboleth/idp/profile/spring/relyingparty/metadata/DynamicHTTPMetadataProviderParserTest.java
@@ -235,6 +235,23 @@ public class DynamicHTTPMetadataProviderParserTest extends AbstractMetadataParse
     }
 
     @Test
+    public void testTemplateWithLegacyEncoded() throws Exception {
+        MockPropertySource propSource = singletonPropertySource(PROP_MDURL, 
+                RepositorySupport.buildHTTPResourceURL(REPO_OPENSAML, TEMPLATE_URL, false));
+        
+        final FunctionDrivenDynamicHTTPMetadataResolver resolver = getBean(FunctionDrivenDynamicHTTPMetadataResolver.class, 
+                propSource, "dynamicTemplateWithLegacyEncoded.xml", "beans.xml");
+        
+        final String entityID = "https://www.example.org/sp";
+        
+        final CriteriaSet criteriaSet = new CriteriaSet( new EntityIdCriterion(entityID));
+        
+        final EntityDescriptor ed = resolver.resolveSingle(criteriaSet);
+        Assert.assertNotNull(ed);
+        Assert.assertEquals(ed.getEntityID(), entityID);
+    }
+
+    @Test
     public void testMDQ() throws Exception {
         final FunctionDrivenDynamicHTTPMetadataResolver resolver = getBean(FunctionDrivenDynamicHTTPMetadataResolver.class, 
                 "dynamicMetadataQueryProtocol.xml", "beans.xml");
diff --git a/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/relyingparty/metadata/dynamicTemplate.xml b/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/relyingparty/metadata/dynamicTemplate.xml
index 2d245e3..3359d27 100644
--- a/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/relyingparty/metadata/dynamicTemplate.xml
+++ b/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/relyingparty/metadata/dynamicTemplate.xml
@@ -7,7 +7,7 @@
 	id="dynamicTemplate" xsi:type="metadata:DynamicHTTPMetadataProvider" >
     
     <!-- Note: use of the transformRef here is mostly just to facilitate testing. -->
-    <metadata:Template transformRef="digester.SHA1HexLower">
+    <metadata:Template transformRef="digester.SHA1HexLower" encodingStyle="form">
         %{metadataURL}
     </metadata:Template>
 
diff --git a/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/relyingparty/metadata/dynamicTemplate.xml b/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/relyingparty/metadata/dynamicTemplateWithLegacyEncoded.xml
similarity index 86%
copy from idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/relyingparty/metadata/dynamicTemplate.xml
copy to idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/relyingparty/metadata/dynamicTemplateWithLegacyEncoded.xml
index 2d245e3..160b2ec 100644
--- a/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/relyingparty/metadata/dynamicTemplate.xml
+++ b/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/relyingparty/metadata/dynamicTemplateWithLegacyEncoded.xml
@@ -7,7 +7,7 @@
 	id="dynamicTemplate" xsi:type="metadata:DynamicHTTPMetadataProvider" >
     
     <!-- Note: use of the transformRef here is mostly just to facilitate testing. -->
-    <metadata:Template transformRef="digester.SHA1HexLower">
+    <metadata:Template transformRef="digester.SHA1HexLower" encoded="true">
         %{metadataURL}
     </metadata:Template>
 
diff --git a/idp-schema/src/main/resources/schema/shibboleth-metadata.xsd b/idp-schema/src/main/resources/schema/shibboleth-metadata.xsd
index 26a5616..ca265c2 100644
--- a/idp-schema/src/main/resources/schema/shibboleth-metadata.xsd
+++ b/idp-schema/src/main/resources/schema/shibboleth-metadata.xsd
@@ -372,11 +372,21 @@
                                     <attribute name="encoded" type="string">
                                         <annotation>
                                             <documentation>
-                                                Boolean flag indicating whether the entityID should be encoded
+                                                Deprecated, use encodingStyle instead.
+                                                
+                                                Boolean flag indicating whether the entityID should be URL form-encoded
                                                 before substitution into the template.
                                             </documentation>
                                         </annotation>
                                     </attribute>
+                                    <attribute name="encodingStyle" type="string">
+                                        <annotation>
+                                            <documentation>
+                                                Enum value indicating whether and how the entityID should be encoded into the 
+                                                URL. Allowed values are: 1) none 2) form 3) path 4) fragment.
+                                            </documentation>
+                                        </annotation>
+                                    </attribute>
                                     <attribute name="transformRef" type="string">
                                         <annotation>
                                             <documentation>

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


More information about the commits mailing list