use of com.oxygenxml.git.options.CredentialsBase.CredentialsType in project oxygen-git-client-addon by oxygenxml.
the class AuthUtil method getCredentialsProvider.
/**
* Get the credentials provider for the given host.
*
* @param host The host.
*
* @return The credentials provider.
*/
public static SSHCapableUserCredentialsProvider getCredentialsProvider(String host) {
CredentialsBase credentials = OptionsManager.getInstance().getGitCredentials(host);
CredentialsType credentialsType = credentials.getType();
return new SSHCapableUserCredentialsProvider(credentialsType == CredentialsType.USER_AND_PASSWORD ? ((UserAndPasswordCredentials) credentials).getUsername() : ((PersonalAccessTokenInfo) credentials).getTokenValue(), credentialsType == CredentialsType.USER_AND_PASSWORD ? ((UserAndPasswordCredentials) credentials).getPassword() : ((PersonalAccessTokenInfo) credentials).getTokenValue(), OptionsManager.getInstance().getSshPassphrase(), credentials.getHost());
}
use of com.oxygenxml.git.options.CredentialsBase.CredentialsType in project oxygen-git-client-addon by oxygenxml.
the class OptionsManager method getGitCredentials.
/**
* Loads the user credentials for git push and pull
*
* @param host Host.
*
* @return the credentials. Never <code>null</code>.
*/
public CredentialsBase getGitCredentials(String host) {
String username = null;
String decryptedPassword = null;
String decryptedToken = null;
CredentialsType detectedCredentialsType = null;
if (host != null) {
Optional<CredentialsBase> credential = getAllCredentials().stream().filter(c -> c.getHost().equals(host)).findFirst();
if (credential.isPresent()) {
CredentialsBase credentialsBase = credential.get();
PluginWorkspace saPluginWS = PluginWorkspaceProvider.getPluginWorkspace();
UtilAccess utilAccess = saPluginWS.getUtilAccess();
detectedCredentialsType = credentialsBase.getType();
if (detectedCredentialsType == CredentialsType.USER_AND_PASSWORD) {
username = ((UserAndPasswordCredentials) credentialsBase).getUsername();
decryptedPassword = utilAccess.decrypt(((UserAndPasswordCredentials) credentialsBase).getPassword());
} else if (detectedCredentialsType == CredentialsType.PERSONAL_ACCESS_TOKEN) {
decryptedToken = utilAccess.decrypt(((PersonalAccessTokenInfo) credentialsBase).getTokenValue());
}
}
}
return detectedCredentialsType != null && detectedCredentialsType == CredentialsType.PERSONAL_ACCESS_TOKEN ? new PersonalAccessTokenInfo(host, decryptedToken) : new UserAndPasswordCredentials(username, decryptedPassword, host);
}
use of com.oxygenxml.git.options.CredentialsBase.CredentialsType in project oxygen-git-client-addon by oxygenxml.
the class OptionsManager method saveGitCredentials.
/**
* Saves the user credentials.
*
* @param credentials The credentials to be saved.
*/
public void saveGitCredentials(CredentialsBase credentials) {
if (credentials != null) {
// Keep only one type of credentials for a host
CredentialsType type = credentials.getType();
if (type == CredentialsType.USER_AND_PASSWORD) {
saveUserAndPasswordCredentials((UserAndPasswordCredentials) credentials);
savePersonalAccessToken(null);
} else if (type == CredentialsType.PERSONAL_ACCESS_TOKEN) {
savePersonalAccessToken((PersonalAccessTokenInfo) credentials);
saveUserAndPasswordCredentials(null);
}
} else {
saveUserAndPasswordCredentials(null);
savePersonalAccessToken(null);
}
}
Aggregations