OpenSAML 2.0 and x500 Attribute

Campbell, Shawn scampbell at malone.edu
Mon Nov 18 16:56:53 EST 2013


Scott,

Skipping it is a good suggestion.  I ended up figuring it out.

1.  Add the name space for X500
            t_Attribute.getNamespaceManager().getNamespaces().add(new Namespace(SAMLConstants.SAML20X500_NS, SAMLConstants.SAML20X500_PREFIX));

2.  Use the getUnknownAttributes method to add the X500:Encoding attribute.

            t_Attribute.getUnknownAttributes().put(new QName(SAMLConstants.SAML20X500_NS, "Encoding", SAMLConstants.SAML20X500_PREFIX), "LDAP");


Below is the complete code.

            // AttributeValue
            XMLObjectBuilder t_AttributeValueBuilder = (XMLObjectBuilder)t_XMLObjectBuilderFactory.getBuilder(XSString.TYPE_NAME);
            XSString t_AttributeValue = (XSString)t_AttributeValueBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
            t_AttributeValue.setValue(p_Mail);

            // Attribute
            AttributeBuilder t_AttributeBuilder = (AttributeBuilder)t_XMLObjectBuilderFactory.getBuilder(Attribute.DEFAULT_ELEMENT_NAME);
            Attribute t_Attribute = t_AttributeBuilder.buildObject();
            t_Attribute.getNamespaceManager().getNamespaces().add(new Namespace(SAMLConstants.SAML20X500_NS, SAMLConstants.SAML20X500_PREFIX));
            t_Attribute.setFriendlyName("mail");
            t_Attribute.setName("urn:oid:0.9.2342.19200300.100.1.3"); // RFC 4524
            t_Attribute.setNameFormat("urn:oasis:names:tc:SAML:2.0:attrname-format:uri");
            t_Attribute.getAttributeValues().add(t_AttributeValue);
            t_Attribute.getUnknownAttributes().put(new QName(SAMLConstants.SAML20X500_NS, "Encoding", SAMLConstants.SAML20X500_PREFIX), "LDAP");
            AttributeStatementBuilder t_AttributeStatementBuilder = (AttributeStatementBuilder)t_XMLObjectBuilderFactory.getBuilder(AttributeStatement.DEFAULT_ELEMENT_NAME);
            AttributeStatement t_AttributeStatement = t_AttributeStatementBuilder.buildObject();
            t_AttributeStatement.getAttributes().add(t_Attribute);
            t_Assertion.getAttributeStatements().add(t_AttributeStatement);

When I look in code forums, many times people find the solution and never post it.  I wanted to be a good forum citizen and post my solution.

Shawn Campbell
Systems Analyst
Information Technology Offices
Phone:  330.471.8501
Fax:  330.471.8302
E-mail:  scampbell at malone.edu



Malone University
2600 Cleveland Avenue NW
Canton, Ohio 44709



-----Original Message-----
From: dev-bounces at shibboleth.net [mailto:dev-bounces at shibboleth.net] On Behalf Of Cantor, Scott
Sent: Monday, November 18, 2013 4:26 PM
To: Shib Dev
Subject: Re: OpenSAML 2.0 and x500 Attribute

On 11/18/13, 4:18 PM, "Campbell, Shawn" <scampbell at malone.edu> wrote:

>I am trying to create a AttributeStatement containing an Attribute from 
>an LDAP server source using the OpenSAML 2.0 libraries.  Below is an 
>example of what I  am trying to create:

Nobody follows the letter of the profile and the Encoding attribute is never seen in the wild. Just skip it.

>I am not sure how to add the following XML attributes to the Attribute
>element:
> 
>xmlns:x500="urn:oasis:names:tc:SAML:2.0:profiles:attribute:X500"
> 
>x500:Encoding="LDAP"
> 
>Does anyone know how to handle this in the OpenSAML 2.0 library?

One is a namespace declaration, not an attribute. The Encoding attribute would be added using the AttributeExtensibleXMLObject super interface.

But it's moot, just ignore it.

-- Scott


--
To unsubscribe from this list send an email to dev-unsubscribe at shibboleth.net


More information about the dev mailing list