Class Attribute

Object
se.curity.identityserver.sdk.attribute.Attribute
All Implemented Interfaces:
Iterable<AttributeValue>, AttributeOrAttributeValue<Attribute>
Direct Known Subclasses:
AuthenticationSessionAttribute, ComplexAttribute

public class Attribute extends Object implements AttributeOrAttributeValue<Attribute>, Iterable<AttributeValue>
An Attribute is a collection of AttributeValues, together with a name and, optionally, an authority.

For the common case where an Attribute has a single value, the methods getValue() and getAttributeValue() are provided (it is advisable to check first if a value is present using the collection methods).

Type-safe getters (getValuesOfType(Class) and getValueOfType(Class)) may be used when the type of the attribute is known.

  • Field Details

  • Constructor Details

  • Method Details

    • ofFlag

      public static Attribute ofFlag(String attributePath)
      Create an attribute flag at the given path with the default authority.

      Note: a flag is represented as Attribute with an empty-list value.

      Parameters:
      attributePath - full path of the attribute. Notice that the path separator is the dot ('.'), so a path such as `name.familyName` with value 'joe' means, in JSON format: {"name": {"familyName": "joe"}}
      Returns:
      Attribute
    • ofFlag

      public static Attribute ofFlag(AttributeName name)
      Create an attribute flag with the given name and the default authority.

      Note: a flag is represented as Attribute with an empty-list value.

      Parameters:
      name - of the flag
      Returns:
      Attribute
    • of

      public static Attribute of(String attributePath, Comparable value)
      Create an attribute at the given path with the default authority.
      Parameters:
      attributePath - full path of the attribute. Notice that the path separator is the dot ('.'), so a path such as `name.familyName` with value 'joe' means, in JSON format: {"name": {"familyName": "joe"}}
      value - value of the attribute
      Returns:
      Attribute
    • of

      public static Attribute of(AttributeName name, Comparable value)
      Create an attribute with the given name and the default authority.
      Parameters:
      name - of the attribute
      value - value of the attribute
      Returns:
      Attribute
    • of

      public static Attribute of(String attributePath, Comparable value, String authority)
      Create an attribute at the given path.
      Parameters:
      attributePath - full path of the attribute. Notice that the path separator is the dot ('.'), so a path such as `name.familyName` with value 'joe' means, in JSON format: {"name": {"familyName": "joe"}}
      value - value of the attribute
      authority - authority
      Returns:
      Attribute
    • of

      public static Attribute of(AttributeName name, Comparable value, String authority)
      Create an attribute with the given name.
      Parameters:
      name - of the attribute
      value - value of the attribute
      authority - authority
      Returns:
      Attribute
    • of

      public static Attribute of(String attributePath, Collection<?> values)
      Create an attribute at the given path with the default authority.
      Parameters:
      attributePath - full path of the attribute. Notice that the path separator is the dot ('.'), so a path such as `name.familyName` with value 'joe' means, in JSON format: {"name": {"familyName": "joe"}}
      values - values of the attribute
      Returns:
      Attribute
    • of

      public static Attribute of(AttributeName name, Collection<?> values)
      Create an attribute with the given name and the default authority.
      Parameters:
      name - of the attribute
      values - values of the attribute
      Returns:
      Attribute
    • of

      public static Attribute of(String attributePath, Collection<?> values, String authority)
      Create an attribute at the given path.
      Parameters:
      attributePath - full path of the attribute. Notice that the path separator is the dot ('.'), so a path such as `name.familyName` with value 'joe' means, in JSON format: {"name": {"familyName": "joe"}}
      values - values of the attribute
      authority - authority
      Returns:
      Attribute
    • of

      public static Attribute of(AttributeName name, Collection<?> values, String authority)
      Create an attribute with the given name.
      Parameters:
      name - of the attribute
      values - values of the attribute
      authority - authority
      Returns:
      Attribute
    • of

      public static Attribute of(String attributePath, AttributeValue value)
      Create an attribute at the given path with the default authority.
      Parameters:
      attributePath - full path of the attribute. Notice that the path separator is the dot ('.'), so a path such as `name.familyName` with value 'joe' means, in JSON format: {"name": {"familyName": "joe"}}
      value - value of the attribute
      Returns:
      Attribute
    • of

      public static Attribute of(AttributeName name, AttributeValue value)
      Create an attribute with the given name and the default authority.
      Parameters:
      name - of the attribute
      value - value of the attribute
      Returns:
      Attribute
    • of

      public static Attribute of(String attributePath, AttributeValue value, String authority)
      Create an attribute at the given path.
      Parameters:
      attributePath - full path of the attribute. Notice that the path separator is the dot ('.'), so a path such as `name.familyName` with value 'joe' means, in JSON format: {"name": {"familyName": "joe"}}
      value - value of the attribute
      authority - authority
      Returns:
      Attribute
    • of

      public static Attribute of(AttributeName name, AttributeValue value, String authority)
      Create an attribute with the given name.
      Parameters:
      name - of the attribute
      value - value of the attribute
      authority - authority
      Returns:
      Attribute
    • map

      Description copied from interface: AttributeOrAttributeValue
      Apply the provided transformation on each Attribute and AttributeValue in this attribute tree, recursively.
      Specified by:
      map in interface AttributeOrAttributeValue<Attribute>
      Parameters:
      parentPath - of the current attribute or value being transformed.
      transform - transformation function.
      Returns:
      the transformed attribute or value
    • getName

      public AttributeName getName()
    • getAuthority

      public String getAuthority()
    • getAttributeValue

      public AttributeValue getAttributeValue()
      Returns the attribute's value.
      Returns:
      the value of this attribute.
    • isMultiValued

      public boolean isMultiValued()
      A flag indicating whether or not the attribute has just one value or multiple.
      Returns:
      true if this Attribute is multi-valued, as opposed to single-valued.
    • hasValueOfType

      public @io.curity.java_to_ts_docs.annotations.TypescriptDocs("This method is meant to be used from Java only!") boolean hasValueOfType(Class<? extends Comparable> type)
      A flag indicating whether or not the attribute has a value of a certain type.
      Parameters:
      type - of a value
      Returns:
      true if this Attribute contains at least one value of the given type, false otherwise.
    • getValue

      @Nullable public @Nullable Object getValue()
      Retrieves just the attribute's value.
      Specified by:
      getValue in interface AttributeOrAttributeValue<Attribute>
      Returns:
      the value of this attribute.
    • getValueWithMetadata

      @Nullable public @Nullable Object getValueWithMetadata()
      Specified by:
      getValueWithMetadata in interface AttributeOrAttributeValue<Attribute>
      Returns:
      the value of this entity, including any metadata it might have.
    • getOptionalValueOfType

      @Nullable public <Type> Type getOptionalValueOfType(Class<Type> type)
      Returns an optional value of some type.
      Type Parameters:
      Type - type of the value
      Parameters:
      type - type of the value
      Returns:
      the single value of this attribute, or null if not found.
    • getValueOfType

      public <Type> Type getValueOfType(Class<Type> type)
      Returns a value of some type.
      Type Parameters:
      Type - type of the value
      Parameters:
      type - type of the value
      Returns:
      the single value of this attribute.
      Throws:
      NoSuchElementException - if this attribute's value has a different type
    • getValuesOfType

      public <Type extends Comparable> List<Type> getValuesOfType(Class<Type> type)
      Unwraps the values within the AttributeValues of this Attribute, returning all values that are intances of the given type in a Collection.
      Type Parameters:
      Type - type of the values
      Parameters:
      type - type of the values
      Returns:
      unwrapped values
    • stream

      public Stream<AttributeValue> stream()
    • iterator

      public Iterator<AttributeValue> iterator()
      Specified by:
      iterator in interface Iterable<AttributeValue>
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • withValue

      public Attribute withValue(AttributeValue value)
    • withValue

      public Attribute withValue(Comparable<?> value)
    • withName

      public Attribute withName(String name)
    • withName

      public Attribute withName(AttributeName name)
    • withAuthority

      public Attribute withAuthority(String authority)