Class ProjectCredentialsStorage
- java.lang.Object
-
- jetbrains.buildServer.serverSide.impl.projects.ProjectCredentialsStorage
-
- All Implemented Interfaces:
CredentialsStorage
,CredentialsStorageEx
,EncryptionChangeListener
,ServerExtension
,TeamCityExtension
public class ProjectCredentialsStorage extends Object implements CredentialsStorageEx, EncryptionChangeListener
-
-
Field Summary
Fields Modifier and Type Field Description static String
ALLOW_CHANGING_VALUES_FOR_TOKENS_PROPERTY
static String
CREDENTIALS_FILE_PATH
static String
CREDENTIALS_JSON_FILENAME
static String
STORAGE_TYPE
-
Constructor Summary
Constructors Constructor Description ProjectCredentialsStorage(EventDispatcher<BuildServerListener> eventDispatcher, ProjectManager projectManager, ProjectManagerErrors projectManagerErrors, ServerResponsibilityEx serverResponsibility, AccessChecker accessChecker, SecurityContextEx securityContext, EncryptionManager encryptionManager, ConfigActionFactory configActionFactory, ExecutorServices executorServices)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
beforeProjectSettingsLoaded(ProjectEx project)
void
copySecureValuesForTokens(Map<String,SProject> tokenProjects, SProject contextProject)
Copy tokens to contextProject from tokenProjects.void
deleteTokensFromProject(List<String> tokens, SProject contextProject)
Delete tokens from context project Requires explicit persist action after, see CredentialsStorageEx#schedulePersistingCredentialsMap<String,Map<String,String>>
findSecureValuesForTokens(Set<String> tokens, List<SProject> contextProjects)
Find all secure values for tokens in contextProjects For each token, different secure values can be found in different projectsString
findTokenForSecureValue(String secureValue, SProject contextProject)
Finds already existing token for the secure valueMap<String,String>
getStoredValues(SProject contextProject)
Return all stored secure values for [contextProject]String
getType()
String
mapSecureValueToToken(String secureValue, SProject contextProject)
Maps some secure value (password or api token) to some other token which can be safely stored in configuration files.String
mapTokenToSecureValue(String token, SProject contextProject)
Maps token to secure value if there is such a value in this credentials storage.void
onEncryptionChanged()
PersistTask
schedulePersistingCredentials(SProject project)
Schedules persisting of all tokens related to [project] to persistent storage.void
setSecureValuesForTokens(Map<String,String> tokens, SProject contextProject)
Save tokens and their secure values to credentials storage if no mapping for token exists
-
-
-
Field Detail
-
ALLOW_CHANGING_VALUES_FOR_TOKENS_PROPERTY
public static final String ALLOW_CHANGING_VALUES_FOR_TOKENS_PROPERTY
- See Also:
- Constant Field Values
-
CREDENTIALS_JSON_FILENAME
public static final String CREDENTIALS_JSON_FILENAME
- See Also:
- Constant Field Values
-
CREDENTIALS_FILE_PATH
public static final String CREDENTIALS_FILE_PATH
- See Also:
- Constant Field Values
-
STORAGE_TYPE
public static final String STORAGE_TYPE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ProjectCredentialsStorage
public ProjectCredentialsStorage(@NotNull EventDispatcher<BuildServerListener> eventDispatcher, @NotNull ProjectManager projectManager, @NotNull ProjectManagerErrors projectManagerErrors, @NotNull ServerResponsibilityEx serverResponsibility, @NotNull AccessChecker accessChecker, @NotNull SecurityContextEx securityContext, @NotNull EncryptionManager encryptionManager, @NotNull ConfigActionFactory configActionFactory, @NotNull ExecutorServices executorServices)
-
-
Method Detail
-
getType
@NotNull public String getType()
- Specified by:
getType
in interfaceCredentialsStorage
- Returns:
- type of this credentials storage. This type will be added by core API as a prefix to all tokens generated by this storage.
-
onEncryptionChanged
public void onEncryptionChanged()
- Specified by:
onEncryptionChanged
in interfaceEncryptionChangeListener
-
mapSecureValueToToken
@NotNull public String mapSecureValueToToken(@NotNull String secureValue, @NotNull SProject contextProject)
Description copied from interface:CredentialsStorage
Maps some secure value (password or api token) to some other token which can be safely stored in configuration files.- Specified by:
mapSecureValueToToken
in interfaceCredentialsStorage
- Parameters:
secureValue
- secure valuecontextProject
- context project where such mapping is performed- Returns:
- new or existing token corresponding to provided secure value
-
findTokenForSecureValue
@Nullable public String findTokenForSecureValue(@NotNull String secureValue, @NotNull SProject contextProject)
Description copied from interface:CredentialsStorage
Finds already existing token for the secure value- Specified by:
findTokenForSecureValue
in interfaceCredentialsStorage
- Parameters:
secureValue
- secure valuecontextProject
- context project where search is performed- Returns:
- existing token for the secure value or null if none found
-
beforeProjectSettingsLoaded
public void beforeProjectSettingsLoaded(@NotNull ProjectEx project)
-
mapTokenToSecureValue
@Nullable public String mapTokenToSecureValue(@NotNull String token, @NotNull SProject contextProject)
Description copied from interface:CredentialsStorage
Maps token to secure value if there is such a value in this credentials storage.- Specified by:
mapTokenToSecureValue
in interfaceCredentialsStorage
- Parameters:
token
- tokencontextProject
- context project where such mapping is performed- Returns:
- secure value corresponding to token pr null if there is no such value
-
getStoredValues
@NotNull public Map<String,String> getStoredValues(@NotNull SProject contextProject)
Description copied from interface:CredentialsStorageEx
Return all stored secure values for [contextProject]- Specified by:
getStoredValues
in interfaceCredentialsStorageEx
- Parameters:
contextProject
- context project to get all stored secure values for- Returns:
- map token -> secure value
-
schedulePersistingCredentials
@Nullable public PersistTask schedulePersistingCredentials(@NotNull SProject project)
Description copied from interface:CredentialsStorageEx
Schedules persisting of all tokens related to [project] to persistent storage. Returns task which can be used to wait for the persisting to complete. If returned task is null, then project did not have tokens.- Specified by:
schedulePersistingCredentials
in interfaceCredentialsStorageEx
-
deleteTokensFromProject
public void deleteTokensFromProject(@NotNull List<String> tokens, @NotNull SProject contextProject)
Description copied from interface:CredentialsStorageEx
Delete tokens from context project Requires explicit persist action after, see CredentialsStorageEx#schedulePersistingCredentials- Specified by:
deleteTokensFromProject
in interfaceCredentialsStorageEx
- Parameters:
tokens
- list of tokens to deletecontextProject
- project being edited
-
setSecureValuesForTokens
public void setSecureValuesForTokens(@NotNull Map<String,String> tokens, @NotNull SProject contextProject)
Description copied from interface:CredentialsStorageEx
Save tokens and their secure values to credentials storage if no mapping for token exists- Specified by:
setSecureValuesForTokens
in interfaceCredentialsStorageEx
- Parameters:
tokens
- map from token to secure value that should be storedcontextProject
- project being edited
-
findSecureValuesForTokens
@NotNull public Map<String,Map<String,String>> findSecureValuesForTokens(@NotNull Set<String> tokens, @NotNull List<SProject> contextProjects)
Description copied from interface:CredentialsStorageEx
Find all secure values for tokens in contextProjects For each token, different secure values can be found in different projects- Specified by:
findSecureValuesForTokens
in interfaceCredentialsStorageEx
- Parameters:
tokens
- list of tokens to find secure values forcontextProjects
- list of projects to search secure values in- Returns:
- map from token to map from project external id to secure value
-
copySecureValuesForTokens
public void copySecureValuesForTokens(@NotNull Map<String,SProject> tokenProjects, @NotNull SProject contextProject)
Description copied from interface:CredentialsStorageEx
Copy tokens to contextProject from tokenProjects.- Specified by:
copySecureValuesForTokens
in interfaceCredentialsStorageEx
- Parameters:
tokenProjects
- map from token to project. All tokens from this map will be copied to contextProjectcontextProject
- project to copy tokens to
-
-