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

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

commit 5508f24069cec66eb8248a6874fc8535ce8e3644
Author: Lyor Goldstein <lgoldst...@apache.org>
AuthorDate: Thu Apr 1 21:37:07 2021 +0300

    [SSHD-1116] Provide SessionContext argument to 
AuthenticationIdentitiesProvider#loadIdentities
---
 CHANGES.md                                                  |  1 +
 .../java/org/apache/sshd/cli/client/ScpCommandMain.java     |  2 +-
 .../sshd/client/auth/AuthenticationIdentitiesProvider.java  | 13 ++++++++++---
 .../src/main/java/org/apache/sshd/client/SshClient.java     | 10 ++++++----
 4 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index f99e6ea..5a6ffd8 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -30,6 +30,7 @@
 * [SSHD-1111](https://issues.apache.org/jira/browse/SSHD-1111) Fixed 
SshClientCliSupport compression option detection
 * [SSHD-1116](https://issues.apache.org/jira/browse/SSHD-1116) Provide 
SessionContext argument to HostKeyIdentityProvider#loadHostKeys
 * [SSHD-1116](https://issues.apache.org/jira/browse/SSHD-1116) Provide 
SessionContext argument to PasswordIdentityProvider#loadPasswords
+* [SSHD-1116](https://issues.apache.org/jira/browse/SSHD-1116) Provide 
SessionContext argument to AuthenticationIdentitiesProvider#loadIdentities
 * [SSHD-1125](https://issues.apache.org/jira/browse/SSHD-1125) Added option to 
require immediate close of channel in command `ExitCallback` invocation
 * [SSHD-1127](https://issues.apache.org/jira/browse/SSHD-1127) Consolidated 
`SftpSubsystem` support implementations into `SftpSubsystemConfigurator`
 * [SSHD-1148](https://issues.apache.org/jira/browse/SSHD-1148) Generate a 
unique thread name for each `SftpSubsystem` instance
diff --git 
a/sshd-cli/src/main/java/org/apache/sshd/cli/client/ScpCommandMain.java 
b/sshd-cli/src/main/java/org/apache/sshd/cli/client/ScpCommandMain.java
index 662f00b..c72f741 100644
--- a/sshd-cli/src/main/java/org/apache/sshd/cli/client/ScpCommandMain.java
+++ b/sshd-cli/src/main/java/org/apache/sshd/cli/client/ScpCommandMain.java
@@ -354,7 +354,7 @@ public class ScpCommandMain extends SshClientCliSupport {
                 // TODO see if there is a way to specify different 
password/key for target
                 // copy non-default identities from source session
                 AuthenticationIdentitiesProvider provider = 
srcSession.getRegisteredIdentities();
-                Iterable<?> ids = (provider == null) ? null : 
provider.loadIdentities();
+                Iterable<?> ids = (provider == null) ? null : 
provider.loadIdentities(srcSession);
                 Iterator<?> iter = (ids == null) ? null : ids.iterator();
                 while ((iter != null) && iter.hasNext()) {
                     Object v = iter.next();
diff --git 
a/sshd-common/src/main/java/org/apache/sshd/client/auth/AuthenticationIdentitiesProvider.java
 
b/sshd-common/src/main/java/org/apache/sshd/client/auth/AuthenticationIdentitiesProvider.java
index 6234d33..f7d61a3 100644
--- 
a/sshd-common/src/main/java/org/apache/sshd/client/auth/AuthenticationIdentitiesProvider.java
+++ 
b/sshd-common/src/main/java/org/apache/sshd/client/auth/AuthenticationIdentitiesProvider.java
@@ -19,6 +19,8 @@
 
 package org.apache.sshd.client.auth;
 
+import java.io.IOException;
+import java.security.GeneralSecurityException;
 import java.security.KeyPair;
 import java.util.Comparator;
 import java.util.List;
@@ -61,9 +63,14 @@ public interface AuthenticationIdentitiesProvider extends 
KeyIdentityProvider, P
     };
 
     /**
-     * @return All the currently available identities - passwords, keys, etc...
+     * @param  session                  The {@link SessionContext} for 
invoking this load command - may be {@code null}
+     *                                  if not invoked within a session 
context (e.g., offline tool).
+     * @return                          All the currently available identities 
- passwords, keys, etc...
+     * @throws IOException              If failed to load the identities
+     * @throws GeneralSecurityException If some security issue with the 
identities (e.g., keys)
      */
-    Iterable<?> loadIdentities();
+    Iterable<?> loadIdentities(SessionContext session)
+            throws IOException, GeneralSecurityException;
 
     static int findIdentityIndex(List<?> identities, Comparator<? super 
Object> comp, Object target) {
         for (int index = 0; index < identities.size(); index++) {
@@ -93,7 +100,7 @@ public interface AuthenticationIdentitiesProvider extends 
KeyIdentityProvider, P
             }
 
             @Override
-            public Iterable<?> loadIdentities() {
+            public Iterable<?> loadIdentities(SessionContext session) {
                 return 
LazyMatchingTypeIterable.lazySelectMatchingTypes(identities, Object.class);
             }
         };
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java 
b/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
index d5fa906..a00954c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
@@ -715,7 +715,7 @@ public class SshClient extends AbstractFactoryManager 
implements ClientFactoryMa
                     try {
                         onConnectOperationComplete(ioSession, connectFuture, 
username, address, identities,
                                 useDefaultIdentities);
-                    } catch (RuntimeException e) {
+                    } catch (IOException | GeneralSecurityException | 
RuntimeException e) {
                         warn("operationComplete({}@{}) failed ({}) to signal 
completion of session={}: {}",
                                 username, address, 
e.getClass().getSimpleName(), ioSession, e.getMessage(), e);
                         connectFuture.setException(e);
@@ -734,7 +734,8 @@ public class SshClient extends AbstractFactoryManager 
implements ClientFactoryMa
 
     protected void onConnectOperationComplete(
             IoSession ioSession, ConnectFuture connectFuture, String username,
-            SocketAddress address, KeyIdentityProvider identities, boolean 
useDefaultIdentities) {
+            SocketAddress address, KeyIdentityProvider identities, boolean 
useDefaultIdentities)
+            throws IOException, GeneralSecurityException {
         AbstractClientSession session = (AbstractClientSession) 
AbstractSession.getSession(ioSession);
         session.setUsername(username);
         session.setConnectAddress(address);
@@ -752,7 +753,8 @@ public class SshClient extends AbstractFactoryManager 
implements ClientFactoryMa
     }
 
     protected void setupDefaultSessionIdentities(
-            ClientSession session, KeyIdentityProvider extraIdentities) {
+            ClientSession session, KeyIdentityProvider extraIdentities)
+            throws IOException, GeneralSecurityException {
         boolean debugEnabled = log.isDebugEnabled();
         // check if session listener intervened
         KeyIdentityProvider kpSession = session.getKeyIdentityProvider();
@@ -782,7 +784,7 @@ public class SshClient extends AbstractFactoryManager 
implements ClientFactoryMa
 
         AuthenticationIdentitiesProvider idsClient = getRegisteredIdentities();
         boolean traceEnabled = log.isTraceEnabled();
-        for (Iterator<?> iter = GenericUtils.iteratorOf((idsClient == null) ? 
null : idsClient.loadIdentities());
+        for (Iterator<?> iter = GenericUtils.iteratorOf((idsClient == null) ? 
null : idsClient.loadIdentities(session));
              iter.hasNext();) {
             Object id = iter.next();
             if (id instanceof String) {

Reply via email to