Search in sources :

Example 1 with CredentialsType

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());
}
Also used : CredentialsBase(com.oxygenxml.git.options.CredentialsBase) CredentialsType(com.oxygenxml.git.options.CredentialsBase.CredentialsType) UserAndPasswordCredentials(com.oxygenxml.git.options.UserAndPasswordCredentials) PersonalAccessTokenInfo(com.oxygenxml.git.options.PersonalAccessTokenInfo)

Example 2 with CredentialsType

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);
}
Also used : Arrays(java.util.Arrays) PullType(com.oxygenxml.git.view.event.PullType) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) WhenRepoDetectedInProject(com.oxygenxml.git.OxygenGitOptionPagePluginExtension.WhenRepoDetectedInProject) PluginWorkspace(ro.sync.exml.workspace.api.PluginWorkspace) Collection(java.util.Collection) WSOptionsStorage(ro.sync.exml.workspace.api.options.WSOptionsStorage) LoggerFactory(org.slf4j.LoggerFactory) OxygenGitPlugin(com.oxygenxml.git.OxygenGitPlugin) CredentialsType(com.oxygenxml.git.options.CredentialsBase.CredentialsType) ArrayList(java.util.ArrayList) List(java.util.List) PluginWorkspaceProvider(ro.sync.exml.workspace.api.PluginWorkspaceProvider) Map(java.util.Map) Optional(java.util.Optional) ResourcesViewMode(com.oxygenxml.git.view.staging.ChangesPanel.ResourcesViewMode) UtilAccess(ro.sync.exml.workspace.api.util.UtilAccess) PluginWorkspace(ro.sync.exml.workspace.api.PluginWorkspace) CredentialsType(com.oxygenxml.git.options.CredentialsBase.CredentialsType) UtilAccess(ro.sync.exml.workspace.api.util.UtilAccess)

Example 3 with CredentialsType

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);
    }
}
Also used : CredentialsType(com.oxygenxml.git.options.CredentialsBase.CredentialsType)

Aggregations

CredentialsType (com.oxygenxml.git.options.CredentialsBase.CredentialsType)3 WhenRepoDetectedInProject (com.oxygenxml.git.OxygenGitOptionPagePluginExtension.WhenRepoDetectedInProject)1 OxygenGitPlugin (com.oxygenxml.git.OxygenGitPlugin)1 CredentialsBase (com.oxygenxml.git.options.CredentialsBase)1 PersonalAccessTokenInfo (com.oxygenxml.git.options.PersonalAccessTokenInfo)1 UserAndPasswordCredentials (com.oxygenxml.git.options.UserAndPasswordCredentials)1 PullType (com.oxygenxml.git.view.event.PullType)1 ResourcesViewMode (com.oxygenxml.git.view.staging.ChangesPanel.ResourcesViewMode)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 PluginWorkspace (ro.sync.exml.workspace.api.PluginWorkspace)1 PluginWorkspaceProvider (ro.sync.exml.workspace.api.PluginWorkspaceProvider)1 WSOptionsStorage (ro.sync.exml.workspace.api.options.WSOptionsStorage)1