use of com.oxygenxml.git.auth.SSHCapableUserCredentialsProvider in project oxygen-git-client-addon by oxygenxml.
the class GitAccess method doListRemoteBranchesInternal.
/**
* Do list remote branches internal.
*
* @param repoURL The repository URL.
* @param excMessPresenter Exception message presenter.
*
* @return the remote branches or an empty list.
*/
public Collection<Ref> doListRemoteBranchesInternal(URIish repoURL, AuthExceptionMessagePresenter excMessPresenter) {
Collection<Ref> remoteRefs = Collections.emptySet();
String host = repoURL.getHost();
boolean shouldStopTryingLogin = false;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("START LISTING REMOTE BRANCHES FOR: " + repoURL);
}
do {
SSHCapableUserCredentialsProvider credentialsProvider = AuthUtil.getCredentialsProvider(host);
try {
LOGGER.debug("Now do list the remote branches...");
remoteRefs = Git.lsRemoteRepository().setHeads(true).setRemote(repoURL.toString()).setCredentialsProvider(credentialsProvider).call();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("BRANCHES: " + remoteRefs);
}
shouldStopTryingLogin = true;
} catch (TransportException ex) {
LOGGER.debug(ex.getMessage(), ex);
boolean retryLogin = AuthUtil.handleAuthException(ex, host, excMessPresenter, !credentialsProvider.wasResetCalled());
if (!retryLogin || credentialsProvider.shouldCancelLogin()) {
LOGGER.debug("STOP TRYING TO LOGIN!");
shouldStopTryingLogin = true;
}
} catch (GitAPIException e) {
LOGGER.error(e.getMessage(), e);
}
} while (!shouldStopTryingLogin);
return remoteRefs;
}
use of com.oxygenxml.git.auth.SSHCapableUserCredentialsProvider in project oxygen-git-client-addon by oxygenxml.
the class GitAccess method fetch.
/**
* Brings all the commits to the local repository but does not merge them.
*
* @throws SSHPassphraseRequiredException
* @throws PrivateRepositoryException
* @throws RepositoryUnavailableException
*/
public void fetch() throws SSHPassphraseRequiredException, PrivateRepositoryException, RepositoryUnavailableException {
LOGGER.debug("Begin fetch");
if (git == null) {
throw new RepositoryUnavailableException(new NoRepositorySelected("Repository is empty"));
}
AuthenticationInterceptor.install();
SSHCapableUserCredentialsProvider credentialsProvider = AuthUtil.getCredentialsProvider(getHostName());
try {
StoredConfig config = git.getRepository().getConfig();
Set<String> sections = config.getSections();
if (sections.contains(ConfigConstants.CONFIG_KEY_REMOTE)) {
git.fetch().setRefSpecs(new RefSpec("+refs/heads/*:refs/remotes/" + getRemoteFromCurrentBranch() + "/*")).setCheckFetchedObjects(true).setRemote(getRemoteFromCurrentBranch()).setRemoveDeletedRefs(true).setCredentialsProvider(credentialsProvider).call();
}
} catch (TransportException e) {
LOGGER.debug(e.getMessage(), e);
Throwable cause = e;
while (cause.getCause() != null) {
cause = cause.getCause();
}
String message = e.getMessage();
if (message != null && (message.contains("Authentication is required but no CredentialsProvider has been registered") || message.contains(AuthUtil.NOT_AUTHORIZED))) {
throw new PrivateRepositoryException(e);
} else if (message != null && message.toLowerCase().contains(AuthUtil.AUTH_FAIL) && credentialsProvider.isPassphaseRequested() || (cause instanceof SshException) && ((SshException) cause).getDisconnectCode() == SshConstants.SSH2_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE) {
throw new SSHPassphraseRequiredException(e);
} else {
throw new RepositoryUnavailableException(e);
}
} catch (GitAPIException | RevisionSyntaxException e) {
LOGGER.error(e.getMessage(), e);
}
LOGGER.debug("End fetch");
}
use of com.oxygenxml.git.auth.SSHCapableUserCredentialsProvider in project oxygen-git-client-addon by oxygenxml.
the class GitTestBase method pushOneFileToRemote.
/**
* Loads the repository and pushes one file to the remote.
*
* @throws Exception If it fails.
*/
protected final void pushOneFileToRemote(String repository, String fileName, String fileContent) throws Exception {
commitOneFile(repository, fileName, fileContent);
GitAccess.getInstance().push(new SSHCapableUserCredentialsProvider("", "", "", GitAccess.getInstance().getHostName()));
}
Aggregations