Class TokenAttributes
Object
se.curity.identityserver.sdk.attribute.Attributes
se.curity.identityserver.sdk.data.tokens.TokenAttributes
- All Implemented Interfaces:
Iterable<Attribute>,AttributeContainer<Attributes>,SerializableAsMap
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 Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionTokenAttributes(Instant expires) TokenAttributes(Instant expires, Instant created) TokenAttributes(Instant expires, Instant created, Attributes attributes) protectedTokenAttributes(Attributes attributes) Create a new token with the provided attributes. -
Method Summary
Methods inherited from class se.curity.identityserver.sdk.attribute.Attributes
append, append, asMap, contains, empty, equals, fromMap, fromMap, get, getAll, getMandatoryAttribute, getMandatoryValue, getValuesOfType, hashCode, isEmpty, iterator, keys, of, of, of, of, of, of, of, removeAttributes, retainAttributes, size, stream, toMap, toString, with, withMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface se.curity.identityserver.sdk.attribute.AttributeContainer
contains, getOptionalValue, getOptionalValue, removeAttribute, retainAttributeMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
CREATED
- See Also:
-
EXPIRES
- See Also:
-
-
Constructor Details
-
TokenAttributes
Create a new token with the provided attributes.- Parameters:
attributes- the attributes of this token. Must contain at least theCREATEDandEXPIRESattributes.- Throws:
NoSuchElementException- if a mandatory attribute is missing.
-
TokenAttributes
Create a new token using the current time as itsCREATEDattribute value, and the provided expires parameter as theEXPIRESattribute value.- Parameters:
expires- instant at which this token expires
-
TokenAttributes
- Parameters:
expires- instant at which this token expirescreated- instant when this token was created
-
TokenAttributes
Create a token using the provided instants for theEXPIRESandCREATEDattributes, as well as the provided extra attributes.- Parameters:
expires- instant at which this token expirescreated- instant when this token was createdattributes- extra attributes of this token
-
-
Method Details
-
created
- Returns:
- the instant when this token was created.
-
expires
- Returns:
- the instant when this token expires.
-
getExtraAttributes
-