Interface TokensManagement
public interface TokensManagement
Tokens API allows for manipulating generic tokens. Token is a piece of information which is:
- bound to an entity
- has unique identifier
- has type (e.g. OAuth access token)
- can have expiration time, when it is removed
- can contain additional, type specific data
As this is a low level interface it allows for external transaction steering. All methods will join an existing transaction if it is present.
- Author:
- K. Benedyczak
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceReceives notifications about expired tokens. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a new token without ownervoidaddToken(String type, String value, pl.edu.icm.unity.base.entity.EntityParam owner, byte[] contents, Date created, Date expires) Adds a new tokenvoidaddTokenExpirationListener(TokensManagement.TokenExpirationListener listener, String type) Adds a new listenr which is notified about expired tokens of a specified typeList<pl.edu.icm.unity.base.token.Token> List<pl.edu.icm.unity.base.token.Token> getAllTokens(String type) List<pl.edu.icm.unity.base.token.Token> getOwnedTokens(String type, pl.edu.icm.unity.base.entity.EntityParam entity) Returns all tokens of the entitypl.edu.icm.unity.base.token.TokengetTokenById(String type, String value) Returns a specified tokenpl.edu.icm.unity.base.token.TokengetTokenByIdForUpdate(String type, String value) AsgetTokenById(String, String), but takes a database row lock (SELECT ...voidremoveToken(String type, String value) Removes the tokenvoidupdateToken(String type, String value, Date expires, byte[] contents) Update the token.
-
Method Details
-
addToken
void addToken(String type, String value, pl.edu.icm.unity.base.entity.EntityParam owner, byte[] contents, Date created, Date expires) throws pl.edu.icm.unity.base.identity.IllegalIdentityValueException, IllegalTypeException Adds a new token- Parameters:
type- type or category of the tokencreated- creation timestamp. It is guaranteed to be stored with second precision, though implementation might also store the full time.expires- precision as in created case.- Throws:
pl.edu.icm.unity.base.identity.IllegalIdentityValueExceptionIllegalTypeException
-
addToken
void addToken(String type, String value, byte[] contents, Date created, Date expires) throws IllegalTypeException Adds a new token without owner- Parameters:
type- type or category of the tokencreated- creation timestamp. It is guaranteed to be stored with second precision, though implementation might also store the full time.expires- precision as in created case.- Throws:
IllegalTypeException
-
removeToken
Removes the token -
updateToken
Update the token. Only contents and expiration time can be updated - the type and value are used to look up a token for update.- Parameters:
expires- if null -> leave unchangedcontents- if null -> leave unchanged
-
getTokenById
Returns a specified token -
getTokenByIdForUpdate
AsgetTokenById(String, String), but takes a database row lock (SELECT ... FOR UPDATE), held for the duration of the current transaction. Must be called inside an existing transaction which will follow up with a write, so that the whole read-decide-write sequence is atomic with regard to concurrent callers acting on the same token.Unlike
getTokenById(String, String), this does NOT filter out an already-expired token - it is still returned (withToken.isExpired()true) rather than causing aTokenNotFoundException. Callers of this method are, by definition, about to make their own atomic decision and often need to distinguish "expired" from "never existed" themselves (e.g. to report a protocol-specific expiry error instead of a generic not-found one). -
getOwnedTokens
List<pl.edu.icm.unity.base.token.Token> getOwnedTokens(String type, pl.edu.icm.unity.base.entity.EntityParam entity) throws pl.edu.icm.unity.base.identity.IllegalIdentityValueException, IllegalTypeException Returns all tokens of the entity- Throws:
pl.edu.icm.unity.base.identity.IllegalIdentityValueExceptionIllegalTypeException
-
getAllTokens
- Returns:
- all tokens of a given type
-
getAllTokens
List<pl.edu.icm.unity.base.token.Token> getAllTokens()- Returns:
- all tokens
-
addTokenExpirationListener
Adds a new listenr which is notified about expired tokens of a specified type
-