Class AttributeUtils
java.lang.Object
se.swedenconnect.opensaml.eidas.ext.attributes.AttributeUtils
Utility methods for handling attributes and attribute values.
- Author:
- Martin Lindström
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends org.opensaml.core.xml.XMLObject>
voidaddAttributeValue
(org.opensaml.saml.saml2.core.Attribute attribute, T value) Utility method that adds an XML object as a value to anAttribute
.static org.opensaml.saml.saml2.core.Attribute
createAttribute
(String name, String friendlyName) Creates anAttribute
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 anAttribute
given its name, friendly name and name format.static <T extends org.opensaml.core.xml.XMLObject>
TcreateAttributeValueObject
(Class<T> clazz) Creates anAttributeValue
object of the given class.static <T extends org.opensaml.core.xml.XMLObject>
TcreateAttributeValueObject
(QName schemaType, Class<T> clazz) Creates anAttributeValue
object of the given class and schema type.
-
Method Details
-
createAttribute
public static org.opensaml.saml.saml2.core.Attribute createAttribute(String name, String friendlyName, String nameFormat) Utility method that creates anAttribute
given its name, friendly name and name format.- Parameters:
name
- the attribute namefriendlyName
- the attribute friendly name (may benull
)nameFormat
- the name format- Returns:
- an
Attribute
object
-
createAttribute
public static org.opensaml.saml.saml2.core.Attribute createAttribute(String name, String friendlyName) Creates anAttribute
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 namefriendlyName
- the attribute friendly name (may benull
)- Returns:
- an
Attribute
object - See Also:
-
createAttributeValueObject
public static <T extends org.opensaml.core.xml.XMLObject> T createAttributeValueObject(Class<T> clazz) Creates anAttributeValue
object of the given class. The type of the attribute value will be the field that is declared asTYPE_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 anAttributeValue
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 anAttribute
.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 updatevalue
- the value to add
-