Class TokenAuthenticationModelImpl
- java.lang.Object
-
- jetbrains.buildServer.serverSide.auth.impl.TokenAuthenticationModelImpl
-
- All Implemented Interfaces:
TokenAuthenticationModel
public class TokenAuthenticationModelImpl extends Object implements TokenAuthenticationModel
- Author:
- Dmitrii Bogdanov
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jetbrains.buildServer.serverSide.auth.TokenAuthenticationModel
TokenAuthenticationModel.CheckCredentialsResult
-
-
Field Summary
Fields Modifier and Type Field Description static String
LOG_EXPIRED_TOKENS_PROPERTY
-
Constructor Summary
Constructors Constructor Description TokenAuthenticationModelImpl(UserModelEx userModelEx, AuthenticationTokenCreator authenticationTokenCreator, AuthenticationTokenStorage authenticationTokenStorage, MultiNodesEvents multiNodesEvents, ServerResponsibility responsibility, ScheduledExecutorService executorService, TimeService timeService, AuditLogFactory auditLogFactory, EventDispatcher<BuildServerListener> dispatcher)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TokenAuthenticationModel.CheckCredentialsResult
checkCredentials(SimpleCredentials credentials)
Checks whether the password provided in credentials matches existing token for user with provided usernameint
countUserTokens(long userId)
Count user tokensAuthenticationToken
createToken(long userId, String tokenName, Date expirationTime)
Generate token withtokenName
for userId.AuthenticationToken
createToken(long userId, String tokenName, Date expirationTime, AuthenticationToken.PermissionsRestriction permissionsRestriction)
Generate token withtokenName
for userId.void
deleteAllTokens()
Delete all tokensvoid
deleteAllUserTokens(long userId)
Delete all user tokensvoid
deleteToken(long userId, String tokenName)
Delete token by user id and token nameAuthenticationToken
find(String id)
List<AuthenticationToken>
getUserTokens(long userId)
List all user tokensboolean
isMyToken(String tokenValue)
Check whether the token was generated by this moduleBearerTokenCredentials
parseToken(String token)
Parse token from raw stringvoid
updateLastAccessInfo(SimpleCredentials credentials, String remoteAddress)
Update information about last usage of a token.boolean
userHasReachedMaxAllowedNumberOfTokens(long userId)
Check whether user has already reached max number of allowed tokensvoid
validateName(String name)
Validate the token name
-
-
-
Field Detail
-
LOG_EXPIRED_TOKENS_PROPERTY
@NotNull public static final String LOG_EXPIRED_TOKENS_PROPERTY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TokenAuthenticationModelImpl
public TokenAuthenticationModelImpl(@NotNull UserModelEx userModelEx, @NotNull AuthenticationTokenCreator authenticationTokenCreator, @NotNull AuthenticationTokenStorage authenticationTokenStorage, @NotNull MultiNodesEvents multiNodesEvents, @NotNull ServerResponsibility responsibility, @NotNull ScheduledExecutorService executorService, @NotNull TimeService timeService, @NotNull AuditLogFactory auditLogFactory, @NotNull EventDispatcher<BuildServerListener> dispatcher)
-
-
Method Detail
-
createToken
@NotNull public AuthenticationToken createToken(long userId, @NotNull String tokenName, @NotNull Date expirationTime) throws AuthenticationTokenStorage.CreationException
Description copied from interface:TokenAuthenticationModel
Generate token withtokenName
for userId. Subsequent invocation ofTokenAuthenticationModel.parseToken(java.lang.String)
on the string returned by this method should result in correct instance ofBearerTokenCredentials
- Specified by:
createToken
in interfaceTokenAuthenticationModel
- Returns:
- generated token
- Throws:
AuthenticationTokenStorage.CreationException
- if the user already has the token with specified name
-
createToken
@NotNull public AuthenticationToken createToken(long userId, @NotNull String tokenName, @NotNull Date expirationTime, @NotNull AuthenticationToken.PermissionsRestriction permissionsRestriction) throws AuthenticationTokenStorage.CreationException
Description copied from interface:TokenAuthenticationModel
Generate token withtokenName
for userId. Subsequent invocation ofTokenAuthenticationModel.parseToken(java.lang.String)
on the string returned by this method should result in correct instance ofBearerTokenCredentials
- Specified by:
createToken
in interfaceTokenAuthenticationModel
- Returns:
- generated token
- Throws:
AuthenticationTokenStorage.CreationException
- if the user already has the token with specified name
-
getUserTokens
@NotNull public List<AuthenticationToken> getUserTokens(long userId)
Description copied from interface:TokenAuthenticationModel
List all user tokens- Specified by:
getUserTokens
in interfaceTokenAuthenticationModel
- Returns:
- empty collection if user doesn't have tokens or list of tokens without values
-
countUserTokens
public int countUserTokens(long userId)
Description copied from interface:TokenAuthenticationModel
Count user tokens- Specified by:
countUserTokens
in interfaceTokenAuthenticationModel
- Returns:
- number of user tokens
-
updateLastAccessInfo
public void updateLastAccessInfo(@NotNull SimpleCredentials credentials, @Nullable String remoteAddress)
Description copied from interface:TokenAuthenticationModel
Update information about last usage of a token.- Specified by:
updateLastAccessInfo
in interfaceTokenAuthenticationModel
-
deleteToken
public void deleteToken(long userId, @NotNull String tokenName)
Description copied from interface:TokenAuthenticationModel
Delete token by user id and token name- Specified by:
deleteToken
in interfaceTokenAuthenticationModel
-
deleteAllUserTokens
public void deleteAllUserTokens(long userId)
Description copied from interface:TokenAuthenticationModel
Delete all user tokens- Specified by:
deleteAllUserTokens
in interfaceTokenAuthenticationModel
-
deleteAllTokens
public void deleteAllTokens()
Description copied from interface:TokenAuthenticationModel
Delete all tokens- Specified by:
deleteAllTokens
in interfaceTokenAuthenticationModel
-
parseToken
@NotNull public BearerTokenCredentials parseToken(@NotNull String token)
Description copied from interface:TokenAuthenticationModel
Parse token from raw string- Specified by:
parseToken
in interfaceTokenAuthenticationModel
- Returns:
- BearerTokenCredentials containing name and token value
-
userHasReachedMaxAllowedNumberOfTokens
public boolean userHasReachedMaxAllowedNumberOfTokens(long userId)
Description copied from interface:TokenAuthenticationModel
Check whether user has already reached max number of allowed tokens- Specified by:
userHasReachedMaxAllowedNumberOfTokens
in interfaceTokenAuthenticationModel
- Returns:
- true if user already has max number of tokens
-
checkCredentials
public TokenAuthenticationModel.CheckCredentialsResult checkCredentials(@NotNull SimpleCredentials credentials)
Description copied from interface:TokenAuthenticationModel
Checks whether the password provided in credentials matches existing token for user with provided username- Specified by:
checkCredentials
in interfaceTokenAuthenticationModel
- Returns:
-
isMyToken
public boolean isMyToken(@NotNull String tokenValue)
Description copied from interface:TokenAuthenticationModel
Check whether the token was generated by this module- Specified by:
isMyToken
in interfaceTokenAuthenticationModel
- Parameters:
tokenValue
- token- Returns:
- true if token created by this module
-
validateName
public void validateName(@NotNull String name) throws AuthenticationTokenStorage.InvalidTokenName
Description copied from interface:TokenAuthenticationModel
Validate the token name- Specified by:
validateName
in interfaceTokenAuthenticationModel
- Parameters:
name
- token name- Throws:
AuthenticationTokenStorage.InvalidTokenName
- when the name is not valid
-
find
public AuthenticationToken find(@NotNull String id)
- Specified by:
find
in interfaceTokenAuthenticationModel
-
-