mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
use UUID instead of incremental int id
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user