Search in sources :

Example 1 with UserPasswordCredentials

use of org.eclipse.egit.core.securestorage.UserPasswordCredentials in project egit by eclipse.

the class RepositorySelectionPage method checkPage.

/**
 * Check the user input and set messages in case of invalid input.
 */
protected void checkPage() {
    if (isURISelected()) {
        assert uri != null;
        if (uriText.getText().length() == 0) {
            selectionIncomplete(null);
            return;
        } else if (uriText.getText().endsWith(" ")) {
            // $NON-NLS-1$
            selectionIncomplete(UIText.RepositorySelectionPage_UriMustNotHaveTrailingSpacesMessage);
            return;
        }
        try {
            final URIish finalURI = new URIish(GitUrlChecker.sanitizeAsGitUrl(uriText.getText()));
            String proto = finalURI.getScheme();
            if (proto == null && scheme.getSelectionIndex() >= 0)
                proto = scheme.getItem(scheme.getSelectionIndex());
            if (uri.getPath() == null) {
                selectionIncomplete(NLS.bind(UIText.RepositorySelectionPage_fieldRequired, unamp(UIText.RepositorySelectionPage_promptPath), proto));
                return;
            }
            if (Protocol.FILE.handles(finalURI)) {
                String badField = null;
                if (uri.getHost() != null)
                    badField = UIText.RepositorySelectionPage_promptHost;
                else if (uri.getUser() != null)
                    badField = UIText.RepositorySelectionPage_promptUser;
                else if (uri.getPass() != null)
                    badField = UIText.RepositorySelectionPage_promptPassword;
                if (badField != null) {
                    selectionIncomplete(NLS.bind(UIText.RepositorySelectionPage_fieldNotSupported, unamp(badField), proto));
                    return;
                }
                final File d = FS.DETECTED.resolve(new File("."), // $NON-NLS-1$
                uri.getPath());
                if (!d.exists()) {
                    selectionIncomplete(NLS.bind(UIText.RepositorySelectionPage_fileNotFound, d.getAbsolutePath()));
                    return;
                }
                selectionComplete(finalURI, null);
                return;
            }
            if (uri.getHost() == null) {
                selectionIncomplete(NLS.bind(UIText.RepositorySelectionPage_fieldRequired, unamp(UIText.RepositorySelectionPage_promptHost), proto));
                return;
            }
            if (Protocol.GIT.handles(finalURI)) {
                String badField = null;
                if (uri.getUser() != null)
                    badField = UIText.RepositorySelectionPage_promptUser;
                else if (uri.getPass() != null)
                    badField = UIText.RepositorySelectionPage_promptPassword;
                if (badField != null) {
                    selectionIncomplete(NLS.bind(UIText.RepositorySelectionPage_fieldNotSupported, unamp(badField), proto));
                    return;
                }
            }
            if (Protocol.HTTP.handles(finalURI) || Protocol.HTTPS.handles(finalURI)) {
                UserPasswordCredentials credentials = SecureStoreUtils.getCredentials(finalURI);
                if (credentials != null) {
                    String u = credentials.getUser();
                    String p = credentials.getPassword();
                    String uriUser = finalURI.getUser();
                    if (uriUser == null) {
                        if (setSafeUser(u) && setSafePassword(p))
                            setStoreInSecureStore(true);
                    } else if (uriUser.length() != 0 && uriUser.equals(u)) {
                        if (setSafePassword(p))
                            setStoreInSecureStore(true);
                    }
                }
            }
            selectionComplete(finalURI, null);
            return;
        } catch (URISyntaxException e) {
            selectionIncomplete(e.getReason());
            return;
        } catch (Exception e) {
            Activator.logError(NLS.bind(UIText.RepositorySelectionPage_errorValidating, getClass().getName()), e);
            selectionIncomplete(UIText.RepositorySelectionPage_internalError);
            return;
        }
    } else {
        assert remoteButton.getSelection();
        selectionComplete(null, remoteConfig);
        return;
    }
}
Also used : URIish(org.eclipse.jgit.transport.URIish) URISyntaxException(java.net.URISyntaxException) File(java.io.File) UserPasswordCredentials(org.eclipse.egit.core.securestorage.UserPasswordCredentials) URISyntaxException(java.net.URISyntaxException)

Example 2 with UserPasswordCredentials

use of org.eclipse.egit.core.securestorage.UserPasswordCredentials in project egit by eclipse.

the class EGitCredentialsProvider method get.

@Override
public boolean get(final URIish uri, final CredentialItem... items) throws UnsupportedCredentialItem {
    if (items.length == 0) {
        return true;
    }
    CredentialItem.Username userItem = null;
    CredentialItem.Password passwordItem = null;
    boolean isSpecial = false;
    for (CredentialItem item : items) {
        if (item instanceof CredentialItem.Username)
            userItem = (CredentialItem.Username) item;
        else if (item instanceof CredentialItem.Password)
            passwordItem = (CredentialItem.Password) item;
        else
            isSpecial = true;
    }
    if (!isSpecial && (userItem != null || passwordItem != null)) {
        UserPasswordCredentials credentials = null;
        if ((user != null) && (password != null))
            credentials = new UserPasswordCredentials(user, password);
        else
            credentials = SecureStoreUtils.getCredentials(uri);
        if (credentials == null) {
            credentials = getCredentialsFromUser(uri);
            if (credentials == null)
                return false;
        }
        if (userItem != null)
            userItem.setValue(credentials.getUser());
        if (passwordItem != null)
            passwordItem.setValue(credentials.getPassword().toCharArray());
        return true;
    }
    // special handling for non-user,non-password type items
    final boolean[] result = new boolean[1];
    PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

        @Override
        public void run() {
            Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
            if (items.length == 1) {
                CredentialItem item = items[0];
                result[0] = getSingleSpecial(shell, uri, item);
            } else {
                result[0] = getMultiSpecial(shell, uri, items);
            }
        }
    });
    return result[0];
}
Also used : Shell(org.eclipse.swt.widgets.Shell) CredentialItem(org.eclipse.jgit.transport.CredentialItem) UnsupportedCredentialItem(org.eclipse.jgit.errors.UnsupportedCredentialItem) UserPasswordCredentials(org.eclipse.egit.core.securestorage.UserPasswordCredentials)

Example 3 with UserPasswordCredentials

use of org.eclipse.egit.core.securestorage.UserPasswordCredentials in project egit by eclipse.

the class LoginService method changeCredentials.

/**
 * The method shows a change credentials dialog for a given URI. The user
 * field is taken from the URI if a user is present in the URI. In this case
 * the user is not editable.
 *
 * @param parent
 * @param uri
 * @return credentials, <code>null</code> if the user canceled the dialog.
 */
public static UserPasswordCredentials changeCredentials(Shell parent, URIish uri) {
    LoginDialog dialog = new LoginDialog(parent, uri);
    dialog.setChangeCredentials(true);
    UserPasswordCredentials oldCredentials = SecureStoreUtils.getCredentials(uri);
    if (oldCredentials != null)
        dialog.setOldUser(oldCredentials.getUser());
    if (dialog.open() == Window.OK) {
        UserPasswordCredentials credentials = dialog.getCredentials();
        if (credentials != null)
            SecureStoreUtils.storeCredentials(credentials, uri);
        return credentials;
    }
    return null;
}
Also used : UserPasswordCredentials(org.eclipse.egit.core.securestorage.UserPasswordCredentials)

Example 4 with UserPasswordCredentials

use of org.eclipse.egit.core.securestorage.UserPasswordCredentials in project egit by eclipse.

the class FetchWizard method performFinish.

@Override
public boolean performFinish() {
    boolean calledFromRepoPage = false;
    if (getContainer().getCurrentPage() == repoPage)
        calledFromRepoPage = true;
    if (repoPage.getSelection().isConfigSelected() && refSpecPage.isSaveRequested())
        saveConfig();
    if (repoPage.getStoreInSecureStore()) {
        if (!SecureStoreUtils.storeCredentials(repoPage.getCredentials(), repoPage.getSelection().getURI()))
            return false;
    }
    final FetchOperationUI op;
    int timeout = Activator.getDefault().getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT);
    final RepositorySelection repoSelection = repoPage.getSelection();
    if (calledFromRepoPage)
        op = new FetchOperationUI(localDb, repoSelection.getConfig(), timeout, false);
    else if (repoSelection.isConfigSelected())
        op = new FetchOperationUI(localDb, repoSelection.getConfig().getURIs().get(0), refSpecPage.getRefSpecs(), timeout, false);
    else
        op = new FetchOperationUI(localDb, repoSelection.getURI(false), refSpecPage.getRefSpecs(), timeout, false);
    UserPasswordCredentials credentials = repoPage.getCredentials();
    if (credentials != null)
        op.setCredentialsProvider(new EGitCredentialsProvider(credentials.getUser(), credentials.getPassword()));
    // add the RefSpecs from the RefSpec page into the FetchOperation
    if (!calledFromRepoPage)
        op.setTagOpt(refSpecPage.getTagOpt());
    op.start();
    repoPage.saveUriInPrefs();
    return true;
}
Also used : RepositorySelection(org.eclipse.egit.ui.internal.components.RepositorySelection) EGitCredentialsProvider(org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider) UserPasswordCredentials(org.eclipse.egit.core.securestorage.UserPasswordCredentials)

Example 5 with UserPasswordCredentials

use of org.eclipse.egit.core.securestorage.UserPasswordCredentials in project egit by eclipse.

the class PushWizard method performFinish.

@Override
public boolean performFinish() {
    boolean calledFromRepoPage = false;
    if (getContainer().getCurrentPage() == repoPage)
        calledFromRepoPage = true;
    if (repoPage.getSelection().isConfigSelected() && refSpecPage.isSaveRequested()) {
        saveRefSpecs();
    }
    if (repoPage.getStoreInSecureStore()) {
        if (!SecureStoreUtils.storeCredentials(repoPage.getCredentials(), repoPage.getSelection().getURI()))
            return false;
    }
    final PushOperation operation = createPushOperation(calledFromRepoPage);
    if (operation == null)
        return false;
    UserPasswordCredentials credentials = repoPage.getCredentials();
    if (credentials != null)
        operation.setCredentialsProvider(new EGitCredentialsProvider(credentials.getUser(), credentials.getPassword()));
    final PushOperationResult resultToCompare;
    if (confirmPage.isShowOnlyIfChangedSelected()) {
        resultToCompare = confirmPage.getConfirmedResult();
    } else {
        resultToCompare = null;
    }
    final Job job = new PushJob(NLS.bind(UIText.PushWizard_jobName, getURIsString(operation.getSpecification().getURIs())), localDb, operation, resultToCompare, getDestinationString(repoPage.getSelection()), true, PushMode.UPSTREAM);
    job.setUser(true);
    job.schedule();
    repoPage.saveUriInPrefs();
    return true;
}
Also used : PushOperationResult(org.eclipse.egit.core.op.PushOperationResult) PushOperation(org.eclipse.egit.core.op.PushOperation) Job(org.eclipse.core.runtime.jobs.Job) EGitCredentialsProvider(org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider) UserPasswordCredentials(org.eclipse.egit.core.securestorage.UserPasswordCredentials)

Aggregations

UserPasswordCredentials (org.eclipse.egit.core.securestorage.UserPasswordCredentials)6 EGitCredentialsProvider (org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider)3 File (java.io.File)2 URIish (org.eclipse.jgit.transport.URIish)2 URISyntaxException (java.net.URISyntaxException)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 Job (org.eclipse.core.runtime.jobs.Job)1 CloneOperation (org.eclipse.egit.core.op.CloneOperation)1 PostCloneTask (org.eclipse.egit.core.op.CloneOperation.PostCloneTask)1 PushOperation (org.eclipse.egit.core.op.PushOperation)1 PushOperationResult (org.eclipse.egit.core.op.PushOperationResult)1 RepositorySelection (org.eclipse.egit.ui.internal.components.RepositorySelection)1 UnsupportedCredentialItem (org.eclipse.jgit.errors.UnsupportedCredentialItem)1 Ref (org.eclipse.jgit.lib.Ref)1 Repository (org.eclipse.jgit.lib.Repository)1 CredentialItem (org.eclipse.jgit.transport.CredentialItem)1 CredentialsProvider (org.eclipse.jgit.transport.CredentialsProvider)1