[java-opensaml] branch main updated: JMETAGEN-5 - Metadata generation.

Scott Cantor cantor.2 at osu.edu
Thu Jul 13 14:18:40 UTC 2023


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

scantor pushed a commit to branch main
in repository java-opensaml.

View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=542d3b9d0a0e91b882292603a8127ffebc3c6004

The following commit(s) were added to refs/heads/main by this push:
     new 542d3b9d0 JMETAGEN-5 - Metadata generation.
542d3b9d0 is described below

commit 542d3b9d0a0e91b882292603a8127ffebc3c6004
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Jul 13 10:18:37 2023 -0400

    JMETAGEN-5 - Metadata generation.
    
    https://shibboleth.atlassian.net/browse/JMETAGEN-5
    
    Add XML escaping.
    Add tag support.
---
 .../impl/MetadataGeneratorParameters.java          | 17 ++++++++--
 .../generator/impl/VelocityMetadataGenerator.java  |  6 +++-
 .../metadata/AttributeAuthorityDescriptor.vm       |  2 +-
 .../templates/metadata/EntityDescriptor.vm         | 37 +++++++++++++++-------
 .../templates/metadata/IDPSSODescriptor.vm         |  6 ++--
 .../templates/metadata/SPSSODescriptor.vm          |  8 ++---
 6 files changed, 53 insertions(+), 23 deletions(-)

diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/generator/impl/MetadataGeneratorParameters.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/generator/impl/MetadataGeneratorParameters.java
index 50f131cc3..17cd5f633 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/generator/impl/MetadataGeneratorParameters.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/generator/impl/MetadataGeneratorParameters.java
@@ -16,13 +16,16 @@
  */
 package org.opensaml.saml.metadata.generator.impl;
 
+import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import org.opensaml.core.xml.Namespace;
+import org.opensaml.saml.ext.saml2mdattr.EntityAttributes;
 import org.opensaml.saml.ext.saml2mdui.Logo;
 import org.opensaml.saml.saml2.metadata.AttributeAuthorityDescriptor;
 import org.opensaml.saml.saml2.metadata.ContactPerson;
@@ -67,7 +70,8 @@ public interface MetadataGeneratorParameters {
      * @return whether to include extensions element
      */
     default boolean isRequiresExtensions() {
-        return getDisplayName() != null || getDescription() != null || getLogo() != null;
+        return getDisplayName() != null || getDescription() != null || getLogo() != null
+                || !getTagAssignments().isEmpty();
     }
     
     /**
@@ -207,5 +211,14 @@ public interface MetadataGeneratorParameters {
     @Nonnull @Unmodifiable @NotLive default List<ContactPerson> getContactPersons() {
         return CollectionSupport.emptyList();
     }
-
+    
+    /**
+     * Get the {@link EntityAttributes} tag names and values in the form of a Java-based multi-map.
+     * 
+     * @return map of tag names to zero or more values
+     */
+    @Nonnull @Unmodifiable @NotLive default Map<String,Collection<String>> getTagAssignments() {
+        return CollectionSupport.emptyMap();
+    }
+    
 }
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/generator/impl/VelocityMetadataGenerator.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/generator/impl/VelocityMetadataGenerator.java
index 60ede274b..813609882 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/generator/impl/VelocityMetadataGenerator.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/generator/impl/VelocityMetadataGenerator.java
@@ -31,6 +31,8 @@ import org.opensaml.core.xml.Namespace;
 import org.opensaml.saml.common.xml.SAMLConstants;
 import org.opensaml.xmlsec.signature.support.SignatureConstants;
 
+import com.google.common.xml.XmlEscapers;
+
 import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
 import net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent;
 import net.shibboleth.shared.component.ComponentInitializationException;
@@ -102,7 +104,6 @@ public class VelocityMetadataGenerator extends AbstractIdentifiableInitializable
             final Map<String,String> prefixMap = new HashMap<>();
             
             prefixMap.put(SAMLConstants.SAML20MD_PREFIX, SAMLConstants.SAML20MD_NS);
-            prefixMap.put(SAMLConstants.SAML20_PREFIX, SAMLConstants.SAML20_NS);
             prefixMap.put(SignatureConstants.XMLSIG_PREFIX, SignatureConstants.XMLSIG_NS);
             
             final Set<Namespace> additionalNamespaces = params.getAdditionalNamespaces();
@@ -115,6 +116,9 @@ public class VelocityMetadataGenerator extends AbstractIdentifiableInitializable
             context.put("namespaces", prefixMap);
         }
         
+        context.put("xmltext", XmlEscapers.xmlContentEscaper());
+        context.put("xmlattr", XmlEscapers.xmlAttributeEscaper());
+        
         return context;
     }
 
diff --git a/opensaml-saml-impl/src/main/resources/templates/metadata/AttributeAuthorityDescriptor.vm b/opensaml-saml-impl/src/main/resources/templates/metadata/AttributeAuthorityDescriptor.vm
index d4d8b206e..dd016fb50 100644
--- a/opensaml-saml-impl/src/main/resources/templates/metadata/AttributeAuthorityDescriptor.vm
+++ b/opensaml-saml-impl/src/main/resources/templates/metadata/AttributeAuthorityDescriptor.vm
@@ -2,6 +2,6 @@
     <md:AttributeAuthorityDescriptor protocolSupportEnumeration="#foreach($p in $role.supportedProtocols)$p#if(!$foreach.last) #end#end">
 #parse("$params.templatePath/KeyDescriptors.vm")
 #foreach ($endpoint in $role.attributeServices)
-        <md:AttributeService Binding="$endpoint.binding" Location="$endpoint.location" />
+        <md:AttributeService Binding="$endpoint.binding" Location="$xmlattr.escape($endpoint.location)" />
 #end
     </md:AttributeAuthorityDescriptor>
diff --git a/opensaml-saml-impl/src/main/resources/templates/metadata/EntityDescriptor.vm b/opensaml-saml-impl/src/main/resources/templates/metadata/EntityDescriptor.vm
index f9ba18271..0cee3f67b 100644
--- a/opensaml-saml-impl/src/main/resources/templates/metadata/EntityDescriptor.vm
+++ b/opensaml-saml-impl/src/main/resources/templates/metadata/EntityDescriptor.vm
@@ -1,20 +1,33 @@
-<md:EntityDescriptor#if (!$params.omitNamespaceDeclarations)#foreach ($ns in $namespaces.entrySet()) xmlns:$ns.key="$ns.value"#end#end entityID="$params.entityID">
+<md:EntityDescriptor entityID="$xmlattr.escape($params.entityID)"#if (!$params.omitNamespaceDeclarations)#foreach ($ns in $namespaces.entrySet()) xmlns:$ns.key="$ns.value"#end#end>
 #if ($params.requiresExtensions)
 
     <md:Extensions>
 #if ($params.displayName || $params.description || $params.logo)
         <mdui:UIInfo>
 #if ($params.displayName)
-            <mdui:DisplayName>$params.displayName</mdui:DisplayName>
+            <mdui:DisplayName>$xmltext.escape($params.displayName)</mdui:DisplayName>
 #end
 #if ($params.description)
-            <mdui:Description>$params.description</mdui:Description>
+            <mdui:Description>$xmltext.escape($params.description)</mdui:Description>
 #end
 #if ($params.logo)
-            <mdui:Logo#if ($params.lang) xml:lang="$params.lang"#end#if ($params.logo.width) width="$params.logo.width"#end#if ($params.logo.height) height="$params.logo.height"#end>$params.logo.URI</mdui:Logo>
+            <mdui:Logo#if ($params.lang) xml:lang="$params.lang"#end#if ($params.logo.width) width="$params.logo.width"#end#if ($params.logo.height) height="$params.logo.height"#end>$xmltext.escape($params.logo.URI)</mdui:Logo>
 #end
 #end
         </mdui:UIInfo>
+#foreach ($tag in $params.tagAssignments.entrySet())
+#if ($foreach.first)
+        <mdattr:EntityAttributes>
+#end
+            <saml:Attribute Name="$xmlattr.escape($tag.key)" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
+#foreach ($val in $tag.value)
+                <saml:AttributeValue>$xmltext.escape($val)</saml:AttributeValue>
+#end
+            </saml:Attribute>
+#if ($foreach.last)
+        </mdattr:EntityAttributes>
+#end
+#end
     </md:Extensions>
 #end
 #if ($params.IDPSSODescriptor)
@@ -32,30 +45,30 @@
 #if ($params.organizationName || $params.organizationURL)
     <md:Organization>
 #if ($params.organizationName)
-        <md:OrganizationName#if ($params.lang) xml:lang="$params.lang"#end>$params.organizationName</md:OrganizationName>
-        <md:OrganizationDisplayName#if ($params.lang) xml:lang="$params.lang"#end>$params.organizationName</md:OrganizationDisplayName>
+        <md:OrganizationName#if ($params.lang) xml:lang="$params.lang"#end>$xmltext.escape($params.organizationName)</md:OrganizationName>
+        <md:OrganizationDisplayName#if ($params.lang) xml:lang="$params.lang"#end>$xmltext.escape($params.organizationName)</md:OrganizationDisplayName>
 #end
 #if ($params.organizationURL)
-        <md:OrganizationURL#if ($params.lang) xml:lang="$params.lang"#end>$params.organizationURL</md:OrganizationURL>
+        <md:OrganizationURL#if ($params.lang) xml:lang="$params.lang"#end>$xmltext.escape($params.organizationURL)</md:OrganizationURL>
 #end
     </md:Organization>
 #end
 #foreach ($contact in $params.contactPersons)
     <md:ContactPerson contactType="$contact.type">
 #if ($contact.company)
-        <md:Company>$contact.company.value</md:Company>
+        <md:Company>$xmltext.escape($contact.company.value)</md:Company>
 #end
 #if ($contact.givenName)
-        <md:GivenName>$contact.givenName.value</md:GivenName>
+        <md:GivenName>$xmltext.escape($contact.givenName.value)</md:GivenName>
 #end
 #if ($contact.surName)
-        <md:SurName>$contact.surName.value</md:SurName>
+        <md:SurName>$xmltext.escape($contact.surName.value)</md:SurName>
 #end
 #foreach ($mail in $contact.emailAddresses)
-        <md:EmailAddress>$mail.URI</md:EmailAddress>
+        <md:EmailAddress>$xmltext.escape($mail.URI)</md:EmailAddress>
 #end
 #foreach ($phone in $contact.telephoneNumbers)
-        <md:TelephoneNumber>$phone.value</md:TelephoneNumber>
+        <md:TelephoneNumber>$xmltext.escape($phone.value)</md:TelephoneNumber>
 #end
     </md:ContactPerson>
 #end
diff --git a/opensaml-saml-impl/src/main/resources/templates/metadata/IDPSSODescriptor.vm b/opensaml-saml-impl/src/main/resources/templates/metadata/IDPSSODescriptor.vm
index bb639ea4b..81091be9b 100644
--- a/opensaml-saml-impl/src/main/resources/templates/metadata/IDPSSODescriptor.vm
+++ b/opensaml-saml-impl/src/main/resources/templates/metadata/IDPSSODescriptor.vm
@@ -2,12 +2,12 @@
     <md:IDPSSODescriptor protocolSupportEnumeration="#foreach($p in $role.supportedProtocols)$p#if(!$foreach.last) #end#end">
 #parse("$params.templatePath/KeyDescriptors.vm")
 #foreach ($endpoint in $role.artifactResolutionServices)
-        <md:ArtifactResolutionService index="$endpoint.index" Binding="$endpoint.binding" Location="$endpoint.location" />
+        <md:ArtifactResolutionService index="$endpoint.index" Binding="$endpoint.binding" Location="$xmlattr.escape($endpoint.location)" />
 #end
 #foreach ($endpoint in $role.singleLogoutServices)
-        <md:SingleLogoutService Binding="$endpoint.binding" Location="$endpoint.location" />
+        <md:SingleLogoutService Binding="$endpoint.binding" Location=""$xmlattr.escape($endpoint.location)" />
 #end
 #foreach ($endpoint in $role.singleSignOnServices)
-        <md:SingleSignOnService Binding="$endpoint.binding" Location="$endpoint.location" />
+        <md:SingleSignOnService Binding="$endpoint.binding" Location=""$xmlattr.escape($endpoint.location)" />
 #end
     </md:IDPSSODescriptor>
diff --git a/opensaml-saml-impl/src/main/resources/templates/metadata/SPSSODescriptor.vm b/opensaml-saml-impl/src/main/resources/templates/metadata/SPSSODescriptor.vm
index 477f53794..1811e39fb 100644
--- a/opensaml-saml-impl/src/main/resources/templates/metadata/SPSSODescriptor.vm
+++ b/opensaml-saml-impl/src/main/resources/templates/metadata/SPSSODescriptor.vm
@@ -2,15 +2,15 @@
     <md:SPSSODescriptor #if ($role.wantAssertionsSigned)WantAssertionsSigned="true" #{end}protocolSupportEnumeration="#foreach($p in $role.supportedProtocols)$p#if(!$foreach.last) #end#end">
 #parse("$params.templatePath/KeyDescriptors.vm")
 #foreach ($endpoint in $role.artifactResolutionServices)
-        <md:ArtifactResolutionService index="$endpoint.index" Binding="$endpoint.binding" Location="$endpoint.location" />
+        <md:ArtifactResolutionService index="$endpoint.index" Binding="$endpoint.binding" Location=""$xmlattr.escape($endpoint.location)" />
 #end
 #foreach ($endpoint in $role.singleLogoutServices)
-        <md:SingleLogoutService Binding="$endpoint.binding" Location="$endpoint.location" />
+        <md:SingleLogoutService Binding="$endpoint.binding" Location=""$xmlattr.escape($endpoint.location)" />
 #end
 #foreach ($format in $role.nameIDFormats)
-        <md:NameIDFormat>$format.URI</md:NameIDFormat>
+        <md:NameIDFormat>$xmltext.escape($format.URI)</md:NameIDFormat>
 #end
 #foreach ($endpoint in $role.assertionConsumerServices)
-        <md:AssertionConsumerService index="$endpoint.index" Binding="$endpoint.binding" Location="$endpoint.location" />
+        <md:AssertionConsumerService index="$endpoint.index" Binding="$endpoint.binding" Location=""$xmlattr.escape($endpoint.location)" />
 #end
     </md:SPSSODescriptor>

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


More information about the commits mailing list