diff options
author | Thomas Wolf <thomas.wolf@paranor.ch> | 2021-10-27 14:03:10 +0200 |
---|---|---|
committer | Thomas Wolf <thomas.wolf@paranor.ch> | 2021-11-10 13:57:01 -0500 |
commit | e7838b9c080011817ddb59c53298237a9c24a7a6 (patch) | |
tree | 885bd217ebe1f0226c156aa2676272cfa1e9cc43 /org.eclipse.jgit.ssh.apache.agent/src | |
parent | b84738c3693081d3ed9e8e1ba4a5db6e5ac3abf8 (diff) | |
download | jgit-e7838b9c080011817ddb59c53298237a9c24a7a6.tar.gz jgit-e7838b9c080011817ddb59c53298237a9c24a7a6.zip |
[sshd agent] Introduce ConnectorDescriptor
Once a factory supports different SSH agents on the same platform,
which is planned for Windows once we use Apache MINA sshd 2.8.0,
client code may need to have a way to specify which SSH agent shall
be used when the SSH config doesn't define anything.
Add a mechanism by which a ConnectorFactory can tell what Connectors
it may provide. Client code can use this to set the identityAgent
parameter of ConnectorFactory.create() to the wanted default if it
would be null otherwise.
A ConnectorDescriptor is a pair of strings: an internal name, and a
display name. The latter is included because client code might want to
communicate agent names to the user, be it in error messages or in some
chooser dialog where a user could define which of several alternative
SSH agents should be used as default. The internal name is intended to
be used in the IdentityAgent directive in ~/.ssh/config.
Also make the ConnectorFactory discovered via the ServiceLoader
accessible and overrideable. Provide static get/setDefault() methods,
similar to the SshSessionFactory itself.
Change-Id: Ie3d077395d32dfddc72bc8627e92b23636938182
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.ssh.apache.agent/src')
4 files changed, 60 insertions, 0 deletions
diff --git a/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/Factory.java b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/Factory.java index 1cbf0e41b6..d7409b0c3c 100644 --- a/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/Factory.java +++ b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/Factory.java @@ -11,6 +11,8 @@ package org.eclipse.jgit.internal.transport.sshd.agent.connector; import java.io.File; import java.io.IOException; +import java.util.Collection; +import java.util.Collections; import org.eclipse.jgit.transport.sshd.agent.Connector; import org.eclipse.jgit.transport.sshd.agent.ConnectorFactory; @@ -41,4 +43,26 @@ public class Factory implements ConnectorFactory { public String getName() { return NAME; } + + /** + * {@inheritDoc} + * <p> + * This factory returns on Windows a + * {@link org.eclipse.jgit.transport.sshd.agent.ConnectorFactory.ConnectorDescriptor + * ConnectorDescriptor} for the internal name "pageant"; on Unix one for + * "SSH_AUTH_SOCK". + * </p> + */ + @Override + public Collection<ConnectorDescriptor> getSupportedConnectors() { + return Collections.singleton(getDefaultConnector()); + } + + @Override + public ConnectorDescriptor getDefaultConnector() { + if (SystemReader.getInstance().isWindows()) { + return PageantConnector.DESCRIPTOR; + } + return UnixDomainSocketConnector.DESCRIPTOR; + } } diff --git a/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/PageantConnector.java b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/PageantConnector.java index 59fe2fc246..b0e3bce724 100644 --- a/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/PageantConnector.java +++ b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/PageantConnector.java @@ -12,12 +12,29 @@ package org.eclipse.jgit.internal.transport.sshd.agent.connector; import java.io.IOException; import org.eclipse.jgit.transport.sshd.agent.AbstractConnector; +import org.eclipse.jgit.transport.sshd.agent.ConnectorFactory.ConnectorDescriptor; /** * A connector using Pageant's shared memory IPC mechanism. */ public class PageantConnector extends AbstractConnector { + /** + * {@link ConnectorDescriptor} for the {@link PageantConnector}. + */ + public static final ConnectorDescriptor DESCRIPTOR = new ConnectorDescriptor() { + + @Override + public String getIdentityAgent() { + return "pageant"; //$NON-NLS-1$ + } + + @Override + public String getDisplayName() { + return Texts.get().pageant; + } + }; + private final PageantLibrary lib; /** diff --git a/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/Texts.java b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/Texts.java index 6b66261546..fb45b30dd2 100644 --- a/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/Texts.java +++ b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/Texts.java @@ -42,5 +42,7 @@ public final class Texts extends TranslationBundle { /***/ public String msgSendFailed2; /***/ public String msgSharedMemoryFailed; /***/ public String msgShortRead; + /***/ public String pageant; + /***/ public String unixDefaultAgent; } diff --git a/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/UnixDomainSocketConnector.java b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/UnixDomainSocketConnector.java index 4c698d974a..3b75f3a7da 100644 --- a/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/UnixDomainSocketConnector.java +++ b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/UnixDomainSocketConnector.java @@ -24,6 +24,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.apache.sshd.common.SshException; import org.eclipse.jgit.transport.sshd.agent.AbstractConnector; +import org.eclipse.jgit.transport.sshd.agent.ConnectorFactory.ConnectorDescriptor; import org.eclipse.jgit.util.StringUtils; import org.eclipse.jgit.util.SystemReader; import org.slf4j.Logger; @@ -38,6 +39,22 @@ import com.sun.jna.platform.unix.LibCAPI; */ public class UnixDomainSocketConnector extends AbstractConnector { + /** + * {@link ConnectorDescriptor} for the {@link UnixDomainSocketConnector}. + */ + public static final ConnectorDescriptor DESCRIPTOR = new ConnectorDescriptor() { + + @Override + public String getIdentityAgent() { + return ENV_SSH_AUTH_SOCK; + } + + @Override + public String getDisplayName() { + return Texts.get().unixDefaultAgent; + } + }; + private static final Logger LOG = LoggerFactory .getLogger(UnixDomainSocketConnector.class); |