Class TokenAttributes

Object
se.curity.identityserver.sdk.attribute.Attributes
se.curity.identityserver.sdk.data.tokens.TokenAttributes
All Implemented Interfaces:
Iterable<Attribute>, AttributeContainer<Attributes>, SerializableAsMap

public class TokenAttributes extends Attributes
A data token containing a number of attributes, always including the CREATED and EXPIRES attributes.

Plugins can create their own implementations of Attributes to map to/from TokenAttributes instances, and use a TokenIssuer such as NonceTokenIssuer to issue and retrieve such tokens.

For example, assuming a plugin has the following Attributes implementation class:

 class PluginAttributesExample extends Attributes
 {
   private final String _id;

   PluginAttributesExample(Attributes attributes)
   {
     super(attributes);
     _id = getMandatoryValue("id", String.class);
   }

   PluginAttributesExample(String id)
   {
     super(Attributes.of("id", id));
     _id = id;
   }

   public String getId()
   {
     return _id;
   }
 }
 
Then, it could easily embed it into an instance of TokenAttributes as follows:
 Instant now = Instant.now();
 Instant expires = now.plus(Duration.ofSeconds(120));
 TokenAttributes token = new TokenAttributes(expires, now, new PluginAttributesExample("1234567"));
 

And to convert a TokenAttributes back to a PluginAttributesExample instance:

 PluginAttributesExample pluginAttributesExample = new PluginAttributesExample(token.getExtraAttributes());
 
Since:
2.1.0
  • Field Details

  • Constructor Details

    • TokenAttributes

      protected TokenAttributes(Attributes attributes)
      Create a new token with the provided attributes.
      Parameters:
      attributes - the attributes of this token. Must contain at least the CREATED and EXPIRES attributes.
      Throws:
      NoSuchElementException - if a mandatory attribute is missing.
    • TokenAttributes

      public TokenAttributes(Instant expires)
      Create a new token using the current time as its CREATED attribute value, and the provided expires parameter as the EXPIRES attribute value.
      Parameters:
      expires - instant at which this token expires
    • TokenAttributes

      public TokenAttributes(Instant expires, Instant created)
      Create a token using the provided instants for the EXPIRES and CREATED attributes.
      Parameters:
      expires - instant at which this token expires
      created - instant when this token was created
    • TokenAttributes

      public TokenAttributes(Instant expires, Instant created, Attributes attributes)
      Create a token using the provided instants for the EXPIRES and CREATED attributes, as well as the provided extra attributes.
      Parameters:
      expires - instant at which this token expires
      created - instant when this token was created
      attributes - extra attributes of this token
  • Method Details

    • created

      public Instant created()
      Returns:
      the instant when this token was created.
    • expires

      public Instant expires()
      Returns:
      the instant when this token expires.
    • getExtraAttributes

      public Attributes getExtraAttributes()
      Get the extra attributes (i.e. non-mandatory) attributes of this token.

      Sub-types must override this method if they contain any mandatory attributes other than EXPIRES and CREATED.

      Returns:
      The extra attributes of this token (does not include EXPIRES and CREATED).