Class Token
- java.lang.Object
-
- org.forgerock.openam.cts.api.tokens.Token
-
public class Token extends Object
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.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearAttribute(CoreTokenField field)Clear a set attribute.<T> TgetAttribute(CoreTokenField field)Accessor for the CoreTokenField attributes.Collection<CoreTokenField>getAttributeNames()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.CalendargetExpiryTimestamp()<T> Set<T>getMultiAttribute(CoreTokenField field)Accessor for the multi-value CoreTokenField attributes.StringgetTokenId()TokenTypegetType()StringgetUserId()static booleanisFieldReadOnly(CoreTokenField field)Trying to change a read-only field will trigger a runtime exception.<T> voidsetAttribute(CoreTokenField field, T value)Mutator for the non-primary fields of the Token.voidsetBlob(byte[] data)voidsetExpiryTimestamp(Calendar expiryDate)<T> voidsetMultiAttribute(CoreTokenField field, T value)Mutator for the fields of the Token.voidsetUserId(String userId)PartialTokentoPartialToken()Converts thisTokeninto aPartialTokencontaining all of the populated fields.StringtoString()Returns a formatted version of the Token which is intended to be human readable.
-
-
-
Constructor Detail
-
Token
public Token(String tokenId, TokenType type)
Create an instance of the Token.- Parameters:
tokenId- Required field which cannot be null.type- Required to define the type of Token.
-
Token
public Token(Token copy)
Copy constructor will create a shallow-copy of the provided Token.- Parameters:
copy- Non null Token to copy.
-
-
Method Detail
-
getTokenId
public String getTokenId()
- Returns:
- The unique id for this Token.
-
getType
public TokenType getType()
- Returns:
- The TokenType of the Token.
-
getUserId
public String getUserId()
- Returns:
- The unique id for the user.
-
setUserId
public void setUserId(String userId)
- Parameters:
userId- The unique id for the user.
-
getExpiryTimestamp
public Calendar getExpiryTimestamp()
- Returns:
- The timestamp (with timezone information) when the Token is due to expire.
-
setExpiryTimestamp
public void setExpiryTimestamp(Calendar expiryDate)
- 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 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
public Collection<CoreTokenField> 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
public <T> T getAttribute(CoreTokenField field)
Accessor for the CoreTokenField attributes.- Parameters:
field- The CoreTokenField to request the value for.- Returns:
- The value assigned which may be null.
-
getMultiAttribute
public <T> Set<T> getMultiAttribute(CoreTokenField field)
Accessor for the multi-value CoreTokenField attributes.- Parameters:
field- The CoreTokenField to request the value for.- Returns:
- The value assigned which may be null.
-
setMultiAttribute
public <T> void setMultiAttribute(CoreTokenField field, T value)
Mutator for the fields of the Token.- Parameters:
field- The CoreTokenField field to store the value against.value- The possibly null value to store in this Token.
-
setAttribute
public <T> void setAttribute(CoreTokenField field, T value)
Mutator for the non-primary fields of the Token.- Parameters:
field- The CoreTokenField field to store the value against.value- The possibly null value to store in this Token.
-
clearAttribute
public void clearAttribute(CoreTokenField field)
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
public static boolean isFieldReadOnly(CoreTokenField field)
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
public String 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
public PartialToken toPartialToken()
Converts thisTokeninto aPartialTokencontaining all of the populated fields.- Returns:
- A
PartialToken. - Since:
- 14.0.0
-
-