You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by tw...@apache.org on 2021/10/23 23:05:55 UTC
[mina-sshd] 03/05: [SSHD-1218] Handle null SshAgent
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 fc03c20c28da5833b8d46d9680a5da57de61dfae
Author: Thomas Wolf <tw...@apache.org>
AuthorDate: Sat Oct 23 21:01:35 2021 +0200
[SSHD-1218] Handle null SshAgent
Don't require a non-null result from SshAgentFactory.createClient().
Instead simply treat this case as if there was no SSH agent. This way,
an SshAgentFactory can return null if for a particular session no
communication with the SSH agent shall be done.
---
sshd-core/src/main/java/org/apache/sshd/agent/SshAgentFactory.java | 2 +-
.../apache/sshd/client/auth/pubkey/UserAuthPublicKeyIterator.java | 5 ++++-
2 files changed, 5 insertions(+), 2 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 a0e6fe2..a528d58 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
@@ -45,7 +45,7 @@ public interface SshAgentFactory {
*
* @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
+ * @return The {@link SshAgent} instance, or {@code null} if no SSH agent shall be used
* @throws IOException If failed to create the client
*/
SshAgent createClient(Session session, FactoryManager manager) throws IOException;
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 09555f1..970aa7d 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,10 @@ public class UserAuthPublicKeyIterator extends AbstractKeyPairIterator<PublicKey
return null;
}
- agent = Objects.requireNonNull(factory.createClient(session, manager), "No agent created");
+ agent = factory.createClient(session, manager);
+ if (agent == null) {
+ return null;
+ }
return new Iterable<KeyAgentIdentity>() {
@SuppressWarnings("synthetic-access")
private final Iterable<? extends Map.Entry<PublicKey, String>> agentIds = agent.getIdentities();