Interface TokenService
public interface TokenService
-
Method Summary
Modifier and TypeMethodDescriptioncreateAccessToken(String clientId, String userKey, String authorizationCode, long authorizationDate, Scope scope) Creates an Access TokencreateRefreshToken(String clientId, String userKey, long authorizationDate, String accessTokenId, Scope scope, String authorizationCode, int refreshCount) Creates a Refresh TokenfindAccessTokensByUserKey(com.atlassian.sal.api.user.UserKey userKey) Finds access tokens for userKeyfindByAccessTokenId(String tokenId) Tries to find aAccessTokenusing the raw tokenfindByRefreshTokenId(String tokenId) Tries to find aRefreshTokenusing the raw tokenfindRefreshTokensByUserKey(com.atlassian.sal.api.user.UserKey userKey) Finds refresh tokens for userKeyfindRefreshTokensForClientId(String clientId) Finds refresh tokens for a client idfindUserKeysByClientId(String clientId) Finds user keys of tokens for a client idbooleanisAccessTokenValid(String clientId, String accessTokenId) Checks if the provided access token is stored against the provided client IDbooleanisCodeRedeemed(String authorizationCode) Checks if the provided authorization code is held against an existing tokenbooleanisRefreshTokenValid(String clientId, String refreshTokenId) Checks if the provided refresh token is stored against the provided client IDremoveAccessTokenAssociatedWith(String refreshTokenId) Removes token associated with refresh tokenremoveAccessTokenById(String tokenId) Removes stored token using raw tokenvoidremoveByClientId(String clientId) Removes all tokens for client idremoveByUserKey(String userKey) Removes all tokens for user keydefault booleanremoveCurrentUsersTokensById(String tokenId) Removes associated tokens for a given tokenId.voidremoveExpiredAccessTokens(Duration expirationPeriod) Removes all expired access tokensvoidremoveExpiredRefreshTokens(Duration expirationPeriod) Removes all expired refresh tokensremoveRefreshToken(String refreshTokenId) Removes refresh tokenremoveRefreshTokenAssociatedWith(String accessTokenId) Removes token associated with access tokenremoveTokensByAuthorizationCode(String authorizationCode) Removes stored tokens using the provided authorization codebooleanremoveTokensById(String tokenId) Deprecated.voidupdateAccessTokenLastAccessed(String tokenId) Updates last accessed time for access token
-
Method Details
-
createAccessToken
@Nonnull AccessToken createAccessToken(String clientId, String userKey, String authorizationCode, long authorizationDate, Scope scope) Creates an Access Token- Parameters:
clientId- client id for the tokenuserKey- userKey for tokenauthorizationCode- authorization code used to redeem tokenauthorizationDate- date when authorization was givenscope- scope for access token- Returns:
- created access token
-
createRefreshToken
@Nonnull RefreshToken createRefreshToken(String clientId, String userKey, long authorizationDate, String accessTokenId, Scope scope, String authorizationCode, int refreshCount) Creates a Refresh Token- Parameters:
clientId- client id for the tokenuserKey- userKey for tokenauthorizationDate- date when authorization was givenaccessTokenId- associated with refresh tokenscope- scope for refresh tokenrefreshCount- the number of refreshesauthorizationCode- authorization code used to redeem token- Returns:
- created refresh token
-
updateAccessTokenLastAccessed
Updates last accessed time for access token- Parameters:
tokenId- token to update
-
findByAccessTokenId
Tries to find aAccessTokenusing the raw token- Parameters:
tokenId- raw token to search database with- Returns:
- an optional token
-
findByRefreshTokenId
Tries to find aRefreshTokenusing the raw token- Parameters:
tokenId- raw token to search database with- Returns:
- an optional token
-
removeAccessTokenById
Removes stored token using raw token- Parameters:
tokenId- id of the token to remove- Returns:
- removed token or empty
-
removeTokensByAuthorizationCode
Removes stored tokens using the provided authorization code- Parameters:
authorizationCode- authorization code to search for- Returns:
- removed tokens or empty
-
removeByClientId
Removes all tokens for client id- Parameters:
clientId- client id whose tokens are to be removed
-
removeByUserKey
Removes all tokens for user key- Parameters:
userKey- user key for whose tokens are to be removed- Returns:
- removed tokens or empty
-
removeExpiredAccessTokens
Removes all expired access tokens- Parameters:
expirationPeriod- the period of time after which we remove access tokens
-
removeExpiredRefreshTokens
Removes all expired refresh tokens- Parameters:
expirationPeriod- the period of time after which we remove refresh tokens
-
findUserKeysByClientId
Finds user keys of tokens for a client id- Parameters:
clientId- client id with tokens to search for- Returns:
- found userKeys as strings or an empty list
-
findRefreshTokensForClientId
Finds refresh tokens for a client id- Parameters:
clientId- client id with tokens to search for- Returns:
- found refreshTokens or an empty list
-
findAccessTokensByUserKey
Finds access tokens for userKey- Parameters:
userKey- user key to search with- Returns:
- found tokens or an empty list
-
findRefreshTokensByUserKey
Finds refresh tokens for userKey- Parameters:
userKey- user key to search with- Returns:
- found tokens or an empty list
-
removeAccessTokenAssociatedWith
Removes token associated with refresh token- Returns:
- revoked access token
-
removeRefreshTokenAssociatedWith
Removes token associated with access token- Returns:
- revoked refresh token
-
isAccessTokenValid
Checks if the provided access token is stored against the provided client ID- Parameters:
clientId- id of the clientaccessTokenId- id of the access token to validate- Returns:
- true if the refresh token is valid
-
isRefreshTokenValid
Checks if the provided refresh token is stored against the provided client ID- Parameters:
clientId- id of the clientrefreshTokenId- id of the refresh token to validate- Returns:
- true if the refresh token is valid
-
removeRefreshToken
Removes refresh token- Parameters:
refreshTokenId- - id of the refresh token to remove- Returns:
- removed
RefreshTokenor empty
-
isCodeRedeemed
Checks if the provided authorization code is held against an existing token- Parameters:
authorizationCode- code to search for- Returns:
- true if the authorization code is found
-
removeCurrentUsersTokensById
Removes associated tokens for a given tokenId. The ID can be of an access or refresh token and the result will be that both are removed regardless of what is passed in. The currently logged-in user must own the tokens or be a system admin.- Parameters:
tokenId- access or refresh token id- Returns:
- true if tokens removed, false if no tokens removed
-
removeTokensById
Deprecated.useremoveCurrentUsersTokensById(String)insteadRemoves tokens for tokenId, treating it as an access or refresh token and removing either- Parameters:
tokenId- access or refresh token id- Returns:
- true if tokens removed, false if no tokens removed
-
removeCurrentUsersTokensById(String)instead