Class AttributeUtils

java.lang.Object
se.swedenconnect.opensaml.eidas.ext.attributes.AttributeUtils

public class AttributeUtils extends Object
Utility methods for handling attributes and attribute values.
Author:
Martin Lindström
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T extends org.opensaml.core.xml.XMLObject>
    void
    addAttributeValue(org.opensaml.saml.saml2.core.Attribute attribute, T value)
    Utility method that adds an XML object as a value to an Attribute.
    static org.opensaml.saml.saml2.core.Attribute
    createAttribute(String name, String friendlyName)
    Creates an Attribute with the given name (and friendly name) and with a name format of "urn:oasis:names:tc:SAML:2.0:attrname-format:uri".
    static org.opensaml.saml.saml2.core.Attribute
    createAttribute(String name, String friendlyName, String nameFormat)
    Utility method that creates an Attribute given its name, friendly name and name format.
    static <T extends org.opensaml.core.xml.XMLObject>
    T
    Creates an AttributeValue object of the given class.
    static <T extends org.opensaml.core.xml.XMLObject>
    T
    createAttributeValueObject(QName schemaType, Class<T> clazz)
    Creates an AttributeValue object of the given class and schema type.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • createAttribute

      public static org.opensaml.saml.saml2.core.Attribute createAttribute(String name, String friendlyName, String nameFormat)
      Utility method that creates an Attribute given its name, friendly name and name format.
      Parameters:
      name - the attribute name
      friendlyName - the attribute friendly name (may be null)
      nameFormat - the name format
      Returns:
      an Attribute object
    • createAttribute

      public static org.opensaml.saml.saml2.core.Attribute createAttribute(String name, String friendlyName)
      Creates an Attribute with the given name (and friendly name) and with a name format of "urn:oasis:names:tc:SAML:2.0:attrname-format:uri".
      Parameters:
      name - the attribute name
      friendlyName - the attribute friendly name (may be null)
      Returns:
      an Attribute object
      See Also:
    • createAttributeValueObject

      public static <T extends org.opensaml.core.xml.XMLObject> T createAttributeValueObject(Class<T> clazz)
      Creates an AttributeValue object of the given class. The type of the attribute value will be the field that is declared as TYPE_NAME of the given class.

      After the object has been constructed, its setter methods should be called to setup the value object before adding it to the attribute itself.

      Type Parameters:
      T - the type
      Parameters:
      clazz - the type of attribute value
      Returns:
      the attribute value
      See Also:
    • createAttributeValueObject

      public static <T extends org.opensaml.core.xml.XMLObject> T createAttributeValueObject(QName schemaType, Class<T> clazz)
      Creates an AttributeValue object of the given class and schema type.

      After the object has been constructed, its setter methods should be called to setup the value object before adding it to the attribute itself.

      Type Parameters:
      T - the type
      Parameters:
      schemaType - the schema type that should be assigned to the attribute value, i.e., xsi:type="eidas:CurrentFamilyNameType"
      clazz - the type of the attribute value
      Returns:
      the attribute value
      See Also:
    • addAttributeValue

      public static <T extends org.opensaml.core.xml.XMLObject> void addAttributeValue(org.opensaml.saml.saml2.core.Attribute attribute, T value)
      Utility method that adds an XML object as a value to an Attribute.

      Example:

      
       Attribute attr =
           AttributeUtils.createAttribute("http://eidas.europa.eu/attributes/naturalperson/CurrentFamilyName",
               "FamilyName");
       CurrentFamilyNameType value = AttributeUtils.createAttributeValueObject(CurrentFamilyNameType.class);
       value.setValue("Lindström");
       AttributeUtils.addAttributeValue(attr, value);
       
       
      Type Parameters:
      T - the type
      Parameters:
      attribute - the attribute to update
      value - the value to add