IDEA-64891 don't store schema in remembered urls
authorKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Mon, 25 Apr 2011 08:54:40 +0000 (12:54 +0400)
committerKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Mon, 25 Apr 2011 12:02:16 +0000 (16:02 +0400)
Thus http and https paths to a repo will be treated as equal in terms of passwords.

plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandAuthenticator.java

index 948ac1fd63a7db2b40b04bac8c3c97b5c5c2ee14..485ca4baa7b80cc2a7dcb3d29ae01eb1dd669c72 100644 (file)
@@ -48,7 +48,8 @@ class HgCommandAuthenticator {
     // if checkbox is selected, remember on disk. Otherwise in memory. Don't read password safe settings.
 
     final PasswordSafeImpl passwordSafe = (PasswordSafeImpl)PasswordSafe.getInstance();
-    final String key = keyForUrlAndLogin(myRunnable.getURL(), myRunnable.getUserName());
+    final String url = stripSchemaFromUrl(myRunnable.getURL());
+    final String key = keyForUrlAndLogin(url, myRunnable.getUserName());
 
     final PasswordSafeProvider provider =
       myRunnable.isRememberPassword() ? passwordSafe.getMasterKeyProvider() : passwordSafe.getMemoryProvider();
@@ -56,7 +57,7 @@ class HgCommandAuthenticator {
       provider.storePassword(myProject, HgCommandAuthenticator.class, key, myRunnable.getPassword());
       final HgVcs vcs = HgVcs.getInstance(myProject);
       if (vcs != null) {
-        vcs.getGlobalSettings().addRememberedUrl(myRunnable.getURL(), myRunnable.getUserName());
+        vcs.getGlobalSettings().addRememberedUrl(url, myRunnable.getUserName());
       }
     }
     catch (PasswordSafeException e) {
@@ -64,6 +65,18 @@ class HgCommandAuthenticator {
     }
   }
 
+  /**
+   * Removes schema (protocol) part from url. For example, makes "bitbucket.org" from "http://bitbucket.org".
+   */
+  private static String stripSchemaFromUrl(String url) {
+    final String schemaSeparator = "://";
+    int ind = url.indexOf(schemaSeparator);
+    if (ind != -1) {
+      return url.substring(ind + schemaSeparator.length());
+    }
+    return url;
+  }
+
   public boolean promptForAuthentication(Project project, String proposedLogin, String uri, String path) {
     GetPasswordRunnable runnable = new GetPasswordRunnable(project, proposedLogin, uri, path);
     // Don't use Application#invokeAndWait here, as IntelliJ 
@@ -115,7 +128,7 @@ class HgCommandAuthenticator {
       final HgGlobalSettings hgGlobalSettings = vcs.getGlobalSettings();
       @Nullable String rememberedLoginsForUrl = null;
       if (!StringUtils.isBlank(myURL)) {
-        rememberedLoginsForUrl = hgGlobalSettings.getRememberedUserName(myURL);
+        rememberedLoginsForUrl = hgGlobalSettings.getRememberedUserName(stripSchemaFromUrl(myURL));
       }
 
       String login = myProposedLogin;