Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn2014-03-19 19:55:52 -0400
committerMatthias Sohn2014-03-24 09:13:58 -0400
commitbba4e7ff4321b0748d4687e0d40bbf23de5a81d3 (patch)
tree6e08c7f70bd921c6a00c9942f4de2d9ffe99acd6
parent7bc9127d75800fb4efeb47f60908da416cfec280 (diff)
downloadegit-bba4e7ff4321b0748d4687e0d40bbf23de5a81d3.tar.gz
egit-bba4e7ff4321b0748d4687e0d40bbf23de5a81d3.tar.xz
egit-bba4e7ff4321b0748d4687e0d40bbf23de5a81d3.zip
Init credentials from secure store on first page of clone wizard
This way the user can recognize that there are credentials available in the secure store for the URL he entered. Also this simplifies retry handling in jgit if authentication failed either since credentials changed or the user mistyped the credentials. Change-Id: I9f61f8897d45b37ce4dae648878d835330879f79 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RepositorySelectionPage.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RepositorySelectionPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RepositorySelectionPage.java
index 2752f727dd..ea4f7f9f87 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RepositorySelectionPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RepositorySelectionPage.java
@@ -20,6 +20,7 @@ import java.util.List;
import java.util.TreeMap;
import java.util.regex.Pattern;
+import org.eclipse.egit.core.securestorage.EGitSecureStore;
import org.eclipse.egit.core.securestorage.UserPasswordCredentials;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIPreferences;
@@ -30,6 +31,7 @@ import org.eclipse.egit.ui.internal.components.RemoteSelectionCombo.IRemoteSelec
import org.eclipse.egit.ui.internal.components.RemoteSelectionCombo.SelectionType;
import org.eclipse.egit.ui.internal.provisional.wizards.GitRepositoryInfo;
import org.eclipse.egit.ui.internal.provisional.wizards.IRepositorySearchResult;
+import org.eclipse.equinox.security.storage.StorageException;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.preference.IPreferenceStore;
@@ -814,6 +816,23 @@ public class RepositorySelectionPage extends WizardPage implements IRepositorySe
}
}
+ if (Protocol.HTTP.handles(finalURI)
+ || Protocol.HTTPS.handles(finalURI)) {
+ UserPasswordCredentials credentials = getSecureStoreCredentials(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) {
@@ -833,6 +852,40 @@ public class RepositorySelectionPage extends WizardPage implements IRepositorySe
}
}
+ private boolean setSafePassword(String p) {
+ if ((password == null || password.length() == 0) && p != null
+ && p.length() != 0) {
+ password = p;
+ passText.setText(p);
+ return true;
+ }
+ return false;
+ }
+
+ private boolean setSafeUser(String u) {
+ if ((user == null || user.length() == 0) && u != null
+ && u.length() != 0) {
+ user = u;
+ userText.setText(u);
+ return true;
+ }
+ return false;
+ }
+
+ private void setStoreInSecureStore(boolean store) {
+ storeInSecureStore = store;
+ storeCheckbox.setSelection(store);
+ }
+
+ private UserPasswordCredentials getSecureStoreCredentials(
+ final URIish finalURI) throws StorageException {
+ EGitSecureStore secureStore = org.eclipse.egit.core.Activator
+ .getDefault().getSecureStore();
+ UserPasswordCredentials credentials = secureStore
+ .getCredentials(finalURI);
+ return credentials;
+ }
+
private String unamp(String s) {
return s.replace("&", EMPTY_STRING); //$NON-NLS-1$
}

Back to the top