[java-opensaml] branch main updated: Add helper to build Attributes.

Scott Cantor cantor.2 at osu.edu
Wed Sep 18 16:40:13 UTC 2024


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=f80acd35fe843a0f08f4804eaa271333a23f376b

The following commit(s) were added to refs/heads/main by this push:
     new f80acd35f Add helper to build Attributes.
f80acd35f is described below

commit f80acd35fe843a0f08f4804eaa271333a23f376b
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Sep 18 12:40:10 2024 -0400

    Add helper to build Attributes.
---
 .../saml2/testing/SAML2ActionTestingSupport.java   | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/opensaml-testing/src/main/java/org/opensaml/saml/saml2/testing/SAML2ActionTestingSupport.java b/opensaml-testing/src/main/java/org/opensaml/saml/saml2/testing/SAML2ActionTestingSupport.java
index cea05723c..4847072fb 100644
--- a/opensaml-testing/src/main/java/org/opensaml/saml/saml2/testing/SAML2ActionTestingSupport.java
+++ b/opensaml-testing/src/main/java/org/opensaml/saml/saml2/testing/SAML2ActionTestingSupport.java
@@ -15,6 +15,7 @@
 package org.opensaml.saml.saml2.testing;
 
 import java.time.Instant;
+import java.util.Collection;
 import java.util.Set;
 
 import javax.annotation.Nonnull;
@@ -28,11 +29,13 @@ import org.opensaml.saml.saml2.core.Artifact;
 import org.opensaml.saml.saml2.core.ArtifactResolve;
 import org.opensaml.saml.saml2.core.ArtifactResponse;
 import org.opensaml.saml.saml2.core.AttributeStatement;
+import org.opensaml.saml.saml2.core.AttributeValue;
 import org.opensaml.saml.saml2.core.AuthnRequest;
 import org.opensaml.saml.saml2.core.AuthnStatement;
 import org.opensaml.saml.saml2.core.IDPEntry;
 import org.opensaml.saml.saml2.core.IDPList;
 import org.opensaml.saml.saml2.core.Assertion;
+import org.opensaml.saml.saml2.core.Attribute;
 import org.opensaml.saml.saml2.core.AttributeQuery;
 import org.opensaml.saml.saml2.core.Issuer;
 import org.opensaml.saml.saml2.core.LogoutRequest;
@@ -196,6 +199,37 @@ public class SAML2ActionTestingSupport {
 
         return statementBuilder.buildObject();
     }
+    
+    /**
+     * Builds an attribute and values.
+     * 
+     * @param name attribute name
+     * @param format name format
+     * @param values value collection
+     * 
+     * @return the constructed attribute
+     * 
+     * @since 5.2.0
+     */
+    @Nonnull public static Attribute buildAttribute(@Nonnull final String name, @Nonnull final String format,
+            @Nonnull final Collection<String> values) {
+        final SAMLObjectBuilder<Attribute> attributeBuilder = (SAMLObjectBuilder<Attribute>)
+                XMLObjectProviderRegistrySupport.getBuilderFactory().<Attribute>ensureBuilder(
+                        Attribute.DEFAULT_ELEMENT_NAME);
+        final Attribute attr = attributeBuilder.buildObject();
+
+        final SAMLObjectBuilder<AttributeValue> valueBuilder = (SAMLObjectBuilder<AttributeValue>)
+                XMLObjectProviderRegistrySupport.getBuilderFactory().<AttributeValue>ensureBuilder(
+                        Attribute.DEFAULT_ELEMENT_NAME);
+        
+        values.forEach(v -> {
+            final AttributeValue val = valueBuilder.buildObject();
+            val.setTextContent(v);
+            attr.getAttributeValues().add(val);
+        });
+        
+        return attr;
+    }
 
     /**
      * Builds a {@link Subject}. If a principal name is given a {@link NameID}, whose value is the given principal name,

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


More information about the commits mailing list