Package jenkins.security.apitoken
Class ApiTokenStore
java.lang.Object
jenkins.security.apitoken.ApiTokenStore
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class)
public class ApiTokenStore
extends Object
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddFixedNewToken(String name, String tokenPlainValue) Be careful with this method.findMatchingToken(String token) Search in the store if there is a token with the same secret as the one givengenerateNewToken(String name) Create a new token with the given name and return it id and secret value.voidreconfigure(Map<String, net.sf.json.JSONObject> tokenStoreDataMap) Defensive approach to avoid involuntary change since the UUIDs are generated at startup only for UI and so between restart they changevoidregenerateTokenFromLegacy(Secret newLegacyApiToken) Remove the legacy token present and generate a new one using the given secret.voidregenerateTokenFromLegacyIfRequired(Secret newLegacyApiToken) Same asregenerateTokenFromLegacy(Secret)but only applied if there is an existing legacy token.booleanrenameToken(String tokenUuid, String newName) Given a token identifier and a name, the system will try to find a corresponding token and rename itvoidvoidrevokeAllTokensExcept(String tokenUuid) revokeToken(String tokenUuid) Remove a token given its identifier.
-
Constructor Details
-
ApiTokenStore
public ApiTokenStore()
-
-
Method Details
-
getTokenListSortedByName
-
reconfigure
Defensive approach to avoid involuntary change since the UUIDs are generated at startup only for UI and so between restart they change -
regenerateTokenFromLegacy
Remove the legacy token present and generate a new one using the given secret. -
regenerateTokenFromLegacyIfRequired
Same asregenerateTokenFromLegacy(Secret)but only applied if there is an existing legacy token.Otherwise, no effect.
-
getLegacyToken
- Returns:
nulliff there is no legacy token in the store, otherwise the legacy token is returned
-
generateNewToken
Create a new token with the given name and return it id and secret value. Result meant to be sent / displayed and then discarded. -
addFixedNewToken
Be careful with this method. Depending on how the tokenPlainValue was stored/sent to this method, it could be a good idea to generate a new token randomly and revoke this one. -
findMatchingToken
Search in the store if there is a token with the same secret as the one given- Returns:
nulliff there is no matching token
-
revokeToken
Remove a token given its identifier. Effectively make it unusable for future connection.- Parameters:
tokenUuid- The identifier of the token, could be retrieved directly from theApiTokenStore.HashedToken.getUuid()- Returns:
- the revoked token corresponding to the given
tokenUuidif one was found, otherwisenull
-
revokeAllTokens
public void revokeAllTokens() -
revokeAllTokensExcept
-
renameToken
Given a token identifier and a name, the system will try to find a corresponding token and rename it- Returns:
trueiff the token was found and the rename was successful
-