Interface TokenAuthenticationModel
-
- All Known Implementing Classes:
SecureTokenAuthenticationModelImpl,TokenAuthenticationModelImpl
public interface TokenAuthenticationModelEncapsulates managing of access tokens for users- Since:
- 2019.1
- Author:
- Dmitrii Bogdanov
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classTokenAuthenticationModel.CheckCredentialsResult
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description TokenAuthenticationModel.CheckCredentialsResultcheckCredentials(SimpleCredentials credentials)Checks whether the password provided in credentials matches existing token for user with provided usernameintcountUserTokens(long userId)Count user tokensAuthenticationTokencreateToken(long userId, String tokenName, Date expirationTime)Generate token withtokenNamefor userId.AuthenticationTokencreateToken(long userId, String tokenName, Date expirationTime, AuthenticationToken.PermissionsRestriction permissionsRestriction)Generate token withtokenNamefor userId.voiddeleteAllTokens()Delete all tokensvoiddeleteAllUserTokens(long userId)Delete all user tokensvoiddeleteToken(long userId, String tokenName)Delete token by user id and token nameAuthenticationTokenfind(String id)List<AuthenticationToken>getUserTokens(long userId)List all user tokensbooleanisMyToken(String tokenValue)Check whether the token was generated by this moduleBearerTokenCredentialsparseToken(String token)Parse token from raw stringvoidupdateLastAccessInfo(SimpleCredentials credentials, String remoteAddress)Update information about last usage of a token.booleanuserHasReachedMaxAllowedNumberOfTokens(long userId)Check whether user has already reached max number of allowed tokensvoidvalidateName(String name)Validate the token name
-
-
-
Method Detail
-
createToken
@NotNull AuthenticationToken createToken(long userId, @NotNull String tokenName, @NotNull Date expirationTime) throws AuthenticationTokenStorage.CreationException
Generate token withtokenNamefor userId. Subsequent invocation ofparseToken(java.lang.String)on the string returned by this method should result in correct instance ofBearerTokenCredentials- Parameters:
userId-tokenName-expirationTime-- Returns:
- generated token
- Throws:
AuthenticationTokenStorage.CreationException- if the user already has the token with specified nameAuthenticationTokenStorage.CreationException- if the user has already reached max allowed number of tokens
-
createToken
@NotNull AuthenticationToken createToken(long userId, @NotNull String tokenName, @NotNull Date expirationTime, @NotNull AuthenticationToken.PermissionsRestriction permissionsRestriction) throws AuthenticationTokenStorage.CreationException
Generate token withtokenNamefor userId. Subsequent invocation ofparseToken(java.lang.String)on the string returned by this method should result in correct instance ofBearerTokenCredentials- Parameters:
userId-tokenName-expirationTime-permissionsRestriction-- Returns:
- generated token
- Throws:
AuthenticationTokenStorage.CreationException- if the user already has the token with specified nameAuthenticationTokenStorage.CreationException- if the user has already reached max allowed number of tokens
-
getUserTokens
@NotNull List<AuthenticationToken> getUserTokens(long userId)
List all user tokens- Parameters:
userId-- Returns:
- empty collection if user doesn't have tokens or list of tokens without values
-
countUserTokens
int countUserTokens(long userId)
Count user tokens- Parameters:
userId-- Returns:
- number of user tokens
- Since:
- 2019.1.1
-
updateLastAccessInfo
void updateLastAccessInfo(@NotNull SimpleCredentials credentials, @Nullable String remoteAddress)Update information about last usage of a token.- Parameters:
credentials-remoteAddress-
-
deleteToken
void deleteToken(long userId, @NotNull String tokenName) throws AuthenticationTokenStorage.DeletionExceptionDelete token by user id and token name- Parameters:
userId-tokenName-- Throws:
AuthenticationTokenStorage.DeletionException- if token does not exist
-
deleteAllTokens
void deleteAllTokens()
Delete all tokens
-
deleteAllUserTokens
void deleteAllUserTokens(long userId)
Delete all user tokens- Parameters:
userId-
-
parseToken
@NotNull BearerTokenCredentials parseToken(@NotNull String token) throws InvalidBearerTokenException
Parse token from raw string- Parameters:
token-- Returns:
- BearerTokenCredentials containing name and token value
- Throws:
InvalidBearerTokenException- if token has invalid format
-
userHasReachedMaxAllowedNumberOfTokens
boolean userHasReachedMaxAllowedNumberOfTokens(long userId)
Check whether user has already reached max number of allowed tokens- Parameters:
userId-- Returns:
- true if user already has max number of tokens
-
checkCredentials
TokenAuthenticationModel.CheckCredentialsResult checkCredentials(@NotNull SimpleCredentials credentials)
Checks whether the password provided in credentials matches existing token for user with provided username- Parameters:
credentials-- Returns:
- Throws:
InvalidBearerTokenException- if password in credentials is not a valid tokenNotAuthenticatedBearerTokenException- if token is valid but does not match username or if the user does not exist
-
isMyToken
boolean isMyToken(@NotNull String tokenValue)Check whether the token was generated by this module- Parameters:
tokenValue- token- Returns:
- true if token created by this module
-
validateName
void validateName(@NotNull String name) throws AuthenticationTokenStorage.InvalidTokenNameValidate the token name- Parameters:
name- token name- Throws:
AuthenticationTokenStorage.InvalidTokenName- when the name is not valid
-
find
AuthenticationToken find(@NotNull String id)
-
-