mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
git: implement NONE authentication mode for ssh
This commit is contained in:
@@ -27,7 +27,6 @@ import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.intellij.util.ObjectUtils.notNull;
|
||||
import static git4idea.commands.GitAuthenticationMode.FULL;
|
||||
|
||||
/**
|
||||
* Manager for Git remotes authentication.
|
||||
@@ -134,7 +133,7 @@ public class GitHandlerAuthenticationManager implements AutoCloseable {
|
||||
myHandler.addCustomEnvironmentVariable(GitSSHHandler.GIT_SSH_ENV, ssh.getScriptPath().getPath());
|
||||
myHandler.addCustomEnvironmentVariable(GitSSHHandler.GIT_SSH_VAR, "ssh");
|
||||
GitAuthenticationGate authenticationGate = notNull(myHandler.getAuthenticationGate(), GitPassthroughAuthenticationGate.getInstance());
|
||||
GitSSHGUIHandler guiHandler = new GitSSHGUIHandler(myProject, authenticationGate, myHandler.getIgnoreAuthenticationMode() != FULL);
|
||||
GitSSHGUIHandler guiHandler = new GitSSHGUIHandler(myProject, authenticationGate, myHandler.getIgnoreAuthenticationMode());
|
||||
mySshHandler = ssh.registerHandler(guiHandler, myProject);
|
||||
myHandler.addCustomEnvironmentVariable(GitSSHHandler.SSH_HANDLER_ENV, mySshHandler.toString());
|
||||
int port = ssh.getXmlRcpPort();
|
||||
@@ -172,10 +171,8 @@ public class GitHandlerAuthenticationManager implements AutoCloseable {
|
||||
|
||||
boolean doNotRememberPasswords = myHandler.getUrls().size() > 1;
|
||||
GitAuthenticationGate authenticationGate = notNull(myHandler.getAuthenticationGate(), GitPassthroughAuthenticationGate.getInstance());
|
||||
GitNativeSshGuiAuthenticator authenticator = new GitNativeSshGuiAuthenticator(myProject,
|
||||
authenticationGate,
|
||||
myHandler.getIgnoreAuthenticationMode() != FULL,
|
||||
doNotRememberPasswords);
|
||||
GitNativeSshGuiAuthenticator authenticator =
|
||||
new GitNativeSshGuiAuthenticator(myProject, authenticationGate, myHandler.getIgnoreAuthenticationMode(), doNotRememberPasswords);
|
||||
|
||||
myNativeSshHandler = service.registerHandler(authenticator, myProject);
|
||||
int port = service.getXmlRcpPort();
|
||||
|
||||
@@ -16,10 +16,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import static git4idea.commands.GitAuthenticationMode.FULL;
|
||||
|
||||
class GitNativeSshGuiAuthenticator implements GitNativeSshAuthenticator {
|
||||
@NotNull private final Project myProject;
|
||||
@NotNull private final GitAuthenticationGate myAuthenticationGate;
|
||||
private final boolean myIgnoreAuthenticationRequest;
|
||||
@NotNull private final GitAuthenticationMode myAuthenticationMode;
|
||||
private final boolean myDoNotRememberPasswords;
|
||||
|
||||
@Nullable private String myLastAskedKeyPath = null;
|
||||
@@ -27,17 +29,18 @@ class GitNativeSshGuiAuthenticator implements GitNativeSshAuthenticator {
|
||||
|
||||
GitNativeSshGuiAuthenticator(@NotNull Project project,
|
||||
@NotNull GitAuthenticationGate authenticationGate,
|
||||
boolean isIgnoreAuthenticationRequest,
|
||||
@NotNull GitAuthenticationMode authenticationMode,
|
||||
boolean doNotRememberPasswords) {
|
||||
myProject = project;
|
||||
myAuthenticationGate = authenticationGate;
|
||||
myIgnoreAuthenticationRequest = isIgnoreAuthenticationRequest;
|
||||
myAuthenticationMode = authenticationMode;
|
||||
myDoNotRememberPasswords = doNotRememberPasswords;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String handleInput(@NotNull String description) {
|
||||
if(myAuthenticationMode == GitAuthenticationMode.NONE) return null;
|
||||
return myAuthenticationGate.waitAndCompute(() -> {
|
||||
if (isKeyPassphrase(description)) return askKeyPassphraseInput(description);
|
||||
if (isSshPassword(description)) return askSshPasswordInput(description);
|
||||
@@ -68,7 +71,7 @@ class GitNativeSshGuiAuthenticator implements GitNativeSshAuthenticator {
|
||||
});
|
||||
}
|
||||
else {
|
||||
return GitSSHGUIHandler.askPassphrase(myProject, keyPath, resetPassword, myIgnoreAuthenticationRequest, null);
|
||||
return GitSSHGUIHandler.askPassphrase(myProject, keyPath, resetPassword, myAuthenticationMode, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +95,7 @@ class GitNativeSshGuiAuthenticator implements GitNativeSshAuthenticator {
|
||||
});
|
||||
}
|
||||
else {
|
||||
return GitSSHGUIHandler.askPassword(myProject, username, resetPassword, myIgnoreAuthenticationRequest, null);
|
||||
return GitSSHGUIHandler.askPassword(myProject, username, resetPassword, myAuthenticationMode, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +132,7 @@ class GitNativeSshGuiAuthenticator implements GitNativeSshAuthenticator {
|
||||
|
||||
@Nullable
|
||||
private String askUser(@NotNull Computable<String> query) {
|
||||
if (myIgnoreAuthenticationRequest) return null;
|
||||
if (myAuthenticationMode != FULL) return null;
|
||||
|
||||
Ref<String> answerRef = new Ref<>();
|
||||
ApplicationManager.getApplication().invokeAndWait(() -> {
|
||||
|
||||
@@ -39,20 +39,21 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static com.intellij.credentialStore.CredentialAttributesKt.*;
|
||||
import static git4idea.commands.GitAuthenticationMode.FULL;
|
||||
|
||||
/**
|
||||
* Swing GUI handler for the SSH events
|
||||
*/
|
||||
public class GitSSHGUIHandler {
|
||||
@Nullable private final Project myProject;
|
||||
private final boolean myIgnoreAuthenticationRequest;
|
||||
@NotNull private final GitAuthenticationMode myAuthenticationMode;
|
||||
@NotNull private final GitAuthenticationGate myAuthenticationGate;
|
||||
|
||||
GitSSHGUIHandler(@Nullable Project project,
|
||||
@NotNull GitAuthenticationGate authenticationGate,
|
||||
boolean ignoreAuthenticationRequest) {
|
||||
@NotNull GitAuthenticationMode authenticationMode) {
|
||||
myProject = project;
|
||||
myIgnoreAuthenticationRequest = ignoreAuthenticationRequest;
|
||||
myAuthenticationMode = authenticationMode;
|
||||
myAuthenticationGate = authenticationGate;
|
||||
}
|
||||
|
||||
@@ -81,7 +82,7 @@ public class GitSSHGUIHandler {
|
||||
public String askPassphrase(final String username, final String keyPath, boolean resetPassword, final String lastError) {
|
||||
return myAuthenticationGate.waitAndCompute(() -> {
|
||||
String error = processLastError(resetPassword, lastError);
|
||||
return askPassphrase(myProject, keyPath, resetPassword, myIgnoreAuthenticationRequest, error);
|
||||
return askPassphrase(myProject, keyPath, resetPassword, myAuthenticationMode, error);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -89,8 +90,9 @@ public class GitSSHGUIHandler {
|
||||
static String askPassphrase(@Nullable Project project,
|
||||
@NotNull String keyPath,
|
||||
boolean resetPassword,
|
||||
boolean ignoreAuthenticationRequest,
|
||||
@NotNull GitAuthenticationMode authenticationMode,
|
||||
@Nullable String lastError) {
|
||||
if (authenticationMode == GitAuthenticationMode.NONE) return null;
|
||||
CredentialAttributes oldAttributes = oldCredentialAttributes("PASSPHRASE:" + keyPath);
|
||||
CredentialAttributes newAttributes = passphraseCredentialAttributes(keyPath);
|
||||
Credentials credentials = getAndMigrateCredentials(oldAttributes, newAttributes);
|
||||
@@ -98,7 +100,7 @@ public class GitSSHGUIHandler {
|
||||
String password = credentials.getPasswordAsString();
|
||||
if (password != null && !password.isEmpty()) return password;
|
||||
}
|
||||
if (ignoreAuthenticationRequest) return null;
|
||||
if (authenticationMode == GitAuthenticationMode.SILENT) return null;
|
||||
return CredentialPromptDialog.askPassword(project, GitBundle.getString("ssh.ask.passphrase.title"),
|
||||
GitBundle.message("ssh.ask.passphrase.message", PathUtil.getFileName(keyPath)),
|
||||
newAttributes, true, lastError);
|
||||
@@ -165,7 +167,7 @@ public class GitSSHGUIHandler {
|
||||
final Vector<String> prompt,
|
||||
final Vector<Boolean> echo,
|
||||
final String lastError) {
|
||||
if (myIgnoreAuthenticationRequest) return null;
|
||||
if (myAuthenticationMode != FULL) return null;
|
||||
return myAuthenticationGate.waitAndCompute(() -> {
|
||||
final AtomicReference<Vector<String>> rc = new AtomicReference<>();
|
||||
ApplicationManager.getApplication().invokeAndWait(() -> {
|
||||
@@ -191,7 +193,7 @@ public class GitSSHGUIHandler {
|
||||
public String askPassword(final String username, boolean resetPassword, final String lastError) {
|
||||
return myAuthenticationGate.waitAndCompute(() -> {
|
||||
String error = processLastError(resetPassword, lastError);
|
||||
return askPassword(myProject, username, resetPassword, myIgnoreAuthenticationRequest, error);
|
||||
return askPassword(myProject, username, resetPassword, myAuthenticationMode, error);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -199,8 +201,9 @@ public class GitSSHGUIHandler {
|
||||
static String askPassword(@Nullable Project project,
|
||||
@NotNull String username,
|
||||
boolean resetPassword,
|
||||
boolean ignoreAuthenticationRequest,
|
||||
@NotNull GitAuthenticationMode authenticationMode,
|
||||
@Nullable String error) {
|
||||
if(authenticationMode == GitAuthenticationMode.NONE) return null;
|
||||
CredentialAttributes oldAttributes = oldCredentialAttributes("PASSWORD:" + username);
|
||||
CredentialAttributes newAttributes = passwordCredentialAttributes(username);
|
||||
Credentials credentials = getAndMigrateCredentials(oldAttributes, newAttributes);
|
||||
@@ -208,7 +211,7 @@ public class GitSSHGUIHandler {
|
||||
String password = credentials.getPasswordAsString();
|
||||
if (password != null) return password;
|
||||
}
|
||||
if (ignoreAuthenticationRequest) return null;
|
||||
if (authenticationMode == GitAuthenticationMode.SILENT) return null;
|
||||
return CredentialPromptDialog.askPassword(project,
|
||||
GitBundle.getString("ssh.password.title"),
|
||||
GitBundle.message("ssh.password.message", username),
|
||||
|
||||
Reference in New Issue
Block a user