Package org.forgerock.am.cts.api.tokens
Class Token
java.lang.Object
org.forgerock.am.cts.api.tokens.Token
A simple domain value responsible for modelling a Core Token Service Token. This container is intended
to be generic and has little knowledge of the data it is storing.
The Token is backed by the CoreTokenField enumeration which contains the known fields that can be
written to. Every value being stored must be mapped to one of these CoreTokenFields.
There are some read only fields which can only be set during initialisation of the Token.
The Token models the data stored in two ways. Firstly the primary fields of the Token are accessible
via getters and setters. All other fields are accessed in a more generic way.
-
Constructor Summary
ConstructorDescriptionCreate an instance of the Token.Copy constructor will create a shallow-copy of the provided Token. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clearAttribute
(CoreTokenField field) Clear a set attribute.copyWithEtag
(ETag etag) Make a shallow copy of this token and add the given etag.<T> T
getAttribute
(CoreTokenField field) Accessor for the CoreTokenField attributes.The Token supports being accessed in a generic way allowing a caller to iterate over all fields that are assigned in this token.byte[]
getBlob()
A binary representation of the Token being stored can be placed in the Token.getETag()
A read only copy of the backing CTS implementation ETag.<T> Set<T>
getMultiAttribute
(CoreTokenField field) Accessor for the multi-value CoreTokenField attributes.getType()
static boolean
isFieldReadOnly
(CoreTokenField field) Trying to change a read-only field will trigger a runtime exception.<T> void
setAttribute
(CoreTokenField field, T value) Mutator for the non-primary fields of the Token.void
setBlob
(byte[] data) void
setExpiryTimestamp
(Calendar expiryDate) <T> void
setMultiAttribute
(CoreTokenField field, T value) Mutator for the fields of the Token.void
Converts thisToken
into aPartialToken
containing all of the populated fields.toString()
Returns a formatted version of the Token which is intended to be human readable.
-
Constructor Details
-
Token
Create an instance of the Token.- Parameters:
tokenId
- Required field which cannot be null.type
- Required to define the type of Token.
-
Token
Copy constructor will create a shallow-copy of the provided Token.- Parameters:
copy
- Non null Token to copy.
-
Token
Copy constructor which creates a shallow-copy of the providedToken
and in addition, assigns the knownETag
.- Parameters:
copy
- Non null token to copy.etag
- Non null ETag to assign as a read-only field on this Token.
-
-
Method Details
-
copyWithEtag
Make a shallow copy of this token and add the given etag.- Parameters:
etag
- the etag to add to the token- Returns:
- A
Token
-
getTokenId
- Returns:
- The unique id for this Token.
-
getType
- Returns:
- The TokenType of the Token.
-
getUserId
- Returns:
- The unique id for the user.
-
setUserId
- Parameters:
userId
- The unique id for the user.
-
getExpiryTimestamp
- Returns:
- The timestamp (with timezone information) when the Token is due to expire.
-
setExpiryTimestamp
- Parameters:
expiryDate
- Assign the timestamp of when the Token will expire.
-
getBlob
public byte[] getBlob()A binary representation of the Token being stored can be placed in the Token. This ensures that attributes that are not modelled at the Token level can still be persisted.- Returns:
- The serialised binary object for this Token.
-
setBlob
public void setBlob(byte[] data) - Parameters:
data
- Assign the binary data that represents the object being stored in the Token.
-
getAttributeNames
The Token supports being accessed in a generic way allowing a caller to iterate over all fields that are assigned in this token.- Returns:
- A non null, non modifiable list of the CoreTokenField fields currently assigned.
-
getAttribute
Accessor for the CoreTokenField attributes.- Type Parameters:
T
- The type of the value stored. Note: this is not enforced and the caller is responsible for determining the correct type to request. SeeCoreTokenFieldTypes
for more details.- Parameters:
field
- The CoreTokenField to request the value for.- Returns:
- The value assigned which may be null.
-
getMultiAttribute
Accessor for the multi-value CoreTokenField attributes.- Type Parameters:
T
- The type of the value stored in the Set. Note: this is not enforced and the caller is responsible for determining the correct type to request. SeeCoreTokenFieldTypes
for more details.- Parameters:
field
- The CoreTokenField to request the value for.- Returns:
- A possible empty, non null Set containing the values assigned to the multi-value attribute.
-
setMultiAttribute
Mutator for the fields of the Token.- Type Parameters:
T
- The type of the value stored in the Set. SeeCoreTokenFieldTypes
for more details.- Parameters:
field
- The CoreTokenField field to store the value against.value
- The possibly null value to store in this Token.
-
setAttribute
Mutator for the non-primary fields of the Token.- Type Parameters:
T
- The type of the value stored. SeeCoreTokenFieldTypes
for more details.- Parameters:
field
- The CoreTokenField field to store the value against.value
- The possibly null value to store in this Token.
-
clearAttribute
Clear a set attribute. Regardless of whether the attribute was set, it will be cleared as a result of this call.- Parameters:
field
- Non null field to clear.
-
isFieldReadOnly
Trying to change a read-only field will trigger a runtime exception.- Parameters:
field
- The CoreTokenField to check.- Returns:
- True if the field is read only, and cannot be changed once assigned.
-
toString
Returns a formatted version of the Token which is intended to be human readable. Some of the field values have been formatted to ensure that their contents are more meaningful. Note: This is not a machine readable/parsable format. This function is only intended for debugging use only as its conversion logic will not be performant. -
toPartialToken
Converts thisToken
into aPartialToken
containing all of the populated fields.- Returns:
- A
PartialToken
. - Since:
- 14.0.0
-
getETag
A read only copy of the backing CTS implementation ETag.Requests to the
CTSPersistentStore
which include theCTSOptions.ETAG_READ_OPTION
option should populate this Token with an ETag.This concurrency check can then be included in subsequent modify requests to verify that the Token stored in the backing implementation has not been modified by another caller in the mean time.
Note: The value of this field (
getETag()
) is not used by the backing CTS implementation, but rather the value passed in using theOptions
.Note: This feature may not be available or not configured in the backing implementation of the CTS.
- Returns:
- An
Optional
which if present indicates that an ETag was received for this Token from the backing CTS implementation. - See Also:
-