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 192ad6acdf24b7b7c8714b8d5fe4c95cc7d8de4d Author: Lyor Goldstein <lgoldst...@apache.org> AuthorDate: Tue Jul 28 17:09:33 2020 +0300 [SSHD-1042] Added separate callbacks in SftpEventListener for reading vs. already read directory entries --- CHANGES.md | 3 ++- .../sftp/SimpleAccessControlSftpEventListener.java | 4 ++-- .../sftp/server/AbstractSftpEventListenerAdapter.java | 2 +- .../sshd/sftp/server/AbstractSftpSubsystemHelper.java | 2 +- .../org/apache/sshd/sftp/server/SftpEventListener.java | 18 +++++++++++++++++- .../org/apache/sshd/sftp/server/SftpSubsystem.java | 3 +++ .../java/org/apache/sshd/sftp/client/SftpTest.java | 2 +- 7 files changed, 27 insertions(+), 7 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6df3175..b50f202 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,7 +12,7 @@ ## Major code re-factoring -* [SSHD-1034](https://issues.apache.org/jira/browse/SSHD-1034) Rename {{org.apache.sshd.common.ForwardingFilter}} to {{Forwarder}}. +* [SSHD-1034](https://issues.apache.org/jira/browse/SSHD-1034) Rename `org.apache.sshd.common.ForwardingFilter` to `Forwarder`. * [SSHD-1035](https://issues.apache.org/jira/browse/SSHD-1035) Move property definitions to common locations. * [SSHD-1038](https://issues.apache.org/jira/browse/SSHD-1035) Refactor packages from a module into a cleaner hierarchy. @@ -20,6 +20,7 @@ * [SSHD-1040](https://issues.apache.org/jira/browse/SSHD-1040) Make server key available after KEX completed. * [SSHD-1030](https://issues.apache.org/jira/browse/SSHD-1030) Added a NoneFileSystemFactory implementation +* [SSHD-1042](https://issues.apache.org/jira/browse/SSHD-1030) Added more callbacks to SftpEventListener ## Behavioral changes and enhancements diff --git a/sshd-contrib/src/main/java/org/apache/sshd/server/subsystem/sftp/SimpleAccessControlSftpEventListener.java b/sshd-contrib/src/main/java/org/apache/sshd/server/subsystem/sftp/SimpleAccessControlSftpEventListener.java index f4333d1..55474de 100644 --- a/sshd-contrib/src/main/java/org/apache/sshd/server/subsystem/sftp/SimpleAccessControlSftpEventListener.java +++ b/sshd-contrib/src/main/java/org/apache/sshd/server/subsystem/sftp/SimpleAccessControlSftpEventListener.java @@ -83,9 +83,9 @@ public abstract class SimpleAccessControlSftpEventListener extends AbstractSftpE } @Override - public void read(ServerSession session, String remoteHandle, DirectoryHandle localHandle, Map<String, Path> entries) + public void readEntries(ServerSession session, String remoteHandle, DirectoryHandle localHandle, Map<String, Path> entries) throws IOException { - super.read(session, remoteHandle, localHandle, entries); + super.readEntries(session, remoteHandle, localHandle, entries); if (!isAccessAllowed(session, remoteHandle, localHandle)) { throw new AccessDeniedException(remoteHandle); } diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpEventListenerAdapter.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpEventListenerAdapter.java index 29f53d1..2da406c 100644 --- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpEventListenerAdapter.java +++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpEventListenerAdapter.java @@ -74,7 +74,7 @@ public abstract class AbstractSftpEventListenerAdapter extends AbstractLoggingBe } @Override - public void read(ServerSession session, String remoteHandle, DirectoryHandle localHandle, Map<String, Path> entries) + public void readEntries(ServerSession session, String remoteHandle, DirectoryHandle localHandle, Map<String, Path> entries) throws IOException { int numEntries = GenericUtils.size(entries); if (log.isDebugEnabled()) { diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpSubsystemHelper.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpSubsystemHelper.java index 4a8a7d9..2d11207 100644 --- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpSubsystemHelper.java +++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpSubsystemHelper.java @@ -2143,7 +2143,7 @@ public abstract class AbstractSftpSubsystemHelper } SftpEventListener listener = getSftpEventListenerProxy(); - listener.read(getServerSession(), handle, dir, entries); + listener.readEntries(getServerSession(), handle, dir, entries); return nb; } diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpEventListener.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpEventListener.java index 5367ebf..c655761 100644 --- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpEventListener.java +++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpEventListener.java @@ -140,6 +140,22 @@ public interface SftpEventListener extends SshdEventListener { } /** + * About to read entries from a directory - <B>Note:</B> might not be the 1st time it is called for the directory in + * case several iterations are required in order to go through all the entries in the directory + * + * @param session The {@link ServerSession} through which the request was handled + * @param remoteHandle The (opaque) assigned handle for the directory + * @param localHandle The associated {@link DirectoryHandle} + * @throws IOException If failed to handle the call + * @see #readEntries(ServerSession, String, DirectoryHandle, Map) readEntries + */ + default void readingEntries( + ServerSession session, String remoteHandle, DirectoryHandle localHandle) + throws IOException { + // ignored + } + + /** * Result of reading entries from a directory - <B>Note:</B> it may be a <U>partial</U> result if the directory * contains more entries than can be accommodated in the response * @@ -150,7 +166,7 @@ public interface SftpEventListener extends SshdEventListener { * sub-entry * @throws IOException If failed to handle the call */ - default void read( + default void readEntries( ServerSession session, String remoteHandle, DirectoryHandle localHandle, Map<String, Path> entries) throws IOException { // ignored diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystem.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystem.java index b36844f..e39e9c8 100644 --- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystem.java +++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystem.java @@ -657,6 +657,9 @@ public class SftpSubsystem throw new AccessDeniedException(file.toString(), file.toString(), "Not readable"); } + SftpEventListener listener = getSftpEventListenerProxy(); + listener.readingEntries(session, handle, dh); + if (dh.isSendDot() || dh.isSendDotDot() || dh.hasNext()) { // There is at least one file in the directory or we need to send the "..". // Send only a few files at a time to not create packets of a too diff --git a/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/SftpTest.java b/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/SftpTest.java index 3b66eda..c7b3c36 100644 --- a/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/SftpTest.java +++ b/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/SftpTest.java @@ -814,7 +814,7 @@ public class SftpTest extends AbstractSftpClientTestSupport { } @Override - public void read( + public void readEntries( ServerSession session, String remoteHandle, DirectoryHandle localHandle, Map<String, Path> entries) { int numEntries = GenericUtils.size(entries); entriesCount.addAndGet(numEntries);