This is an automated email from the ASF dual-hosted git repository.

twolf pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git

commit 14b4ec07e2bfa7fccc6a053846b0bc4cd5d0fddf
Author: Thomas Wolf <tw...@apache.org>
AuthorDate: Sat Oct 23 20:57:15 2021 +0200

    [SSHD-1218] Pass session to SshAgentFactory.createClient()
    
    This enables the factory to return different SshAgents depending on the
    session and its configuration.
---
 sshd-core/src/main/java/org/apache/sshd/agent/SshAgentFactory.java    | 4 +++-
 .../main/java/org/apache/sshd/agent/local/ChannelAgentForwarding.java | 2 +-
 .../src/main/java/org/apache/sshd/agent/local/LocalAgentFactory.java  | 3 ++-
 .../src/main/java/org/apache/sshd/agent/local/ProxyAgentFactory.java  | 2 +-
 .../src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java    | 2 +-
 .../org/apache/sshd/client/auth/pubkey/UserAuthPublicKeyIterator.java | 2 +-
 sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthAgent.java | 2 +-
 7 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentFactory.java 
b/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentFactory.java
index bc391cf..a0e6fe2 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentFactory.java
@@ -24,6 +24,7 @@ import java.util.List;
 import org.apache.sshd.common.FactoryManager;
 import org.apache.sshd.common.channel.ChannelFactory;
 import org.apache.sshd.common.session.ConnectionService;
+import org.apache.sshd.common.session.Session;
 
 /**
  * The <code>SshAgentFactory</code> is used to communicate with an SshAgent.
@@ -42,11 +43,12 @@ public interface SshAgentFactory {
     /**
      * Create an SshAgent that can be used on the client side by the 
authentication process to send possible keys.
      *
+     * @param  session     the {@link Session} the {@link SshAgent} is to be 
created for; may be {@code null}
      * @param  manager     The {@link FactoryManager} instance
      * @return             The {@link SshAgent} instance
      * @throws IOException If failed to create the client
      */
-    SshAgent createClient(FactoryManager manager) throws IOException;
+    SshAgent createClient(Session session, FactoryManager manager) throws 
IOException;
 
     /**
      * Create the server side that will be used by other SSH clients. It will 
usually create a channel that will forward
diff --git 
a/sshd-core/src/main/java/org/apache/sshd/agent/local/ChannelAgentForwarding.java
 
b/sshd-core/src/main/java/org/apache/sshd/agent/local/ChannelAgentForwarding.java
index a91b1a2..e5f73af 100644
--- 
a/sshd-core/src/main/java/org/apache/sshd/agent/local/ChannelAgentForwarding.java
+++ 
b/sshd-core/src/main/java/org/apache/sshd/agent/local/ChannelAgentForwarding.java
@@ -63,7 +63,7 @@ public class ChannelAgentForwarding extends 
AbstractServerChannel {
             Session session = getSession();
             FactoryManager manager = 
Objects.requireNonNull(session.getFactoryManager(), "No factory manager");
             SshAgentFactory factory = 
Objects.requireNonNull(manager.getAgentFactory(), "No agent factory");
-            agent = factory.createClient(manager);
+            agent = factory.createClient(session, manager);
             client = new AgentClient();
 
             signalChannelOpenSuccess();
diff --git 
a/sshd-core/src/main/java/org/apache/sshd/agent/local/LocalAgentFactory.java 
b/sshd-core/src/main/java/org/apache/sshd/agent/local/LocalAgentFactory.java
index 18ffe60..cbdd861 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/local/LocalAgentFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/local/LocalAgentFactory.java
@@ -30,6 +30,7 @@ import org.apache.sshd.agent.common.AgentDelegate;
 import org.apache.sshd.common.FactoryManager;
 import org.apache.sshd.common.channel.ChannelFactory;
 import org.apache.sshd.common.session.ConnectionService;
+import org.apache.sshd.common.session.Session;
 
 public class LocalAgentFactory implements SshAgentFactory {
     public static final List<ChannelFactory> DEFAULT_FORWARDING_CHANNELS = 
Collections.unmodifiableList(
@@ -57,7 +58,7 @@ public class LocalAgentFactory implements SshAgentFactory {
     }
 
     @Override
-    public SshAgent createClient(FactoryManager manager) throws IOException {
+    public SshAgent createClient(Session session, FactoryManager manager) 
throws IOException {
         return new AgentDelegate(agent);
     }
 
diff --git 
a/sshd-core/src/main/java/org/apache/sshd/agent/local/ProxyAgentFactory.java 
b/sshd-core/src/main/java/org/apache/sshd/agent/local/ProxyAgentFactory.java
index ffde9af..178bf7e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/local/ProxyAgentFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/local/ProxyAgentFactory.java
@@ -57,7 +57,7 @@ public class ProxyAgentFactory implements SshAgentFactory {
     }
 
     @Override
-    public SshAgent createClient(FactoryManager manager) throws IOException {
+    public SshAgent createClient(Session session, FactoryManager manager) 
throws IOException {
         String proxyId = manager.getString(SshAgent.SSH_AUTHSOCKET_ENV_NAME);
         if (GenericUtils.isEmpty(proxyId)) {
             throw new IllegalStateException("No " + 
SshAgent.SSH_AUTHSOCKET_ENV_NAME + " environment variable set");
diff --git 
a/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java 
b/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java
index a390aeb..07209e1 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java
@@ -74,7 +74,7 @@ public class UnixAgentFactory implements SshAgentFactory {
     }
 
     @Override
-    public SshAgent createClient(FactoryManager manager) throws IOException {
+    public SshAgent createClient(Session session, FactoryManager manager) 
throws IOException {
         String authSocket = 
manager.getString(SshAgent.SSH_AUTHSOCKET_ENV_NAME);
         if (GenericUtils.isEmpty(authSocket)) {
             throw new SshException("No " + SshAgent.SSH_AUTHSOCKET_ENV_NAME + 
" value");
diff --git 
a/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKeyIterator.java
 
b/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKeyIterator.java
index 07b115b..09555f1 100644
--- 
a/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKeyIterator.java
+++ 
b/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKeyIterator.java
@@ -147,7 +147,7 @@ public class UserAuthPublicKeyIterator extends 
AbstractKeyPairIterator<PublicKey
             return null;
         }
 
-        agent = Objects.requireNonNull(factory.createClient(manager), "No 
agent created");
+        agent = Objects.requireNonNull(factory.createClient(session, manager), 
"No agent created");
         return new Iterable<KeyAgentIdentity>() {
             @SuppressWarnings("synthetic-access")
             private final Iterable<? extends Map.Entry<PublicKey, String>> 
agentIds = agent.getIdentities();
diff --git 
a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthAgent.java 
b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthAgent.java
index 52f11a2..42c43d1 100644
--- a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthAgent.java
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthAgent.java
@@ -52,7 +52,7 @@ public class UserAuthAgent extends AbstractUserAuth {
         if (agentFactory == null) {
             throw new IllegalStateException("No ssh agent factory has been 
configured");
         }
-        this.agent = agentFactory.createClient(factoryManager);
+        this.agent = agentFactory.createClient(session, factoryManager);
         this.keys = agent.getIdentities().iterator();
     }
 

Reply via email to