You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2018/11/26 14:41:01 UTC

[1/3] mina-sshd git commit: [SSHD-862] Added session context parameter to ScpReceiveLineHandler method invocation

Repository: mina-sshd
Updated Branches:
  refs/heads/master c305bc494 -> 0de416b82


[SSHD-862] Added session context parameter to ScpReceiveLineHandler method invocation


Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/0de416b8
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/0de416b8
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/0de416b8

Branch: refs/heads/master
Commit: 0de416b82d3bbf2d9499178092a8e83b32bb939e
Parents: 857172b
Author: Lyor Goldstein <lg...@apache.org>
Authored: Mon Nov 26 16:22:37 2018 +0200
Committer: Lyor Goldstein <lg...@apache.org>
Committed: Mon Nov 26 16:40:54 2018 +0200

----------------------------------------------------------------------
 .../main/java/org/apache/sshd/common/scp/ScpHelper.java | 12 ++++++------
 .../apache/sshd/common/scp/ScpReceiveLineHandler.java   |  5 ++++-
 .../apache/sshd/common/scp/ScpTargetStreamResolver.java |  9 ++++++---
 3 files changed, 16 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0de416b8/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
----------------------------------------------------------------------
diff --git a/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpHelper.java b/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
index eb447db..6e98a4f 100644
--- a/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
+++ b/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
@@ -116,7 +116,7 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
     }
 
     public void receiveFileStream(OutputStream local, int bufferSize) throws IOException {
-        receive((line, isDir, timestamp) -> {
+        receive((session, line, isDir, timestamp) -> {
             if (isDir) {
                 throw new StreamCorruptedException("Cannot download a directory into a file stream: " + line);
             }
@@ -130,7 +130,7 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
                             throws IOException {
                     if (log.isDebugEnabled()) {
                         log.debug("resolveTargetStream({}) name={}, perms={}, len={} - started local stream download",
-                                  ScpHelper.this, name, perms, length);
+                              ScpHelper.this, name, perms, length);
                     }
                     return local;
                 }
@@ -147,7 +147,7 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
                             throws IOException {
                     if (log.isDebugEnabled()) {
                         log.debug("postProcessReceivedData({}) name={}, perms={}, preserve={} time={}",
-                                  ScpHelper.this, name, perms, preserve, time);
+                              ScpHelper.this, name, perms, preserve, time);
                     }
                 }
 
@@ -162,7 +162,7 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
     public void receive(Path local, boolean recursive, boolean shouldBeDir, boolean preserve, int bufferSize) throws IOException {
         Path localPath = Objects.requireNonNull(local, "No local path").normalize().toAbsolutePath();
         Path path = opener.resolveIncomingReceiveLocation(getSession(), localPath, recursive, shouldBeDir, preserve);
-        receive((line, isDir, time) -> {
+        receive((session, line, isDir, time) -> {
             if (recursive && isDir) {
                 receiveDir(line, path, time, preserve, bufferSize);
             } else {
@@ -174,7 +174,7 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
     protected void receive(ScpReceiveLineHandler handler) throws IOException {
         ack();
         ScpTimestamp time = null;
-        for (;;) {
+        for (Session session = getSession();;) {
             String line;
             boolean isDir = false;
             int c = readAck(true);
@@ -219,7 +219,7 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
             }
 
             try {
-                handler.process(line, isDir, time);
+                handler.process(session, line, isDir, time);
             } finally {
                 time = null;
             }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0de416b8/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpReceiveLineHandler.java
----------------------------------------------------------------------
diff --git a/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpReceiveLineHandler.java b/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpReceiveLineHandler.java
index d0e611c..a2bfed8 100644
--- a/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpReceiveLineHandler.java
+++ b/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpReceiveLineHandler.java
@@ -21,16 +21,19 @@ package org.apache.sshd.common.scp;
 
 import java.io.IOException;
 
+import org.apache.sshd.common.session.Session;
+
 /**
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  */
 @FunctionalInterface
 public interface ScpReceiveLineHandler {
     /**
+     * @param session The client/server {@link Session} through which the transfer is being executed
      * @param line  Received SCP input line
      * @param isDir Does the input line refer to a directory
      * @param time  The received {@link ScpTimestamp} - may be {@code null}
      * @throws IOException If failed to process the line
      */
-    void process(String line, boolean isDir, ScpTimestamp time) throws IOException;
+    void process(Session session, String line, boolean isDir, ScpTimestamp time) throws IOException;
 }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0de416b8/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpTargetStreamResolver.java
----------------------------------------------------------------------
diff --git a/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpTargetStreamResolver.java b/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpTargetStreamResolver.java
index 9a70302..741b240 100644
--- a/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpTargetStreamResolver.java
+++ b/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpTargetStreamResolver.java
@@ -44,8 +44,9 @@ public interface ScpTargetStreamResolver {
      * @return The {@link OutputStream} to write the incoming data
      * @throws IOException If failed to create the stream
      */
-    OutputStream resolveTargetStream(Session session, String name, long length,
-            Set<PosixFilePermission> perms, OpenOption... options) throws IOException;
+    OutputStream resolveTargetStream(
+        Session session, String name, long length, Set<PosixFilePermission> perms, OpenOption... options)
+            throws IOException;
 
     /**
      * @return The {@link Path} to use when invoking the {@link ScpTransferEventListener}
@@ -63,5 +64,7 @@ public interface ScpTargetStreamResolver {
      *                 incoming data
      * @throws IOException If failed to post-process the incoming data
      */
-    void postProcessReceivedData(String name, boolean preserve, Set<PosixFilePermission> perms, ScpTimestamp time) throws IOException;
+    void postProcessReceivedData(
+            String name, boolean preserve, Set<PosixFilePermission> perms, ScpTimestamp time)
+                throws IOException;
 }


[3/3] mina-sshd git commit: [SSHD-862] Propagate session context to ScpTransferEventListener

Posted by lg...@apache.org.
[SSHD-862] Propagate session context to ScpTransferEventListener


Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/ef6ea9e5
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/ef6ea9e5
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/ef6ea9e5

Branch: refs/heads/master
Commit: ef6ea9e592fe4978c61b525dd61e1e240e0162b6
Parents: c305bc4
Author: Lyor Goldstein <lg...@apache.org>
Authored: Mon Nov 26 16:08:01 2018 +0200
Committer: Lyor Goldstein <lg...@apache.org>
Committed: Mon Nov 26 16:40:54 2018 +0200

----------------------------------------------------------------------
 CHANGES.md                                      |  3 ++
 .../apache/sshd/cli/client/ScpCommandMain.java  | 30 +++++++++++------
 .../SimpleAccessControlScpEventListener.java    | 32 ++++++++++--------
 ...AbstractScpTransferEventListenerAdapter.java | 34 ++++++++++++--------
 .../org/apache/sshd/common/scp/ScpHelper.java   | 31 ++++++++++--------
 .../common/scp/ScpTransferEventListener.java    | 19 ++++++++---
 .../org/apache/sshd/client/scp/ScpTest.java     | 27 ++++++++++------
 7 files changed, 113 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ef6ea9e5/CHANGES.md
----------------------------------------------------------------------
diff --git a/CHANGES.md b/CHANGES.md
index 4c49f02..e43f7b9 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -77,6 +77,9 @@ and moved to `PublicKeyEntry` class.
 
 * `PublicKeyEntryResolver` (and its derived classes) accept an extra `SessionContext` parameter.
 
+* All methods `ScpTransferEventListener` accept an extra `Session` parameter indicating the SSH client/server
+session context for the listener's invocation.
+
 ## Behavioral changes and enhancements
 
 * [SSHD-757](https://issues.apache.org/jira/browse/SSHD-757) - Added hooks and some initial code to allow (limited) usage

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ef6ea9e5/sshd-cli/src/main/java/org/apache/sshd/cli/client/ScpCommandMain.java
----------------------------------------------------------------------
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 88910c2..14233b1 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
@@ -39,6 +39,7 @@ import org.apache.sshd.client.scp.ScpClientCreator;
 import org.apache.sshd.client.session.ClientSession;
 import org.apache.sshd.common.scp.ScpLocation;
 import org.apache.sshd.common.scp.ScpTransferEventListener;
+import org.apache.sshd.common.session.Session;
 import org.apache.sshd.common.util.GenericUtils;
 import org.apache.sshd.common.util.io.NoCloseInputStream;
 import org.apache.sshd.common.util.threads.ThreadUtils;
@@ -206,28 +207,37 @@ public class ScpCommandMain extends SshClientCliSupport {
                 if (!quiet) {
                     creator.setScpTransferEventListener(new ScpTransferEventListener() {
                         @Override
-                        public void startFolderEvent(FileOperation op, Path file, Set<PosixFilePermission> perms) {
-                            logEvent("startFolderEvent", op, file, -1L, perms, null);
+                        public void startFolderEvent(
+                                Session session, FileOperation op, Path file, Set<PosixFilePermission> perms) {
+                            logEvent("startFolderEvent", session, op, file, -1L, perms, null);
                         }
 
                         @Override
-                        public void endFolderEvent(FileOperation op, Path file, Set<PosixFilePermission> perms, Throwable thrown) {
-                            logEvent("endFolderEvent", op, file, -1L, perms, thrown);
+                        public void endFolderEvent(
+                                Session session, FileOperation op, Path file, Set<PosixFilePermission> perms, Throwable thrown) {
+                            logEvent("endFolderEvent", session, op, file, -1L, perms, thrown);
                         }
 
                         @Override
-                        public void startFileEvent(FileOperation op, Path file, long length, Set<PosixFilePermission> perms) {
-                            logEvent("startFileEvent", op, file, length, perms, null);
+                        public void startFileEvent(
+                                Session session, FileOperation op, Path file, long length, Set<PosixFilePermission> perms) {
+                            logEvent("startFileEvent", session, op, file, length, perms, null);
                         }
 
                         @Override
-                        public void endFileEvent(FileOperation op, Path file, long length, Set<PosixFilePermission> perms, Throwable thrown) {
-                            logEvent("endFileEvent", op, file, length, perms, thrown);
+                        public void endFileEvent(
+                                Session session, FileOperation op, Path file, long length, Set<PosixFilePermission> perms, Throwable thrown) {
+                            logEvent("endFileEvent", session, op, file, length, perms, thrown);
                         }
 
-                        private void logEvent(String name, FileOperation op, Path file, long length, Collection<PosixFilePermission> perms, Throwable thrown) {
+                        private void logEvent(
+                                String name, Session session, FileOperation op, Path file, long length,
+                                Collection<PosixFilePermission> perms, Throwable thrown) {
                             PrintStream ps = (thrown == null) ? stdout : stderr;
-                            ps.append('\t').append(name).append('[').append(op.name()).append(']').append(' ').append(file.toString());
+                            ps.append("    ").append(name)
+                                .append('[').append(session.toString()).append(']')
+                                .append('[').append(op.name()).append(']')
+                                .append(' ').append(file.toString());
                             if (length > 0L) {
                                 ps.append(' ').append("length=").append(Long.toString(length));
                             }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ef6ea9e5/sshd-contrib/src/main/java/org/apache/sshd/server/scp/SimpleAccessControlScpEventListener.java
----------------------------------------------------------------------
diff --git a/sshd-contrib/src/main/java/org/apache/sshd/server/scp/SimpleAccessControlScpEventListener.java b/sshd-contrib/src/main/java/org/apache/sshd/server/scp/SimpleAccessControlScpEventListener.java
index 9139bcb..a0568ff 100644
--- a/sshd-contrib/src/main/java/org/apache/sshd/server/scp/SimpleAccessControlScpEventListener.java
+++ b/sshd-contrib/src/main/java/org/apache/sshd/server/scp/SimpleAccessControlScpEventListener.java
@@ -26,6 +26,7 @@ import java.nio.file.attribute.PosixFilePermission;
 import java.util.Set;
 
 import org.apache.sshd.common.scp.AbstractScpTransferEventListenerAdapter;
+import org.apache.sshd.common.session.Session;
 
 /**
  * Provides a simple access control by making a distinction between methods
@@ -37,12 +38,12 @@ public abstract class SimpleAccessControlScpEventListener extends AbstractScpTra
     public static final SimpleAccessControlScpEventListener READ_ONLY_ACCESSOR =
         new SimpleAccessControlScpEventListener() {
             @Override
-            protected boolean isFileUploadAllowed(Path path) throws IOException {
+            protected boolean isFileUploadAllowed(Session session, Path path) throws IOException {
                 return false;
             }
 
             @Override
-            protected boolean isFileDownloadAllowed(Path path) throws IOException {
+            protected boolean isFileDownloadAllowed(Session session, Path path) throws IOException {
                 return true;
             }
     };
@@ -52,18 +53,19 @@ public abstract class SimpleAccessControlScpEventListener extends AbstractScpTra
     }
 
     @Override
-    public void startFileEvent(FileOperation op, Path file, long length, Set<PosixFilePermission> perms)
-            throws IOException {
-        super.startFileEvent(op, file, length, perms);
+    public void startFileEvent(
+            Session session, FileOperation op, Path file, long length, Set<PosixFilePermission> perms)
+                throws IOException {
+        super.startFileEvent(session, op, file, length, perms);
         switch(op) {
             case SEND:
-                if (!isFileDownloadAllowed(file)) {
+                if (!isFileDownloadAllowed(session, file)) {
                     throw new AccessDeniedException(file.toString());
                 }
                 break;
 
             case RECEIVE:
-                if (!isFileUploadAllowed(file)) {
+                if (!isFileUploadAllowed(session, file)) {
                     throw new AccessDeniedException(file.toString());
                 }
                 break;
@@ -73,17 +75,19 @@ public abstract class SimpleAccessControlScpEventListener extends AbstractScpTra
     }
 
     @Override
-    public void startFolderEvent(FileOperation op, Path file, Set<PosixFilePermission> perms) throws IOException {
-        super.startFolderEvent(op, file, perms);
+    public void startFolderEvent(
+            Session session, FileOperation op, Path file, Set<PosixFilePermission> perms)
+                throws IOException {
+        super.startFolderEvent(session, op, file, perms);
         switch(op) {
             case SEND:
-                if (!isFileDownloadAllowed(file)) {
+                if (!isFileDownloadAllowed(session, file)) {
                     throw new AccessDeniedException(file.toString());
                 }
                 break;
 
             case RECEIVE:
-                if (!isFileUploadAllowed(file)) {
+                if (!isFileUploadAllowed(session, file)) {
                     throw new AccessDeniedException(file.toString());
                 }
                 break;
@@ -93,16 +97,18 @@ public abstract class SimpleAccessControlScpEventListener extends AbstractScpTra
     }
 
     /**
+     * @param session The client/server {@link Session} through which the transfer is being executed
      * @param path The local file/folder path
      * @return {@code true} if client is allowed to read from the specified local path
      * @throws IOException If failed to handle the call
      */
-    protected abstract boolean isFileDownloadAllowed(Path path) throws IOException;
+    protected abstract boolean isFileDownloadAllowed(Session session, Path path) throws IOException;
 
     /**
+     * @param session The client/server {@link Session} through which the transfer is being executed
      * @param path The local file/folder path
      * @return {@code true} if client is allowed to write to the specified local path
      * @throws IOException If failed to handle the call
      */
-    protected abstract boolean isFileUploadAllowed(Path path) throws IOException;
+    protected abstract boolean isFileUploadAllowed(Session session, Path path) throws IOException;
 }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ef6ea9e5/sshd-scp/src/main/java/org/apache/sshd/common/scp/AbstractScpTransferEventListenerAdapter.java
----------------------------------------------------------------------
diff --git a/sshd-scp/src/main/java/org/apache/sshd/common/scp/AbstractScpTransferEventListenerAdapter.java b/sshd-scp/src/main/java/org/apache/sshd/common/scp/AbstractScpTransferEventListenerAdapter.java
index d929a07..9d3771c 100644
--- a/sshd-scp/src/main/java/org/apache/sshd/common/scp/AbstractScpTransferEventListenerAdapter.java
+++ b/sshd-scp/src/main/java/org/apache/sshd/common/scp/AbstractScpTransferEventListenerAdapter.java
@@ -24,6 +24,7 @@ import java.nio.file.Path;
 import java.nio.file.attribute.PosixFilePermission;
 import java.util.Set;
 
+import org.apache.sshd.common.session.Session;
 import org.apache.sshd.common.util.logging.AbstractLoggingBean;
 
 /**
@@ -40,35 +41,42 @@ public abstract class AbstractScpTransferEventListenerAdapter
     }
 
     @Override
-    public void startFileEvent(FileOperation op, Path file, long length, Set<PosixFilePermission> perms)
-            throws IOException {
+    public void startFileEvent(
+            Session session, FileOperation op, Path file, long length, Set<PosixFilePermission> perms)
+                throws IOException {
         if (log.isTraceEnabled()) {
-            log.trace("startFileEvent(op=" + op + ", file=" + file + ", length=" + length + ", permissions=" + perms + ")");
+            log.trace("startFileEvent({})[{}] - length={}, permissions={}, file={}", session, op, length, perms, file);
         }
     }
 
     @Override
-    public void endFileEvent(FileOperation op, Path file, long length, Set<PosixFilePermission> perms, Throwable thrown)
-            throws IOException {
+    public void endFileEvent(
+            Session session, FileOperation op, Path file, long length, Set<PosixFilePermission> perms, Throwable thrown)
+                throws IOException {
         if (log.isTraceEnabled()) {
-            log.trace("endFileEvent(op=" + op + ", file=" + file + ", length=" + length + ", permissions=" + perms + ")"
-                    + ((thrown == null) ? "" : (": " + thrown.getClass().getSimpleName() + ": " + thrown.getMessage())));
+            log.trace("endFileEvent({})[{}] - length={}, permissions={}, file={} - {}",
+                session, op, length, perms, file,
+                (thrown == null) ? "OK" : thrown.getClass().getSimpleName() + ": " + thrown.getMessage());
         }
     }
 
     @Override
-    public void startFolderEvent(FileOperation op, Path file, Set<PosixFilePermission> perms) throws IOException {
+    public void startFolderEvent(
+            Session session, FileOperation op, Path file, Set<PosixFilePermission> perms)
+                throws IOException {
         if (log.isTraceEnabled()) {
-            log.trace("startFolderEvent(op=" + op + ", file=" + file + ", permissions=" + perms + ")");
+            log.trace("startFolderEvent({})[{}] - permissions={}, file={}", session, op, perms, file);
         }
     }
 
     @Override
-    public void endFolderEvent(FileOperation op, Path file, Set<PosixFilePermission> perms, Throwable thrown)
-            throws IOException {
+    public void endFolderEvent(
+            Session session, FileOperation op, Path file, Set<PosixFilePermission> perms, Throwable thrown)
+                throws IOException {
         if (log.isTraceEnabled()) {
-            log.trace("endFolderEvent(op=" + op + ", file=" + file + ", permissions=" + perms + ")"
-                    + ((thrown == null) ? "" : (": " + thrown.getClass().getSimpleName() + ": " + thrown.getMessage())));
+            log.trace("endFolderEvent({})[{}] - permissions={}, file={} - {}",
+                session, op, perms, file,
+                (thrown == null) ? "OK" : thrown.getClass().getSimpleName() + ": " + thrown.getMessage());
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ef6ea9e5/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
----------------------------------------------------------------------
diff --git a/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpHelper.java b/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
index d7e6fd8..38331e9 100644
--- a/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
+++ b/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
@@ -248,7 +248,9 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
         ack();
 
         time = null;
-        listener.startFolderEvent(FileOperation.RECEIVE, path, perms);
+
+        Session session = getSession();
+        listener.startFolderEvent(session, FileOperation.RECEIVE, path, perms);
         try {
             for (;;) {
                 header = readLine();
@@ -272,10 +274,10 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
                 }
             }
         } catch (IOException | RuntimeException e) {
-            listener.endFolderEvent(FileOperation.RECEIVE, path, perms, e);
+            listener.endFolderEvent(session, FileOperation.RECEIVE, path, perms, e);
             throw e;
         }
-        listener.endFolderEvent(FileOperation.RECEIVE, path, perms, null);
+        listener.endFolderEvent(session, FileOperation.RECEIVE, path, perms, null);
     }
 
     public void receiveFile(String header, Path local, ScpTimestamp time, boolean preserve, int bufferSize) throws IOException {
@@ -330,14 +332,15 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
             ack();
 
             Path file = resolver.getEventListenerFilePath();
-            listener.startFileEvent(FileOperation.RECEIVE, file, length, perms);
+            Session session = getSession();
+            listener.startFileEvent(session, FileOperation.RECEIVE, file, length, perms);
             try {
                 IoUtils.copy(is, os, bufSize);
             } catch (IOException | RuntimeException e) {
-                listener.endFileEvent(FileOperation.RECEIVE, file, length, perms, e);
+                listener.endFileEvent(session, FileOperation.RECEIVE, file, length, perms, e);
                 throw e;
             }
-            listener.endFileEvent(FileOperation.RECEIVE, file, length, perms, null);
+            listener.endFileEvent(session, FileOperation.RECEIVE, file, length, perms, null);
         }
 
         resolver.postProcessReceivedData(name, preserve, perms, time);
@@ -545,16 +548,17 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
         }
         validateAckReplyCode(cmd, resolver, readyCode, false);
 
-        try (InputStream in = resolver.resolveSourceStream(getSession())) {
+        Session session = getSession();
+        try (InputStream in = resolver.resolveSourceStream(session)) {
             Path path = resolver.getEventListenerFilePath();
-            listener.startFileEvent(FileOperation.SEND, path, fileSize, perms);
+            listener.startFileEvent(session, FileOperation.SEND, path, fileSize, perms);
             try {
                 IoUtils.copy(in, out, bufSize);
             } catch (IOException | RuntimeException e) {
-                listener.endFileEvent(FileOperation.SEND, path, fileSize, perms, e);
+                listener.endFileEvent(session, FileOperation.SEND, path, fileSize, perms, e);
                 throw e;
             }
-            listener.endFileEvent(FileOperation.SEND, path, fileSize, perms, null);
+            listener.endFileEvent(session, FileOperation.SEND, path, fileSize, perms, null);
         }
         ack();
 
@@ -640,8 +644,9 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
         }
         validateAckReplyCode(cmd, path, readyCode, false);
 
+        Session session = getSession();
         try (DirectoryStream<Path> children = opener.getLocalFolderChildren(path)) {
-            listener.startFolderEvent(FileOperation.SEND, path, perms);
+            listener.startFolderEvent(session, FileOperation.SEND, path, perms);
 
             try {
                 for (Path child : children) {
@@ -652,11 +657,11 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
                     }
                 }
             } catch (IOException | RuntimeException e) {
-                listener.endFolderEvent(FileOperation.SEND, path, perms, e);
+                listener.endFolderEvent(session, FileOperation.SEND, path, perms, e);
                 throw e;
             }
 
-            listener.endFolderEvent(FileOperation.SEND, path, perms, null);
+            listener.endFolderEvent(session, FileOperation.SEND, path, perms, null);
         }
 
         if (debugEnabled) {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ef6ea9e5/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpTransferEventListener.java
----------------------------------------------------------------------
diff --git a/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpTransferEventListener.java b/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpTransferEventListener.java
index d7954e0..8559470 100644
--- a/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpTransferEventListener.java
+++ b/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpTransferEventListener.java
@@ -24,6 +24,7 @@ import java.nio.file.Path;
 import java.nio.file.attribute.PosixFilePermission;
 import java.util.Set;
 
+import org.apache.sshd.common.session.Session;
 import org.apache.sshd.common.util.SshdEventListener;
 
 /**
@@ -48,6 +49,7 @@ public interface ScpTransferEventListener extends SshdEventListener {
     };
 
     /**
+     * @param session The client/server {@link Session} through which the transfer is being executed
      * @param op     The {@link FileOperation}
      * @param file   The <U>local</U> referenced file {@link Path}
      * @param length Size (in bytes) of transferred data
@@ -55,11 +57,14 @@ public interface ScpTransferEventListener extends SshdEventListener {
      *               once transfer is complete
      * @throws IOException If failed to handle the event
      */
-    default void startFileEvent(FileOperation op, Path file, long length, Set<PosixFilePermission> perms) throws IOException {
+    default void startFileEvent(
+        Session session, FileOperation op, Path file, long length, Set<PosixFilePermission> perms)
+            throws IOException {
         // ignored
     }
 
     /**
+     * @param session The client/server {@link Session} through which the transfer is being executed
      * @param op     The {@link FileOperation}
      * @param file   The <U>local</U> referenced file {@link Path}
      * @param length Size (in bytes) of transferred data
@@ -69,23 +74,28 @@ public interface ScpTransferEventListener extends SshdEventListener {
      *               reception was successful
      * @throws IOException If failed to handle the event
      */
-    default void endFileEvent(FileOperation op, Path file, long length, Set<PosixFilePermission> perms, Throwable thrown)
+    default void endFileEvent(
+        Session session, FileOperation op, Path file, long length, Set<PosixFilePermission> perms, Throwable thrown)
             throws IOException {
                 // ignored
     }
 
     /**
+     * @param session The client/server {@link Session} through which the transfer is being executed
      * @param op    The {@link FileOperation}
      * @param file  The <U>local</U> referenced folder {@link Path}
      * @param perms A {@link Set} of {@link PosixFilePermission}s to be applied
      *              once transfer is complete
      * @throws IOException If failed to handle the event
      */
-    default void startFolderEvent(FileOperation op, Path file, Set<PosixFilePermission> perms) throws IOException {
+    default void startFolderEvent(
+        Session session, FileOperation op, Path file, Set<PosixFilePermission> perms)
+            throws IOException {
         // ignored
     }
 
     /**
+     * @param session The client/server {@link Session} through which the transfer is being executed
      * @param op     The {@link FileOperation}
      * @param file   The <U>local</U> referenced file {@link Path}
      * @param perms  A {@link Set} of {@link PosixFilePermission}s to be applied
@@ -94,7 +104,8 @@ public interface ScpTransferEventListener extends SshdEventListener {
      *               reception was successful
      * @throws IOException If failed to handle the event
      */
-    default void endFolderEvent(FileOperation op, Path file, Set<PosixFilePermission> perms, Throwable thrown)
+    default void endFolderEvent(
+        Session session, FileOperation op, Path file, Set<PosixFilePermission> perms, Throwable thrown)
             throws IOException {
         // ignored
     }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ef6ea9e5/sshd-scp/src/test/java/org/apache/sshd/client/scp/ScpTest.java
----------------------------------------------------------------------
diff --git a/sshd-scp/src/test/java/org/apache/sshd/client/scp/ScpTest.java b/sshd-scp/src/test/java/org/apache/sshd/client/scp/ScpTest.java
index f6b89db..62f6a3e 100644
--- a/sshd-scp/src/test/java/org/apache/sshd/client/scp/ScpTest.java
+++ b/sshd-scp/src/test/java/org/apache/sshd/client/scp/ScpTest.java
@@ -92,32 +92,39 @@ import ch.ethz.ssh2.SCPClient;
 public class ScpTest extends BaseTestSupport {
     private static final ScpTransferEventListener DEBUG_LISTENER = new ScpTransferEventListener() {
         @Override
-        public void startFolderEvent(FileOperation op, Path file, Set<PosixFilePermission> perms) {
-            logEvent("starFolderEvent", op, file, false, -1L, perms, null);
+        public void startFolderEvent(
+                Session s, FileOperation op, Path file, Set<PosixFilePermission> perms) {
+            logEvent("starFolderEvent", s, op, file, false, -1L, perms, null);
         }
 
         @Override
-        public void startFileEvent(FileOperation op, Path file, long length, Set<PosixFilePermission> perms) {
-            logEvent("startFileEvent", op, file, true, length, perms, null);
+        public void startFileEvent(
+                Session s, FileOperation op, Path file, long length, Set<PosixFilePermission> perms) {
+            logEvent("startFileEvent", s, op, file, true, length, perms, null);
 
         }
 
         @Override
-        public void endFolderEvent(FileOperation op, Path file, Set<PosixFilePermission> perms, Throwable thrown) {
-            logEvent("endFolderEvent", op, file, false, -1L, perms, thrown);
+        public void endFolderEvent(
+                Session s, FileOperation op, Path file, Set<PosixFilePermission> perms, Throwable thrown) {
+            logEvent("endFolderEvent", s, op, file, false, -1L, perms, thrown);
         }
 
         @Override
-        public void endFileEvent(FileOperation op, Path file, long length, Set<PosixFilePermission> perms, Throwable thrown) {
-            logEvent("endFileEvent", op, file, true, length, perms, thrown);
+        public void endFileEvent(
+                Session s, FileOperation op, Path file, long length, Set<PosixFilePermission> perms, Throwable thrown) {
+            logEvent("endFileEvent", s, op, file, true, length, perms, thrown);
         }
 
-        private void logEvent(String type, FileOperation op, Path path, boolean isFile, long length, Collection<PosixFilePermission> perms, Throwable t) {
+        private void logEvent(
+                String type, Session s, FileOperation op, Path path, boolean isFile,
+                long length, Collection<PosixFilePermission> perms, Throwable t) {
             if (!OUTPUT_DEBUG_MESSAGES) {
                 return; // just in case
             }
             StringBuilder sb = new StringBuilder(Byte.MAX_VALUE);
-            sb.append('\t').append(type)
+            sb.append("    ").append(type)
+                    .append('[').append(s).append(']')
                     .append('[').append(op).append(']')
                     .append(' ').append(isFile ? "File" : "Directory").append('=').append(path)
                     .append(' ').append("length=").append(length)


[2/3] mina-sshd git commit: [SSHD-862] Added session context parameter to ScpFileOpener methods

Posted by lg...@apache.org.
[SSHD-862] Added session context parameter to ScpFileOpener methods


Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/857172b7
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/857172b7
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/857172b7

Branch: refs/heads/master
Commit: 857172b7835b074b6080fc93874334afbb4f1e35
Parents: ef6ea9e
Author: Lyor Goldstein <lg...@apache.org>
Authored: Mon Nov 26 16:19:54 2018 +0200
Committer: Lyor Goldstein <lg...@apache.org>
Committed: Mon Nov 26 16:40:54 2018 +0200

----------------------------------------------------------------------
 CHANGES.md                                      |  1 +
 .../apache/sshd/common/scp/ScpFileOpener.java   | 48 ++++++++++++++------
 .../org/apache/sshd/common/scp/ScpHelper.java   | 40 ++++++++--------
 .../scp/helpers/DefaultScpFileOpener.java       |  4 +-
 .../LocalFileScpSourceStreamResolver.java       |  3 +-
 5 files changed, 60 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/857172b7/CHANGES.md
----------------------------------------------------------------------
diff --git a/CHANGES.md b/CHANGES.md
index e43f7b9..4daa2c7 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -79,6 +79,7 @@ and moved to `PublicKeyEntry` class.
 
 * All methods `ScpTransferEventListener` accept an extra `Session` parameter indicating the SSH client/server
 session context for the listener's invocation.
+    * Same applies for `ScpFileOpener`
 
 ## Behavioral changes and enhancements
 

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/857172b7/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpFileOpener.java
----------------------------------------------------------------------
diff --git a/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpFileOpener.java b/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpFileOpener.java
index 78e033f..61b696a 100644
--- a/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpFileOpener.java
+++ b/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpFileOpener.java
@@ -58,6 +58,7 @@ public interface ScpFileOpener {
     /**
      * Invoked when receiving a new file to via a directory command
      *
+     * @param session The client/server {@link Session} through which the transfer is being executed
      * @param localPath The target local path
      * @param name The target file name
      * @param preserve Whether requested to preserve the permissions and timestamp
@@ -68,8 +69,8 @@ public interface ScpFileOpener {
      * @see #updateFileProperties(Path, Set, ScpTimestamp) updateFileProperties
      */
     default Path resolveIncomingFilePath(
-            Path localPath, String name, boolean preserve, Set<PosixFilePermission> permissions, ScpTimestamp time)
-                    throws IOException {
+            Session session, Path localPath, String name, boolean preserve, Set<PosixFilePermission> permissions, ScpTimestamp time)
+                throws IOException {
         LinkOption[] options = IoUtils.getLinkOptions(true);
         Boolean status = IoUtils.checkFileExists(localPath, options);
         if (status == null) {
@@ -116,11 +117,12 @@ public interface ScpFileOpener {
     /**
      * Invoked when required to send a pattern of files
      *
+     * @param session The client/server {@link Session} through which the transfer is being executed
      * @param basedir The base directory - may be {@code null}/empty to indicate CWD
      * @param pattern The required pattern
      * @return The matching <U>relative paths</U> of the children to send
      */
-    default Iterable<String> getMatchingFilesToSend(String basedir, String pattern) {
+    default Iterable<String> getMatchingFilesToSend(Session session, String basedir, String pattern) {
         String[] matches = new DirectoryScanner(basedir, pattern).scan();
         if (GenericUtils.isEmpty(matches)) {
             return Collections.emptyList();
@@ -133,13 +135,15 @@ public interface ScpFileOpener {
      * Invoked on a local path in order to decide whether it should be sent
      * as a file or as a directory
      *
+     * @param session The client/server {@link Session} through which the transfer is being executed
      * @param path The local {@link Path}
      * @param options The {@link LinkOption}-s
      * @return Whether to send the file as a regular one - <B>Note:</B> if {@code false}
      * then the {@link #sendAsDirectory(Path, LinkOption...)} is consulted.
      * @throws IOException If failed to decide
      */
-    default boolean sendAsRegularFile(Path path, LinkOption... options) throws IOException {
+    default boolean sendAsRegularFile(Session session, Path path, LinkOption... options)
+            throws IOException {
         return Files.isRegularFile(path, options);
     }
 
@@ -147,20 +151,23 @@ public interface ScpFileOpener {
      * Invoked on a local path in order to decide whether it should be sent
      * as a file or as a directory
      *
+     * @param session The client/server {@link Session} through which the transfer is being executed
      * @param path The local {@link Path}
      * @param options The {@link LinkOption}-s
      * @return Whether to send the file as a directory - <B>Note:</B> if {@code true}
      * then {@link #getLocalFolderChildren(Path)} is consulted
      * @throws IOException If failed to decide
      */
-    default boolean sendAsDirectory(Path path, LinkOption... options) throws IOException {
+    default boolean sendAsDirectory(Session session, Path path, LinkOption... options)
+            throws IOException {
         return Files.isDirectory(path, options);
     }
 
     /**
      * Invoked when required to send all children of a local directory
      *
-     * @param path The local folder {@link Path}{
+     * @param session The client/server {@link Session} through which the transfer is being executed
+     * @param path The local folder {@link Path}
      * @return The {@link DirectoryStream} of children to send - <B>Note:</B> for each child
      * the decision whether to send it as a file or a directory will be reached by consulting
      * the respective {@link #sendAsRegularFile(Path, LinkOption...) sendAsRegularFile} and
@@ -168,26 +175,33 @@ public interface ScpFileOpener {
      * @throws IOException If failed to provide the children stream
      * @see #sendAsDirectory(Path, LinkOption...) sendAsDirectory
      */
-    default DirectoryStream<Path> getLocalFolderChildren(Path path) throws IOException {
+    default DirectoryStream<Path> getLocalFolderChildren(Session session, Path path) throws IOException {
         return Files.newDirectoryStream(path);
     }
 
-    default BasicFileAttributes getLocalBasicFileAttributes(Path path, LinkOption... options) throws IOException {
-        return Files.getFileAttributeView(path, BasicFileAttributeView.class, options).readAttributes();
+    default BasicFileAttributes getLocalBasicFileAttributes(
+            Session session, Path path, LinkOption... options)
+                throws IOException {
+        BasicFileAttributeView view = Files.getFileAttributeView(path, BasicFileAttributeView.class, options);
+        return view.readAttributes();
     }
 
-    default Set<PosixFilePermission> getLocalFilePermissions(Path path, LinkOption... options) throws IOException {
+    default Set<PosixFilePermission> getLocalFilePermissions(
+            Session session, Path path, LinkOption... options)
+                throws IOException {
         return IoUtils.getPermissions(path, options);
     }
 
     /**
+     * @param session The client/server {@link Session} through which the transfer is being executed
      * @param fileSystem The <U>local</U> {@link FileSystem} on which local file should reside
      * @param commandPath The command path using the <U>local</U> file separator
      * @return The resolved absolute and normalized local {@link Path}
      * @throws IOException If failed to resolve the path
      * @throws InvalidPathException If invalid local path value
      */
-    default Path resolveLocalPath(FileSystem fileSystem, String commandPath) throws IOException, InvalidPathException {
+    default Path resolveLocalPath(Session session, FileSystem fileSystem, String commandPath)
+            throws IOException, InvalidPathException {
         String path = SelectorUtils.translateToLocalFileSystemPath(commandPath, File.separatorChar, fileSystem);
         Path lcl = fileSystem.getPath(path);
         Path abs = lcl.isAbsolute() ? lcl : lcl.toAbsolutePath();
@@ -197,6 +211,7 @@ public interface ScpFileOpener {
     /**
      * Invoked when a request to receive something is processed
      *
+     * @param session The client/server {@link Session} through which the transfer is being executed
      * @param path The local target {@link Path} of the request
      * @param recursive Whether the request is recursive
      * @param shouldBeDir Whether target path is expected to be a directory
@@ -205,7 +220,7 @@ public interface ScpFileOpener {
      * @throws IOException If failed to resolve target location
      */
     default Path resolveIncomingReceiveLocation(
-            Path path, boolean recursive, boolean shouldBeDir, boolean preserve)
+            Session session, Path path, boolean recursive, boolean shouldBeDir, boolean preserve)
                 throws IOException {
         if (!shouldBeDir) {
             return path;
@@ -228,12 +243,15 @@ public interface ScpFileOpener {
     /**
      * Called when there is a candidate file/folder for sending
      *
+     * @param session The client/server {@link Session} through which the transfer is being executed
      * @param localPath The original file/folder {@link Path} for sending
      * @param options The {@link LinkOption}-s to use for validation
      * @return The effective outgoing file path (default=same as input)
      * @throws IOException If failed to resolve
      */
-    default Path resolveOutgoingFilePath(Path localPath, LinkOption... options) throws IOException {
+    default Path resolveOutgoingFilePath(
+            Session session, Path localPath, LinkOption... options)
+                throws IOException {
         Boolean status = IoUtils.checkFileExists(localPath, options);
         if (status == null) {
             throw new AccessDeniedException("Send file existence status cannot be determined: " + localPath);
@@ -256,7 +274,7 @@ public interface ScpFileOpener {
      */
     InputStream openRead(Session session, Path file, OpenOption... options) throws IOException;
 
-    ScpSourceStreamResolver createScpSourceStreamResolver(Path path) throws IOException;
+    ScpSourceStreamResolver createScpSourceStreamResolver(Session session, Path path) throws IOException;
 
     /**
      * Create an output stream to write to a file
@@ -269,7 +287,7 @@ public interface ScpFileOpener {
      */
     OutputStream openWrite(Session session, Path file, OpenOption... options) throws IOException;
 
-    ScpTargetStreamResolver createScpTargetStreamResolver(Path path) throws IOException;
+    ScpTargetStreamResolver createScpTargetStreamResolver(Session session, Path path) throws IOException;
 
     static void updateFileProperties(Path file, Set<PosixFilePermission> perms, ScpTimestamp time) throws IOException {
         IoUtils.setPermissions(file, perms);

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/857172b7/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
----------------------------------------------------------------------
diff --git a/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpHelper.java b/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
index 38331e9..eb447db 100644
--- a/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
+++ b/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
@@ -161,7 +161,7 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
 
     public void receive(Path local, boolean recursive, boolean shouldBeDir, boolean preserve, int bufferSize) throws IOException {
         Path localPath = Objects.requireNonNull(local, "No local path").normalize().toAbsolutePath();
-        Path path = opener.resolveIncomingReceiveLocation(localPath, recursive, shouldBeDir, preserve);
+        Path path = opener.resolveIncomingReceiveLocation(getSession(), localPath, recursive, shouldBeDir, preserve);
         receive((line, isDir, time) -> {
             if (recursive && isDir) {
                 receiveDir(line, path, time, preserve, bufferSize);
@@ -243,13 +243,13 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
             throw new IOException("Expected 0 length for directory=" + name + " but got " + length);
         }
 
-        Path file = opener.resolveIncomingFilePath(path, name, preserve, perms, time);
+        Session session = getSession();
+        Path file = opener.resolveIncomingFilePath(session, path, name, preserve, perms, time);
 
         ack();
 
         time = null;
 
-        Session session = getSession();
         listener.startFolderEvent(session, FileOperation.RECEIVE, path, perms);
         try {
             for (;;) {
@@ -287,7 +287,8 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
                       this, header, path, preserve, time, bufferSize);
         }
 
-        receiveStream(header, opener.createScpTargetStreamResolver(path), time, preserve, bufferSize);
+        ScpTargetStreamResolver targetStreamResolver = opener.createScpTargetStreamResolver(getSession(), path);
+        receiveStream(header, targetStreamResolver, time, preserve, bufferSize);
     }
 
     public void receiveStream(String header, ScpTargetStreamResolver resolver, ScpTimestamp time, boolean preserve, int bufferSize) throws IOException {
@@ -398,12 +399,13 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
                     pattern = pattern.substring(lastSep + 1);
                 }
 
-                Iterable<String> included = opener.getMatchingFilesToSend(basedir, pattern);
+                Session session = getSession();
+                Iterable<String> included = opener.getMatchingFilesToSend(session, basedir, pattern);
                 for (String path : included) {
                     Path file = resolveLocalPath(basedir, path);
-                    if (opener.sendAsRegularFile(file, options)) {
+                    if (opener.sendAsRegularFile(session, file, options)) {
                         sendFile(file, preserve, bufferSize);
-                    } else if (opener.sendAsDirectory(file, options)) {
+                    } else if (opener.sendAsDirectory(session, file, options)) {
                         if (!recursive) {
                             if (debugEnabled) {
                                 log.debug("send({}) {}: not a regular file", this, path);
@@ -440,10 +442,11 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
 
     protected void send(Path local, boolean recursive, boolean preserve, int bufferSize, LinkOption... options) throws IOException {
         Path localPath = Objects.requireNonNull(local, "No local path").normalize().toAbsolutePath();
-        Path file = opener.resolveOutgoingFilePath(localPath, options);
-        if (opener.sendAsRegularFile(file, options)) {
+        Session session = getSession();
+        Path file = opener.resolveOutgoingFilePath(session, localPath, options);
+        if (opener.sendAsRegularFile(session, file, options)) {
             sendFile(file, preserve, bufferSize);
-        } else if (opener.sendAsDirectory(file, options)) {
+        } else if (opener.sendAsDirectory(session, file, options)) {
             if (!recursive) {
                 throw new IOException(file + " not a regular file");
             } else {
@@ -469,7 +472,7 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
      * @throws InvalidPathException If invalid local path value
      */
     public Path resolveLocalPath(String commandPath) throws IOException, InvalidPathException {
-        Path p = opener.resolveLocalPath(fileSystem, commandPath);
+        Path p = opener.resolveLocalPath(getSession(), fileSystem, commandPath);
         if (log.isTraceEnabled()) {
             log.trace("resolveLocalPath({}) {}: {}", this, commandPath, p);
         }
@@ -483,7 +486,8 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
             log.debug("sendFile({})[preserve={},buffer-size={}] Sending file {}", this, preserve, bufferSize, path);
         }
 
-        sendStream(opener.createScpSourceStreamResolver(path), preserve, bufferSize);
+        ScpSourceStreamResolver sourceStreamResolver = opener.createScpSourceStreamResolver(getSession(), path);
+        sendStream(sourceStreamResolver, preserve, bufferSize);
     }
 
     public void sendStream(ScpSourceStreamResolver resolver, boolean preserve, int bufferSize) throws IOException {
@@ -602,8 +606,9 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
         }
 
         LinkOption[] options = IoUtils.getLinkOptions(true);
+        Session session = getSession();
         if (preserve) {
-            BasicFileAttributes basic = opener.getLocalBasicFileAttributes(path, options);
+            BasicFileAttributes basic = opener.getLocalBasicFileAttributes(session, path, options);
             FileTime lastModified = basic.lastModifiedTime();
             FileTime lastAccess = basic.lastAccessTime();
             String cmd = "T" + lastModified.to(TimeUnit.SECONDS) + " "
@@ -627,7 +632,7 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
             validateAckReplyCode(cmd, path, readyCode, false);
         }
 
-        Set<PosixFilePermission> perms = opener.getLocalFilePermissions(path, options);
+        Set<PosixFilePermission> perms = opener.getLocalFilePermissions(session, path, options);
         String octalPerms = ((!preserve) || GenericUtils.isEmpty(perms)) ? DEFAULT_DIR_OCTAL_PERMISSIONS : getOctalPermissions(perms);
         String cmd = "D" + octalPerms + " " + "0" + " " + Objects.toString(path.getFileName(), null);
         if (debugEnabled) {
@@ -644,15 +649,14 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
         }
         validateAckReplyCode(cmd, path, readyCode, false);
 
-        Session session = getSession();
-        try (DirectoryStream<Path> children = opener.getLocalFolderChildren(path)) {
+        try (DirectoryStream<Path> children = opener.getLocalFolderChildren(session, path)) {
             listener.startFolderEvent(session, FileOperation.SEND, path, perms);
 
             try {
                 for (Path child : children) {
-                    if (opener.sendAsRegularFile(child, options)) {
+                    if (opener.sendAsRegularFile(session, child, options)) {
                         sendFile(child, preserve, bufferSize);
-                    } else if (opener.sendAsDirectory(child, options)) {
+                    } else if (opener.sendAsDirectory(session, child, options)) {
                         sendDir(child, preserve, bufferSize);
                     }
                 }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/857172b7/sshd-scp/src/main/java/org/apache/sshd/common/scp/helpers/DefaultScpFileOpener.java
----------------------------------------------------------------------
diff --git a/sshd-scp/src/main/java/org/apache/sshd/common/scp/helpers/DefaultScpFileOpener.java b/sshd-scp/src/main/java/org/apache/sshd/common/scp/helpers/DefaultScpFileOpener.java
index bb6ae3b..7516e8c 100644
--- a/sshd-scp/src/main/java/org/apache/sshd/common/scp/helpers/DefaultScpFileOpener.java
+++ b/sshd-scp/src/main/java/org/apache/sshd/common/scp/helpers/DefaultScpFileOpener.java
@@ -64,12 +64,12 @@ public class DefaultScpFileOpener extends AbstractLoggingBean implements ScpFile
     }
 
     @Override
-    public ScpSourceStreamResolver createScpSourceStreamResolver(Path path) throws IOException {
+    public ScpSourceStreamResolver createScpSourceStreamResolver(Session session, Path path) throws IOException {
         return new LocalFileScpSourceStreamResolver(path, this);
     }
 
     @Override
-    public ScpTargetStreamResolver createScpTargetStreamResolver(Path path) throws IOException {
+    public ScpTargetStreamResolver createScpTargetStreamResolver(Session session, Path path) throws IOException {
         return new LocalFileScpTargetStreamResolver(path, this);
     }
 }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/857172b7/sshd-scp/src/main/java/org/apache/sshd/common/scp/helpers/LocalFileScpSourceStreamResolver.java
----------------------------------------------------------------------
diff --git a/sshd-scp/src/main/java/org/apache/sshd/common/scp/helpers/LocalFileScpSourceStreamResolver.java b/sshd-scp/src/main/java/org/apache/sshd/common/scp/helpers/LocalFileScpSourceStreamResolver.java
index 8ce9b61..cdc47c6 100644
--- a/sshd-scp/src/main/java/org/apache/sshd/common/scp/helpers/LocalFileScpSourceStreamResolver.java
+++ b/sshd-scp/src/main/java/org/apache/sshd/common/scp/helpers/LocalFileScpSourceStreamResolver.java
@@ -55,7 +55,8 @@ public class LocalFileScpSourceStreamResolver extends AbstractLoggingBean implem
         this.name = path.getFileName();
         this.perms = IoUtils.getPermissions(path);
 
-        BasicFileAttributes basic = Files.getFileAttributeView(path, BasicFileAttributeView.class).readAttributes();
+        BasicFileAttributeView view = Files.getFileAttributeView(path, BasicFileAttributeView.class);
+        BasicFileAttributes basic = view.readAttributes();
         this.size = basic.size();
         this.time = new ScpTimestamp(basic.lastModifiedTime().toMillis(), basic.lastAccessTime().toMillis());
     }