Class AttributeBuilder

java.lang.Object
se.swedenconnect.opensaml.common.builder.AbstractSAMLObjectBuilder<org.opensaml.saml.saml2.core.Attribute>
se.swedenconnect.opensaml.saml2.attribute.AttributeBuilder
All Implemented Interfaces:
SAMLObjectBuilder<org.opensaml.saml.saml2.core.Attribute>

public class AttributeBuilder extends AbstractSAMLObjectBuilder<org.opensaml.saml.saml2.core.Attribute>
Implements the build pattern to create Attribute objects.
Author:
Martin Lindström (martin@idsec.se)
  • Field Details

    • DEFAULT_NAME_FORMAT

      public static final String DEFAULT_NAME_FORMAT
      The default name format for the attribute being built.
      See Also:
  • Constructor Details

    • AttributeBuilder

      public AttributeBuilder(String name)
      Constructor setting the attribute name.
      Parameters:
      name - the attribute name
    • AttributeBuilder

      public AttributeBuilder(org.opensaml.saml.saml2.core.Attribute template) throws org.opensaml.core.xml.io.MarshallingException, org.opensaml.core.xml.io.UnmarshallingException
      Constructor setting up the builder given an attribute template.
      Parameters:
      template - the attribute template
      Throws:
      org.opensaml.core.xml.io.UnmarshallingException - for unmarshalling errors
      org.opensaml.core.xml.io.MarshallingException - for marshalling errors
      See Also:
    • AttributeBuilder

      public AttributeBuilder(InputStream resource) throws net.shibboleth.shared.xml.XMLParserException, org.opensaml.core.xml.io.UnmarshallingException
      Constructor setting up the builder with a template attribute that is read from an input stream.
      Parameters:
      resource - the attribute template
      Throws:
      org.opensaml.core.xml.io.UnmarshallingException - for unmarshalling errors
      net.shibboleth.shared.xml.XMLParserException - for XML parsing errors
      See Also:
  • Method Details

    • builder

      public static AttributeBuilder builder(String name)
      Static utility method that creates a default AttributeBuilder.
      Parameters:
      name - the attribute name
      Returns:
      an AttributeBuilder instance.
      See Also:
    • builder

      public static AttributeBuilder builder(org.opensaml.saml.saml2.core.Attribute attribute) throws org.opensaml.core.xml.io.MarshallingException, org.opensaml.core.xml.io.UnmarshallingException
      Static utility method that creates a AttributeBuilder given a template attribute.
      Parameters:
      attribute - the attribute template
      Returns:
      an attribute builder
      Throws:
      org.opensaml.core.xml.io.UnmarshallingException - for unmarshalling errors
      org.opensaml.core.xml.io.MarshallingException - for marshalling errors
    • builder

      public static AttributeBuilder builder(InputStream resource) throws net.shibboleth.shared.xml.XMLParserException, org.opensaml.core.xml.io.UnmarshallingException
      Static utility method that creates a AttributeBuilder given a template attribute read from an input stream.
      Parameters:
      resource - the attribute template
      Returns:
      an attribute builder
      Throws:
      org.opensaml.core.xml.io.UnmarshallingException - for unmarshalling errors
      net.shibboleth.shared.xml.XMLParserException - for XML parsing errors
    • build

      public org.opensaml.saml.saml2.core.Attribute build()
      Returns the Attribute object that has been built. If the NameFormat attribute has not been assigned, the method will inject the default value ("urn:oasis:names:tc:SAML:2.0:attrname-format:uri").
      Specified by:
      build in interface SAMLObjectBuilder<org.opensaml.saml.saml2.core.Attribute>
      Overrides:
      build in class AbstractSAMLObjectBuilder<org.opensaml.saml.saml2.core.Attribute>
      Returns:
      the built object
    • name

      public AttributeBuilder name(String name)
      Assigns the attribute name.
      Parameters:
      name - the attribute name
      Returns:
      the builder
    • friendlyName

      public AttributeBuilder friendlyName(String friendlyName)
      Assigns the attribute friendly name.
      Parameters:
      friendlyName - the friendly name
      Returns:
      the builder
    • nameFormat

      public AttributeBuilder nameFormat(String nameFormat)
      Assigns the attribute name format.
      Parameters:
      nameFormat - the name format URI
      Returns:
      the builder
    • value

      public AttributeBuilder value(String... values)
      Assigns one (or more) attribute string values.

      Note: if null is passed as a parameter, any previous attribute values are cleared.

      Parameters:
      values - the string value(s) to add
      Returns:
      the builder
    • value

      public AttributeBuilder value(List<String> values)
      Parameters:
      values - the string value(s) to add
      Returns:
      the builder
      See Also:
    • value

      public <T extends org.opensaml.core.xml.XMLObject> AttributeBuilder value(T value)
      Assigns an attribute value.
      Type Parameters:
      T - the value type
      Parameters:
      value - the value to add
      Returns:
      the builder
    • createValueObject

      public static <T extends org.opensaml.core.xml.XMLObject> T createValueObject(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.

      Note: For attribute having string values, there is no need to explictly create an attribute value. Instead the value(String...) method may be used directly.

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

      public static <T extends org.opensaml.core.xml.XMLObject> T createValueObject(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.

      Note: For attribute having string values, there is no need to explictly create an attribute value. Instead the value(String...) method may be used directly.

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

      protected Class<org.opensaml.saml.saml2.core.Attribute> getObjectType()
      Returns the object type.
      Specified by:
      getObjectType in class AbstractSAMLObjectBuilder<org.opensaml.saml.saml2.core.Attribute>
      Returns:
      the object type