- 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 ofPolicy
scopes.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 Summary
Fields Modifier and Type Field Description protected long
epoch
The start of validity point in timeprotected java.util.Set<java.lang.String>
scopes
List of scopes of this tokenprotected java.lang.String
user
The linked user idprotected long
validity
The validity fromepoch
in ms.protected java.lang.String
value
the public cryptographically secure and universally unique token value
-
Constructor Summary
Constructors 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 Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addScope(java.lang.String scope)
Adds the specified scope to this tokenData
export()
Renders this class instance to a simple data structure for rendering client-side.boolean
inScope(java.lang.String scope)
Returns whether or not this token applies to the specified scopeboolean
isFor(java.lang.String user)
Returns true if theUser
linked to this token matches the provided identifier.boolean
isValid()
Returns whether or not this token is valid at the current moment in timelong
notAfter()
Returns the end of validity of this token as a timestamp in mslong
notBefore()
Returns the start of validity of this token as a timestamp in msvoid
removeScope(java.lang.String scope)
Removes the specified scope from this tokenvoid
reset()
Resets the start of validity of this token to nowUser.Type
user()
Returns theUser
linked to this token.java.lang.String
value()
Returns the public cryptographically secure and universally unique value of this token.
-
-
-
Field Detail
-
value
protected java.lang.String value
the public cryptographically secure and universally unique token value
-
user
protected java.lang.String user
The linked user id
-
epoch
protected long epoch
The start of validity point in time
-
validity
protected long validity
The validity fromepoch
in ms. A validity <= 0 means unlimited.
-
scopes
protected java.util.Set<java.lang.String> scopes
List of scopes of this token
-
-
Constructor Detail
-
Token
public 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 nullscope
- all applicable scopes
-
Token
public 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 nullvalidity
- the validity period in ms. A value <0 meand unlimited.scope
- all applicable scopes
-
Token
public 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 nullvalidity
- the validity period in ms. A value <0 meand unlimited.epoch
- the start of validity as a timestamp in msscope
- all applicable scopes
-
Token
public 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 nullvalidity
- the validity period in ms. A value <0 meand unlimited.epoch
- the start of validity as a timestamp in msvalue
- the opaque token valuescope
- all applicable scopes
-
-
Method Detail
-
value
public 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
-
user
public User.Type user()
Returns theUser
linked to this token.- Returns:
- the
Provider
linked to this token, it may be null if the user does not exist in the registry
-
isFor
public boolean isFor(java.lang.String user)
Returns true if theUser
linked to this token matches the provided identifier.- Parameters:
user
- the user to check- Returns:
- true if the
User
linked to this token matches the provided identifier
-
notBefore
public 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
-
notAfter
public 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
-
isValid
public 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
-
reset
public void reset()
Resets the start of validity of this token to now
-
inScope
public 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
-
addScope
public void addScope(java.lang.String scope)
Adds the specified scope to this token- Parameters:
scope
- the scope to add
-
removeScope
public void removeScope(java.lang.String scope)
Removes the specified scope from this token- Parameters:
scope
- the scope to remove
-
export
public Data export()
Description copied from interface:Exportable
Renders this class instance to a simple data structure for rendering client-side.- Specified by:
export
in interfaceExportable
- Returns:
- a public data representation of this class instance
-
-