Class Attributes

Object
se.curity.identityserver.sdk.attribute.Attributes
All Implemented Interfaces:
Iterable<Attribute>, AttributeContainer<Attributes>, SerializableAsMap
Direct Known Subclasses:
AttributeAdditions, AttributeReplacements, AuthenticationAttributes, AuthorizationAttributes, ConsentAttributes, ConsentorResultAttributes, ResourceAttributes, TokenAttributes

public class Attributes extends Object implements AttributeContainer<Attributes>, SerializableAsMap
Collection of Attribute instances that can be efficiently located by name.
See Also:
  • Constructor Details

    • Attributes

      protected Attributes(Attributes attributes)
  • Method Details

    • empty

      public static Attributes empty()
    • of

      public static Attributes of(String name, Comparable<?> value)
    • of

      public static Attributes of(String name1, Comparable<?> value1, String name2, Comparable<?> value2)
    • of

      public static Attributes of(String name1, Comparable<?> value1, String name2, Comparable<?> value2, String name3, Comparable<?> value3)
    • of

      public static Attributes of(String name1, Comparable<?> value1, String name2, Comparable<?> value2, String name3, Comparable<?> value3, String name4, Comparable<?> value4)
    • of

      public static Attributes of(String name1, Comparable<?> value1, String name2, Comparable<?> value2, String name3, Comparable<?> value3, String name4, Comparable<?> value4, String name5, Comparable<?> value5)
    • of

      public static Attributes of(Attribute... attributes)
    • of

      public static Attributes of(Iterable<Attribute> attributes)
    • fromMap

      public static Attributes fromMap(Map<String,?> map)
    • fromMap

      public static Attributes fromMap(Map<String,?> map, String nameFormat)
      Create an Attributes object from a map of values.
      Parameters:
      map - the names of the attributes to be added and their associated values
      nameFormat - the format of the name attribute
      Returns:
      the new Attributes object
      Since:
      2.1.0
    • toMap

      public Map<String,Object> toMap()
      Returns:
      a Map from Strings to primitive values, Maps and Lists.
    • asMap

      public Map<String,Object> asMap()
      Specified by:
      asMap in interface SerializableAsMap
      Returns:
      representation of this Object as a Map containing only Java primitive types, plus instances of Collection, String and Map.

      It should be possible to fully re-construct this Object from a Map obtained by calling this method.

      Unfortunately, in Java it is quite hard to make the type system enforce this condition, so implementators must be especially careful about this.

    • append

      public Attributes append(Attribute attribute)
      Description copied from interface: AttributeContainer
      Appends the given attribute to a copy of this, returning the result.
      Specified by:
      append in interface AttributeContainer<Attributes>
      Parameters:
      attribute - to append
      Returns:
      copy of this with the provided attribute appended to it
    • append

      public Attributes append(Iterable<Attribute> attributes)
      Description copied from interface: AttributeContainer
      Appends the given attribute to a copy of this, returning the result.
      Specified by:
      append in interface AttributeContainer<Attributes>
      Parameters:
      attributes - to append
      Returns:
      copy of this with the provided attribute appended to it
    • get

      @Nullable public @Nullable Attribute get(String name)
      Description copied from interface: AttributeContainer
      Get the attribute with the given name if it exists, or null otherwise. If multiple attributes with the same name exist (e.g. with different authorities), then one of those attributes will be returned.
      Specified by:
      get in interface AttributeContainer<Attributes>
      Parameters:
      name - of attribute
      Returns:
      one of the attributes with the given name if any, or null otherwise.
    • getAll

      public Collection<Attribute> getAll(String name)
      Description copied from interface: AttributeContainer
      Get a collection containing all attributes with the given name and distinct authorities.
      Specified by:
      getAll in interface AttributeContainer<Attributes>
      Parameters:
      name - of attribute
      Returns:
      an unmodifiable collection with all the contained attributes with the given name.
    • getValuesOfType

      public <T extends Comparable<T>> List<T> getValuesOfType(Class<T> type, String name)
      Lenient method to get all Attribute values of a certain type.
      Type Parameters:
      T - type of attribute values
      Parameters:
      type - of attribute values
      name - name of the attribute
      Returns:
      all attribute values of the given type, or an empty list if the attribute does not have any values or does not exist.
    • getMandatoryAttribute

      public Attribute getMandatoryAttribute(String name)
      Convenience method to get a mandatory attribute. Throws exception if not found
      Parameters:
      name - name
      Returns:
      attribute
      Throws:
      NoSuchElementException - when attribute is not found
    • getMandatoryValue

      public <T extends Comparable<?>> T getMandatoryValue(String name, Class<T> type)
      Convenience method to get the value of a mandatory attribute.
      Type Parameters:
      T - type of the value
      Parameters:
      name - name
      type - type
      Returns:
      attribute
      Throws:
      NoSuchElementException - Throws exception if the attibute is not found, or if the attribute does not have a value of the type
    • contains

      public boolean contains(String name)
      Description copied from interface: AttributeContainer
      A flag indicating that this container has an Attribute with the given name.
      Specified by:
      contains in interface AttributeContainer<Attributes>
      Parameters:
      name - of the attribute
      Returns:
      true if an Attribute with the given name exists, false otherwise. Notice that even if an Attribute exists, it may have no value. The safe way to get a single value from an Attribute you are not sure exists is as follows:
       
      
       Attributes attributes = ... ;
       if (attributes.contains("name") {
         Attribute attribute = attributes.get("name");
         if (attribute.hasValue()) {
           return attribute.getValue();
         } else {
           // no value is present
         }
       }
       
       
      To avoid querying the Map twice, call get() directly and check that the result is not null.
    • removeAttributes

      public Attributes removeAttributes(Set<String> exclusionNames)
      Description copied from interface: AttributeContainer
      Remove all top-level attributes whose names are in the given Set.
      Specified by:
      removeAttributes in interface AttributeContainer<Attributes>
      Parameters:
      exclusionNames - names of attributes to exclude.
      Returns:
      this Attributes without the excluded top-level attributes
    • retainAttributes

      public Attributes retainAttributes(Set<String> inclusionNames)
      Description copied from interface: AttributeContainer
      Retain all attributes whose names are in the given Set. All attributes that are not named in the set are removed.
      Specified by:
      retainAttributes in interface AttributeContainer<Attributes>
      Parameters:
      inclusionNames - names of attributes to retain.
      Returns:
      this Attributes with only the included attributes
    • iterator

      public Iterator<Attribute> iterator()
      Specified by:
      iterator in interface Iterable<Attribute>
    • stream

      public Stream<Attribute> stream()
      Description copied from interface: AttributeContainer
      Returns a stream of the Attributes in the container.
      Specified by:
      stream in interface AttributeContainer<Attributes>
      Returns:
      a Stream of the Attributes contained in the container.
    • with

      public Attributes with(Iterable<Attribute> attributes)
      Description copied from interface: AttributeContainer
      Add the given attributes if not present, or replace the attribute if it already exists. Note that two attributes with the same name and different authorities are considered distinct.
      Specified by:
      with in interface AttributeContainer<Attributes>
      Parameters:
      attributes - attribute to add or to override
      Returns:
      a copy of this which contains the given Attributes
    • with

      public Attributes with(Attribute attribute)
      Description copied from interface: AttributeContainer
      Add the given attribute if not present, or replace the attribute if it already exists. Note that two attributes with the same name and different authorities are considered distinct.
      Specified by:
      with in interface AttributeContainer<Attributes>
      Parameters:
      attribute - attribute to add or to override
      Returns:
      a copy of this which contains the given Attribute
    • equals

      public boolean equals(@Nullable 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
    • size

      public int size()
    • isEmpty

      public boolean isEmpty()
    • keys

      public Set<String> keys()