From bba4e7ff4321b0748d4687e0d40bbf23de5a81d3 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Thu, 20 Mar 2014 00:55:52 +0100 Subject: 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 --- .../components/RepositorySelectionPage.java | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) 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$ } -- cgit v1.2.3