- java.lang.Object
- 
- aeonics.entity.security.Token
 
- 
- All Implemented Interfaces:
- Exportable
 
 public class Token extends java.lang.Object implements Exportable Tokens play a role in the definition of theSecurity. They can be used to represent a time-based access for a list ofPolicyscopes.Entities should only use tokens to perform security checks in order to identify whether or not a user is allowed to perform an action. This ensures that the current access (i.e. scope) is effectively granted. 
- 
- 
Field SummaryFields Modifier and Type Field Description protected longepochThe start of validity point in timeprotected java.util.Set<java.lang.String>scopesList of scopes of this tokenprotected java.lang.StringuserThe linked user idprotected longvalidityThe validity fromepochin ms.protected java.lang.Stringvaluethe public cryptographically secure and universally unique token value
 - 
Constructor SummaryConstructors Constructor Description Token(Data data)Restores a token from itsexport()form.Token(User.Type user, long validity, long epoch, java.lang.String... scope)Creates a new token.Token(User.Type user, long validity, long epoch, java.lang.String value, java.lang.String... scope)Creates a new token.Token(User.Type user, long validity, java.lang.String... scope)Creates a new token.Token(User.Type user, java.lang.String... scope)Creates a new token.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddScope(java.lang.String scope)Adds the specified scope to this tokenDataexport()Renders this class instance to a simple data structure for rendering client-side.booleaninScope(java.lang.String scope)Returns whether or not this token applies to the specified scopebooleanisFor(java.lang.String user)Returns true if theUserlinked to this token matches the provided identifier.booleanisValid()Returns whether or not this token is valid at the current moment in timelongnotAfter()Returns the end of validity of this token as a timestamp in mslongnotBefore()Returns the start of validity of this token as a timestamp in msvoidremoveScope(java.lang.String scope)Removes the specified scope from this tokenvoidreset()Resets the start of validity of this token to nowUser.Typeuser()Returns theUserlinked to this token.java.lang.Stringvalue()Returns the public cryptographically secure and universally unique value of this token.
 
- 
- 
- 
Field Detail- 
valueprotected java.lang.String value the public cryptographically secure and universally unique token value
 - 
userprotected java.lang.String user The linked user id
 - 
epochprotected long epoch The start of validity point in time
 - 
validityprotected long validity The validity fromepochin ms. A validity <= 0 means unlimited.
 - 
scopesprotected java.util.Set<java.lang.String> scopes List of scopes of this token
 
- 
 - 
Constructor Detail- 
Tokenpublic Token(User.Type user, java.lang.String... scope) Creates a new token. The start of validity is now and the token is valid for 1 hour. The token value is aSecurity.randomHash().- Parameters:
- user- the linked user, must not be null
- scope- all applicable scopes
 
 - 
Tokenpublic Token(User.Type user, long validity, java.lang.String... scope) Creates a new token. The start of validity is now. The token value is aSecurity.randomHash().- Parameters:
- user- the linked user, must not be null
- validity- the validity period in ms. A value <0 meand unlimited.
- scope- all applicable scopes
 
 - 
Tokenpublic Token(User.Type user, long validity, long epoch, java.lang.String... scope) Creates a new token. The token value is aSecurity.randomHash().- Parameters:
- user- the linked user, must not be null
- validity- the validity period in ms. A value <0 meand unlimited.
- epoch- the start of validity as a timestamp in ms
- scope- all applicable scopes
 
 - 
Tokenpublic Token(User.Type user, long validity, long epoch, java.lang.String value, java.lang.String... scope) Creates a new token.- Parameters:
- user- the linked user, must not be null
- validity- the validity period in ms. A value <0 meand unlimited.
- epoch- the start of validity as a timestamp in ms
- value- the opaque token value
- scope- all applicable scopes
 
 
- 
 - 
Method Detail- 
valuepublic java.lang.String value() Returns the public cryptographically secure and universally unique value of this token. The value itself is considered meaningless and opaque.- Returns:
- the public cryptographically secure and universally unique value of this token
 
 - 
userpublic User.Type user() Returns theUserlinked to this token.- Returns:
- the Providerlinked to this token, it may be null if the user does not exist in the registry
 
 - 
isForpublic boolean isFor(java.lang.String user) Returns true if theUserlinked to this token matches the provided identifier.- Parameters:
- user- the user to check
- Returns:
- true if the Userlinked to this token matches the provided identifier
 
 - 
notBeforepublic long notBefore() Returns the start of validity of this token as a timestamp in ms- Returns:
- the start of validity of this token as a timestamp in ms
 
 - 
notAfterpublic long notAfter() Returns the end of validity of this token as a timestamp in ms- Returns:
- the end of validity of this token as a timestamp in ms
 
 - 
isValidpublic boolean isValid() Returns whether or not this token is valid at the current moment in time- Returns:
- true if this token is valid at the current moment in time
 
 - 
resetpublic void reset() Resets the start of validity of this token to now
 - 
inScopepublic boolean inScope(java.lang.String scope) Returns whether or not this token applies to the specified scope- Parameters:
- scope- the scope to check
- Returns:
- true if this token applies to the specified scope
 
 - 
addScopepublic void addScope(java.lang.String scope) Adds the specified scope to this token- Parameters:
- scope- the scope to add
 
 - 
removeScopepublic void removeScope(java.lang.String scope) Removes the specified scope from this token- Parameters:
- scope- the scope to remove
 
 - 
exportpublic Data export() Description copied from interface:ExportableRenders this class instance to a simple data structure for rendering client-side.- Specified by:
- exportin interface- Exportable
- Returns:
- a public data representation of this class instance
 
 
- 
 
-