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 StringLOG_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.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
-
-
-
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:TokenAuthenticationModelGenerate token withtokenNamefor userId. Subsequent invocation ofTokenAuthenticationModel.parseToken(java.lang.String)on the string returned by this method should result in correct instance ofBearerTokenCredentials- Specified by:
createTokenin 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:TokenAuthenticationModelGenerate token withtokenNamefor userId. Subsequent invocation ofTokenAuthenticationModel.parseToken(java.lang.String)on the string returned by this method should result in correct instance ofBearerTokenCredentials- Specified by:
createTokenin 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:TokenAuthenticationModelList all user tokens- Specified by:
getUserTokensin 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:TokenAuthenticationModelCount user tokens- Specified by:
countUserTokensin interfaceTokenAuthenticationModel- Returns:
- number of user tokens
-
updateLastAccessInfo
public void updateLastAccessInfo(@NotNull SimpleCredentials credentials, @Nullable String remoteAddress)Description copied from interface:TokenAuthenticationModelUpdate information about last usage of a token.- Specified by:
updateLastAccessInfoin interfaceTokenAuthenticationModel
-
deleteToken
public void deleteToken(long userId, @NotNull String tokenName)Description copied from interface:TokenAuthenticationModelDelete token by user id and token name- Specified by:
deleteTokenin interfaceTokenAuthenticationModel
-
deleteAllUserTokens
public void deleteAllUserTokens(long userId)
Description copied from interface:TokenAuthenticationModelDelete all user tokens- Specified by:
deleteAllUserTokensin interfaceTokenAuthenticationModel
-
deleteAllTokens
public void deleteAllTokens()
Description copied from interface:TokenAuthenticationModelDelete all tokens- Specified by:
deleteAllTokensin interfaceTokenAuthenticationModel
-
parseToken
@NotNull public BearerTokenCredentials parseToken(@NotNull String token)
Description copied from interface:TokenAuthenticationModelParse token from raw string- Specified by:
parseTokenin interfaceTokenAuthenticationModel- Returns:
- BearerTokenCredentials containing name and token value
-
userHasReachedMaxAllowedNumberOfTokens
public boolean userHasReachedMaxAllowedNumberOfTokens(long userId)
Description copied from interface:TokenAuthenticationModelCheck whether user has already reached max number of allowed tokens- Specified by:
userHasReachedMaxAllowedNumberOfTokensin interfaceTokenAuthenticationModel- Returns:
- true if user already has max number of tokens
-
checkCredentials
public TokenAuthenticationModel.CheckCredentialsResult checkCredentials(@NotNull SimpleCredentials credentials)
Description copied from interface:TokenAuthenticationModelChecks whether the password provided in credentials matches existing token for user with provided username- Specified by:
checkCredentialsin interfaceTokenAuthenticationModel- Returns:
-
isMyToken
public boolean isMyToken(@NotNull String tokenValue)Description copied from interface:TokenAuthenticationModelCheck whether the token was generated by this module- Specified by:
isMyTokenin interfaceTokenAuthenticationModel- Parameters:
tokenValue- token- Returns:
- true if token created by this module
-
validateName
public void validateName(@NotNull String name) throws AuthenticationTokenStorage.InvalidTokenNameDescription copied from interface:TokenAuthenticationModelValidate the token name- Specified by:
validateNamein interfaceTokenAuthenticationModel- Parameters:
name- token name- Throws:
AuthenticationTokenStorage.InvalidTokenName- when the name is not valid
-
find
public AuthenticationToken find(@NotNull String id)
- Specified by:
findin interfaceTokenAuthenticationModel
-
-