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 Modifier and Type Class Description static classApiTokenStore.HashedToken
-
Constructor Summary
Constructors Constructor Description ApiTokenStore()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringaddFixedNewToken(String name, String tokenPlainValue)Be careful with this method.ApiTokenStore.HashedTokenfindMatchingToken(String token)Search in the store if there is a token with the same secret as the one givenTokenUuidAndPlainValuegenerateNewToken(String name)Create a new token with the given name and return it id and secret value.ApiTokenStore.HashedTokengetLegacyToken()Collection<ApiTokenStore.HashedToken>getTokenListSortedByName()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 itvoidrevokeAllTokens()voidrevokeAllTokensExcept(String tokenUuid)ApiTokenStore.HashedTokenrevokeToken(String tokenUuid)Remove a token given its identifier.
-
-
-
Method Detail
-
getTokenListSortedByName
@NonNull public Collection<ApiTokenStore.HashedToken> getTokenListSortedByName()
-
reconfigure
public void reconfigure(@NonNull 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 change
-
regenerateTokenFromLegacy
public void regenerateTokenFromLegacy(@NonNull Secret newLegacyApiToken)Remove the legacy token present and generate a new one using the given secret.
-
regenerateTokenFromLegacyIfRequired
public void regenerateTokenFromLegacyIfRequired(@NonNull Secret newLegacyApiToken)Same asregenerateTokenFromLegacy(Secret)but only applied if there is an existing legacy token.Otherwise, no effect.
-
getLegacyToken
@Nullable public ApiTokenStore.HashedToken getLegacyToken()
- Returns:
nulliff there is no legacy token in the store, otherwise the legacy token is returned
-
generateNewToken
@NonNull public TokenUuidAndPlainValue generateNewToken(@NonNull String name)
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
@NonNull public String addFixedNewToken(@NonNull String name, @NonNull String tokenPlainValue)
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
@CheckForNull public ApiTokenStore.HashedToken findMatchingToken(@NonNull String token)
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
@CheckForNull public ApiTokenStore.HashedToken revokeToken(@NonNull String tokenUuid)
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
public void revokeAllTokensExcept(@NonNull String tokenUuid)
-
-