use UUID instead of incremental int id
authorVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Mon, 18 Apr 2016 14:01:17 +0000 (16:01 +0200)
committerVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Fri, 22 Apr 2016 13:16:44 +0000 (15:16 +0200)
plugins/git4idea/rt/src/org/jetbrains/git4idea/http/GitAskPassApp.java
plugins/git4idea/rt/src/org/jetbrains/git4idea/http/GitAskPassXmlRpcClient.java
plugins/git4idea/rt/src/org/jetbrains/git4idea/http/GitAskPassXmlRpcHandler.java
plugins/git4idea/rt/src/org/jetbrains/git4idea/ssh/GitSSHHandler.java
plugins/git4idea/rt/src/org/jetbrains/git4idea/ssh/GitSSHXmlRpcClient.java
plugins/git4idea/rt/src/org/jetbrains/git4idea/ssh/SSHMain.java
plugins/git4idea/src/git4idea/commands/GitHandler.java
plugins/git4idea/src/git4idea/commands/GitHttpAuthService.java
plugins/git4idea/src/git4idea/rebase/GitRebaseEditorService.java
plugins/git4idea/src/org/jetbrains/git4idea/ssh/GitXmlRpcHandlerService.java
plugins/git4idea/src/org/jetbrains/git4idea/ssh/GitXmlRpcSshService.java

index 8c8e425570a2f600f2fd467799d26c1e227f997f..8ce927804e52b8146282ea81d95761bdedc49339 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -56,16 +56,16 @@ public class GitAskPassApp implements GitExternalApp {
       boolean usernameNeeded = arguments.getFirst();
       String url = arguments.getSecond();
 
-      int handler = Integer.parseInt(getNotNull(GitAskPassXmlRpcHandler.GIT_ASK_PASS_HANDLER_ENV));
+      String token = getNotNull(GitAskPassXmlRpcHandler.GIT_ASK_PASS_HANDLER_ENV);
       int xmlRpcPort = Integer.parseInt(getNotNull(GitAskPassXmlRpcHandler.GIT_ASK_PASS_PORT_ENV));
       GitAskPassXmlRpcClient xmlRpcClient = new GitAskPassXmlRpcClient(xmlRpcPort);
 
       if (usernameNeeded) {
-        String username = xmlRpcClient.askUsername(handler, url);
+        String username = xmlRpcClient.askUsername(token, url);
         System.out.println(username);
       }
       else {
-        String pass = xmlRpcClient.askPassword(handler, url);
+        String pass = xmlRpcClient.askPassword(token, url);
         System.out.println(pass);
       }
     }
@@ -77,11 +77,11 @@ public class GitAskPassApp implements GitExternalApp {
 
   @NotNull
   private static String getNotNull(@NotNull String env) {
-    String handlerValue = System.getenv(env);
-    if (handlerValue == null) {
+    String value = System.getenv(env);
+    if (value == null) {
       throw new IllegalStateException(env + " environment variable is not defined!");
     }
-    return handlerValue;
+    return value;
   }
 
   @NotNull
index 5d3f8681f0990e60e75aa3b87c595d3c8a2bf755..85e49697416ed35dbf805a66a819bd49d844ca51 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -38,9 +38,9 @@ class GitAskPassXmlRpcClient {
 
   // Obsolete collection usage because of the XmlRpcClientLite API
   @SuppressWarnings({"UseOfObsoleteCollectionType", "unchecked"})
-  String askUsername(int handler, @NotNull String url) {
+  String askUsername(String token, @NotNull String url) {
     Vector parameters = new Vector();
-    parameters.add(handler);
+    parameters.add(token);
     parameters.add(url);
 
     try {
@@ -56,9 +56,9 @@ class GitAskPassXmlRpcClient {
 
   // Obsolete collection usage because of the XmlRpcClientLite API
   @SuppressWarnings({"UseOfObsoleteCollectionType", "unchecked"})
-  String askPassword(int handler, @NotNull String url) {
+  String askPassword(String token, @NotNull String url) {
     Vector parameters = new Vector();
-    parameters.add(handler);
+    parameters.add(token);
     parameters.add(url);
 
     try {
index 36cc365c1d80040b6c66c22fd1caea5d3fe6e632..9c9900a1f3caceb518231713c0d6b5429d5325cb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -31,25 +31,25 @@ public interface GitAskPassXmlRpcHandler {
 
   /**
    * Get the username from the user to access the given URL.
-   * @param handler XML RPC handler number.
+   * @param token   Access token.
    * @param url     URL which Git tries to access.
    * @return The Username which should be used for the URL.
    */
   // UnusedDeclaration suppressed: the method is used via XML RPC
   @SuppressWarnings("UnusedDeclaration")
   @NotNull
-  String askUsername(int handler, @NotNull String url);
+  String askUsername(String token, @NotNull String url);
 
   /**
    * Get the password from the user to access the given URL.
    * It is assumed that the username either is specified in the URL (http://username@host.com), or has been asked earlier.
-   * @param handler XML RPC handler number.
+   * @param token   Access token.
    * @param url     URL which Git tries to access.
    * @return The password which should be used for the URL.
    */
   // UnusedDeclaration suppressed: the method is used via XML RPC
   @SuppressWarnings("UnusedDeclaration")
   @NotNull
-  String askPassword(int handler, @NotNull String url);
+  String askPassword(String token, @NotNull String url);
 
 }
index 2bc849d83fb0d94c42107a8b8d31983f1429cb26..4ce4ea31b6a25d87152f1ed7aa28e7ab1f028839 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -29,16 +29,10 @@ public interface GitSSHHandler {
    */
   @NonNls String GIT_SSH_PREFIX = "git-ssh-";
   /**
-   * Name of environment variable for SSH handler number
+   * Name of environment variable for SSH handler access token
    */
   @NonNls String SSH_HANDLER_ENV = "GIT4IDEA_SSH_HANDLER";
-  /**
-   * Name of environment variable for SSH handler number
-   */
   @NonNls String SSH_IGNORE_KNOWN_HOSTS_ENV = "GIT4IDEA_SSH_IGNORE_KNOWN_HOSTS";
-  /**
-   * Name of environment variable for SSH handler
-   */
   @NonNls String SSH_PORT_ENV = "GIT4IDEA_SSH_PORT";
   /**
    * Name of environment variable for SSH executable
@@ -60,7 +54,7 @@ public interface GitSSHHandler {
   /**
    * Verify server host key
    *
-   * @param handler                  a handler identifier
+   * @param token                    Access token.
    * @param hostName                 a host name
    * @param port                     a port number
    * @param serverHostKeyAlgorithm   an algorithm
@@ -68,7 +62,7 @@ public interface GitSSHHandler {
    * @param isNew                    true if the key is a new, false if the key was changed
    * @return true the host is verified, false otherwise
    */
-  boolean verifyServerHostKey(int handler,
+  boolean verifyServerHostKey(String token,
                               String hostName,
                               int port,
                               String serverHostKeyAlgorithm,
@@ -78,7 +72,7 @@ public interface GitSSHHandler {
   /**
    * Ask passphrase for the key
    *
-   * @param handler       a handler identifier
+   * @param token       Access token.
    * @param userName      a name of user
    * @param keyPath       a path for the key
    * @param resetPassword a reset password if one was stored in password database
@@ -86,12 +80,12 @@ public interface GitSSHHandler {
    * @return the passphrase entered by the user
    */
   @Nullable
-  String askPassphrase(final int handler, final String userName, final String keyPath, boolean resetPassword, final String lastError);
+  String askPassphrase(String token, final String userName, final String keyPath, boolean resetPassword, final String lastError);
 
   /**
    * Reply to challenge for keyboard-interactive method. Also used for
    *
-   * @param handlerNo   a handler identifier
+   * @param token   Access token.
    * @param userName    a user name (includes host and port)
    * @param name        name of challenge
    * @param instruction instruction
@@ -103,7 +97,7 @@ public interface GitSSHHandler {
    */
   @SuppressWarnings({"UseOfObsoleteCollectionType"})
   @Nullable
-  Vector<String> replyToChallenge(final int handlerNo,
+  Vector<String> replyToChallenge(String token,
                                   final String userName,
                                   final String name,
                                   final String instruction,
@@ -115,19 +109,19 @@ public interface GitSSHHandler {
   /**
    * Ask password for the specified user name
    *
-   * @param handlerNo     a handler identifier
+   * @param token         Access token.
    * @param userName      a name of user to ask password for
    * @param resetPassword a reset password if one was stored in password database
    * @param lastError     a last error
    * @return the password or null if authentication failed.
    */
   @Nullable
-  String askPassword(final int handlerNo, final String userName, boolean resetPassword, final String lastError);
+  String askPassword(String token, final String userName, boolean resetPassword, final String lastError);
 
   /**
    * Notify invoker about last successful authentication attempt.
    *
-   * @param handlerNo the handler
+   * @param token the handler
    * @param userName  the user name
    * @param method    the authentication method, the empty string means that authentication failed
    * @param error     the error shown in the case when authentication process failed
@@ -135,14 +129,14 @@ public interface GitSSHHandler {
    * @return The method doesn't return any sensible value, but it is needed here, since the Apache XML-RPC implementation which we use
    *         doesn't allow void methods: "IllegalArgumentException: void return types for handler methods not supported".
    */
-  String setLastSuccessful(final int handlerNo, final String userName, final String method, final String error);
+  String setLastSuccessful(String token, final String userName, final String method, final String error);
 
   /**
    * Get last successful authentication method
    *
-   * @param handlerNo the handler no
+   * @param token Access token
    * @param userName  the user name
    * @return the authentication method, the empty string means that last authentication failed
    */
-  String getLastSuccessful(final int handlerNo, final String userName);
+  String getLastSuccessful(String token, final String userName);
 }
index c4ddd216e1cd08a67816981531dcffca2b5c6a3c..593362a3ee8eef3ccfa97d3f1d1d607130005a02 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -49,7 +49,7 @@ public class GitSSHXmlRpcClient implements GitSSHHandler {
    * {@inheritDoc}
    */
   @SuppressWarnings("unchecked")
-  public boolean verifyServerHostKey(final int handler,
+  public boolean verifyServerHostKey(String token,
                                      final String hostname,
                                      final int port,
                                      final String serverHostKeyAlgorithm,
@@ -59,7 +59,7 @@ public class GitSSHXmlRpcClient implements GitSSHHandler {
       return false;
     }
     Vector parameters = new Vector();
-    parameters.add(handler);
+    parameters.add(token);
     parameters.add(hostname);
     parameters.add(port);
     parameters.add(serverHostKeyAlgorithm);
@@ -91,7 +91,7 @@ public class GitSSHXmlRpcClient implements GitSSHHandler {
    */
   @Nullable
   @SuppressWarnings("unchecked")
-  public String askPassphrase(final int handler,
+  public String askPassphrase(String token,
                               final String username,
                               final String keyPath,
                               final boolean resetPassword,
@@ -100,7 +100,7 @@ public class GitSSHXmlRpcClient implements GitSSHHandler {
       return null;
     }
     Vector parameters = new Vector();
-    parameters.add(handler);
+    parameters.add(token);
     parameters.add(username);
     parameters.add(keyPath);
     parameters.add(resetPassword);
@@ -121,7 +121,7 @@ public class GitSSHXmlRpcClient implements GitSSHHandler {
    */
   @Nullable
   @SuppressWarnings("unchecked")
-  public Vector<String> replyToChallenge(final int handlerNo,
+  public Vector<String> replyToChallenge(String token,
                                          final String username,
                                          final String name,
                                          final String instruction,
@@ -133,7 +133,7 @@ public class GitSSHXmlRpcClient implements GitSSHHandler {
       return null;
     }
     Vector parameters = new Vector();
-    parameters.add(handlerNo);
+    parameters.add(token);
     parameters.add(username);
     parameters.add(name);
     parameters.add(instruction);
@@ -157,12 +157,12 @@ public class GitSSHXmlRpcClient implements GitSSHHandler {
    */
   @Nullable
   @SuppressWarnings("unchecked")
-  public String askPassword(final int handlerNo, final String username, final boolean resetPassword, final String lastError) {
+  public String askPassword(String token, final String username, final boolean resetPassword, final String lastError) {
     if (myClient == null) {
       return null;
     }
     Vector parameters = new Vector();
-    parameters.add(handlerNo);
+    parameters.add(token);
     parameters.add(username);
     parameters.add(resetPassword);
     parameters.add(lastError);
@@ -179,12 +179,12 @@ public class GitSSHXmlRpcClient implements GitSSHHandler {
 
   @Override
   @SuppressWarnings("unchecked")
-  public String setLastSuccessful(int handlerNo, String userName, String method, String error) {
+  public String setLastSuccessful(String token, String userName, String method, String error) {
     if (myClient == null) {
       return "";
     }
     Vector parameters = new Vector();
-    parameters.add(handlerNo);
+    parameters.add(token);
     parameters.add(userName);
     parameters.add(method);
     parameters.add(error);
@@ -204,22 +204,22 @@ public class GitSSHXmlRpcClient implements GitSSHHandler {
    */
   @Override
   @SuppressWarnings("unchecked")
-  public String getLastSuccessful(int handlerNo, String userName) {
+  public String getLastSuccessful(String token, String userName) {
     if (myClient == null) {
       return "";
     }
     Vector parameters = new Vector();
-    parameters.add(handlerNo);
+    parameters.add(token);
     parameters.add(userName);
     try {
       return (String)myClient.execute(methodName("getLastSuccessful"), parameters);
     }
     catch (XmlRpcException e) {
-      log("getLastSuccessful failed. handlerNo: " + handlerNo + ", userName: " + userName + ", client: " + myClient.getURL());
+      log("getLastSuccessful failed. token: " + token + ", userName: " + userName + ", client: " + myClient.getURL());
       throw new RuntimeException("Invocation failed " + e.getMessage(), e);
     }
     catch (IOException e) {
-      log("getLastSuccessful failed. handlerNo: " + handlerNo + ", userName: " + userName + ", client: " + myClient.getURL());
+      log("getLastSuccessful failed. token: " + token + ", userName: " + userName + ", client: " + myClient.getURL());
       throw new RuntimeException("Invocation failed " + e.getMessage(), e);
     }
   }
index b5bc260b95205032ebb61d238c54e188e0b806a5..67a74b92b0ac680fe8ec51b27c4af5859d235b00 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@ public class SSHMain implements GitExternalApp {
   /**
    * Handler number
    */
-  private final int myHandlerNo;
+  private final String myHandlerNo;
   /**
    * the xml RPC port
    */
@@ -120,7 +120,7 @@ public class SSHMain implements GitExternalApp {
   private SSHMain(String host, String username, Integer port, String command) throws IOException {
     SSHConfig config = SSHConfig.load();
     myHost = config.lookup(username, host, port);
-    myHandlerNo = Integer.parseInt(System.getenv(GitSSHHandler.SSH_HANDLER_ENV));
+    myHandlerNo = System.getenv(GitSSHHandler.SSH_HANDLER_ENV);
     int xmlRpcPort = Integer.parseInt(System.getenv(GitSSHHandler.SSH_PORT_ENV));
     myXmlRpcClient = new GitSSHXmlRpcClient(xmlRpcPort, myHost.isBatchMode());
     myCommand = command;
index ef234be8808765ec7d585eee09dfb9dc2d15714c..52aec9f6388e50951f68a6a82a34c63e7143c579 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -89,8 +89,8 @@ public abstract class GitHandler {
   private final File myWorkingDirectory;
 
   private boolean myEnvironmentCleanedUp = true; // the flag indicating that environment has been cleaned up, by default is true because there is nothing to clean
-  private int mySshHandler = -1;
-  private int myHttpHandler = -1;
+  private UUID mySshHandler;
+  private UUID myHttpHandler;
   private Processor<OutputStream> myInputProcessor; // The processor for stdin
 
   // if true process might be cancelled
@@ -463,7 +463,7 @@ public abstract class GitHandler {
     GitHttpAuthenticator httpAuthenticator = service.createAuthenticator(myProject, myCommand, ObjectUtils.assertNotNull(myUrls));
     myHttpHandler = service.registerHandler(httpAuthenticator, myProject);
     myEnvironmentCleanedUp = false;
-    myEnv.put(GitAskPassXmlRpcHandler.GIT_ASK_PASS_HANDLER_ENV, Integer.toString(myHttpHandler));
+    myEnv.put(GitAskPassXmlRpcHandler.GIT_ASK_PASS_HANDLER_ENV, myHttpHandler.toString());
     int port = service.getXmlRcpPort();
     myEnv.put(GitAskPassXmlRpcHandler.GIT_ASK_PASS_PORT_ENV, Integer.toString(port));
     LOG.debug(String.format("handler=%s, port=%s", myHttpHandler, port));
@@ -475,7 +475,7 @@ public abstract class GitHandler {
     myEnv.put(GitSSHHandler.GIT_SSH_ENV, ssh.getScriptPath().getPath());
     mySshHandler = ssh.registerHandler(new GitSSHGUIHandler(myProject), myProject);
     myEnvironmentCleanedUp = false;
-    myEnv.put(GitSSHHandler.SSH_HANDLER_ENV, Integer.toString(mySshHandler));
+    myEnv.put(GitSSHHandler.SSH_HANDLER_ENV, mySshHandler.toString());
     int port = ssh.getXmlRcpPort();
     myEnv.put(GitSSHHandler.SSH_PORT_ENV, Integer.toString(port));
     LOG.debug(String.format("handler=%s, port=%s", mySshHandler, port));
@@ -602,10 +602,10 @@ public abstract class GitHandler {
     if (myEnvironmentCleanedUp) {
       return;
     }
-    if (mySshHandler >= 0) {
+    if (mySshHandler != null) {
       ServiceManager.getService(GitXmlRpcSshService.class).unregisterHandler(mySshHandler);
     }
-    if (myHttpHandler >= 0) {
+    if (myHttpHandler != null) {
       ServiceManager.getService(GitHttpAuthService.class).unregisterHandler(myHttpHandler);
     }
     myEnvironmentCleanedUp = true;
index 6ddbcab22147b9f4ee7fc07e70cb842022fa8566..7cc1a8deb06cef22fef593ff5ca54195404198f6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ import org.jetbrains.git4idea.ssh.GitXmlRpcHandlerService;
 import org.jetbrains.git4idea.util.ScriptGenerator;
 
 import java.util.Collection;
+import java.util.UUID;
 
 /**
  * Provides the authentication mechanism for Git HTTP connections.
@@ -57,14 +58,14 @@ public abstract class GitHttpAuthService extends GitXmlRpcHandlerService<GitHttp
   public class InternalRequestHandlerDelegate implements GitAskPassXmlRpcHandler {
     @NotNull
     @Override
-    public String askUsername(int handler, @NotNull String url) {
-      return getHandler(handler).askUsername(url);
+    public String askUsername(String token, @NotNull String url) {
+      return getHandler(UUID.fromString(token)).askUsername(url);
     }
 
     @NotNull
     @Override
-    public String askPassword(int handler, @NotNull String url) {
-      return getHandler(handler).askPassword(url);
+    public String askPassword(String token, @NotNull String url) {
+      return getHandler(UUID.fromString(token)).askPassword(url);
     }
   }
 
index ea9d7ab8c2c07c5a5d7e575215b0d3cc5598ef4c..78874b69f6a0448892626a62fed94970fb830e6f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@ import org.jetbrains.annotations.NotNull;
 import org.jetbrains.git4idea.util.ScriptGenerator;
 import org.jetbrains.ide.BuiltInServerManager;
 
+import java.security.SecureRandom;
 import java.util.Map;
 import java.util.Random;
 
@@ -53,7 +54,7 @@ public class GitRebaseEditorService {
   /**
    * Random number generator
    */
-  private static final Random oursRandom = new Random();
+  private static final Random oursRandom = new SecureRandom();
   /**
    * The prefix for rebase editors
    */
index 12c99d9d26ad6ff5da929837a40558e62ae15d3e..a07b2d63d235257e1871a917b608e796a07411fd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@ import org.jetbrains.ide.BuiltInServerManager;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.UUID;
 
 /**
  * <p>The provider of external application scripts called by Git when a remote operation needs communication with the user.</p>
@@ -57,8 +58,7 @@ public abstract class GitXmlRpcHandlerService<T> {
   @Nullable private File myScriptPath;
   @NotNull private final Object SCRIPT_FILE_LOCK = new Object();
 
-  @NotNull private final THashMap<Integer, T> handlers = new THashMap<Integer, T>();
-  private int myNextHandlerKey;
+  @NotNull private final THashMap<UUID, T> handlers = new THashMap<UUID, T>();
   @NotNull private final Object HANDLERS_LOCK = new Object();
 
   /**
@@ -111,14 +111,14 @@ public abstract class GitXmlRpcHandlerService<T> {
    * @param parentDisposable a disposable to unregister the handler if it doesn't get unregistered manually
    * @return an identifier to pass to the environment variable
    */
-  public int registerHandler(@NotNull T handler, @NotNull Disposable parentDisposable) {
+  public UUID registerHandler(@NotNull T handler, @NotNull Disposable parentDisposable) {
     synchronized (HANDLERS_LOCK) {
       XmlRpcServer xmlRpcServer = XmlRpcServer.SERVICE.getInstance();
       if (!xmlRpcServer.hasHandler(myHandlerName)) {
         xmlRpcServer.addHandler(myHandlerName, createRpcRequestHandlerDelegate());
       }
 
-      final int key = myNextHandlerKey;
+      final UUID key = UUID.randomUUID();
       handlers.put(key, handler);
       Disposer.register(parentDisposable, new Disposable() {
         @Override
@@ -126,7 +126,6 @@ public abstract class GitXmlRpcHandlerService<T> {
           handlers.remove(key);
         }
       });
-      myNextHandlerKey++;
       return key;
     }
   }
@@ -146,7 +145,7 @@ public abstract class GitXmlRpcHandlerService<T> {
    * @return the registered handler
    */
   @NotNull
-  protected T getHandler(int key) {
+  protected T getHandler(UUID key) {
     synchronized (HANDLERS_LOCK) {
       T rc = handlers.get(key);
       if (rc == null) {
@@ -161,7 +160,7 @@ public abstract class GitXmlRpcHandlerService<T> {
    *
    * @param key the key to unregister
    */
-  public void unregisterHandler(int key) {
+  public void unregisterHandler(UUID key) {
     synchronized (HANDLERS_LOCK) {
       if (handlers.remove(key) == null) {
         throw new IllegalArgumentException("The handler " + key + " is not registered");
index 5d802d36e065965c91231b8734a40ef092d8528b..9b03e6db8c940cc0a100139ee54c13b88c310f95 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import git4idea.commands.GitSSHGUIHandler;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.git4idea.util.ScriptGenerator;
 
+import java.util.UUID;
 import java.util.Vector;
 
 /**
@@ -49,37 +50,37 @@ public class GitXmlRpcSshService extends GitXmlRpcHandlerService<GitSSHGUIHandle
   public class InternalRequestHandler implements GitSSHHandler {
 
     @Override
-    public boolean verifyServerHostKey(int handler, String hostname, int port, String serverHostKeyAlgorithm, String serverHostKey,
+    public boolean verifyServerHostKey(String handler, String hostname, int port, String serverHostKeyAlgorithm, String serverHostKey,
                                        boolean isNew) {
-      return getHandler(handler).verifyServerHostKey(hostname, port, serverHostKeyAlgorithm, serverHostKey, isNew);
+      return getHandler(UUID.fromString(handler)).verifyServerHostKey(hostname, port, serverHostKeyAlgorithm, serverHostKey, isNew);
     }
 
     @Override
-    public String askPassphrase(int handler, String username, String keyPath, boolean resetPassword, String lastError) {
-      return adjustNull(getHandler(handler).askPassphrase(username, keyPath, resetPassword, lastError));
+    public String askPassphrase(String handler, String username, String keyPath, boolean resetPassword, String lastError) {
+      return adjustNull(getHandler(UUID.fromString(handler)).askPassphrase(username, keyPath, resetPassword, lastError));
     }
 
     @Override
     @SuppressWarnings({"UseOfObsoleteCollectionType"})
-    public Vector<String> replyToChallenge(int handlerNo, String username, String name, String instruction, int numPrompts,
+    public Vector<String> replyToChallenge(String token, String username, String name, String instruction, int numPrompts,
                                            Vector<String> prompt, Vector<Boolean> echo, String lastError) {
-      return adjustNull(getHandler(handlerNo).replyToChallenge(username, name, instruction, numPrompts, prompt, echo, lastError));
+      return adjustNull(getHandler(UUID.fromString(token)).replyToChallenge(username, name, instruction, numPrompts, prompt, echo, lastError));
     }
 
     @Override
-    public String askPassword(int handlerNo, String username, boolean resetPassword, String lastError) {
-      return adjustNull(getHandler(handlerNo).askPassword(username, resetPassword, lastError));
+    public String askPassword(String token, String username, boolean resetPassword, String lastError) {
+      return adjustNull(getHandler(UUID.fromString(token)).askPassword(username, resetPassword, lastError));
     }
 
     @Override
-    public String setLastSuccessful(int handlerNo, String userName, String method, String error) {
-      getHandler(handlerNo).setLastSuccessful(userName, method, error);
+    public String setLastSuccessful(String token, String userName, String method, String error) {
+      getHandler(UUID.fromString(token)).setLastSuccessful(userName, method, error);
       return "";
     }
 
     @Override
-    public String getLastSuccessful(int handlerNo, String userName) {
-      return getHandler(handlerNo).getLastSuccessful(userName);
+    public String getLastSuccessful(String token, String userName) {
+      return getHandler(UUID.fromString(token)).getLastSuccessful(userName);
     }
 
     /**