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 2021/03/05 09:26:11 UTC
[mina-sshd] 01/07: [SSHD-1133] Re-factored locations and names of
ServerSession and server-side ChannelSession related classes
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 80c5e16cd23dd4727c3542d64e552ad83e7c05e1
Author: Lyor Goldstein <lg...@apache.org>
AuthorDate: Fri Feb 26 10:26:50 2021 +0200
[SSHD-1133] Re-factored locations and names of ServerSession and server-side ChannelSession related classes
---
CHANGES.md | 2 +
.../org/apache/sshd/cli/server/SshFsMounter.java | 4 +-
.../sshd/server/channel/ChannelDataReceiver.java | 4 +-
.../apache/sshd/server/channel/ChannelSession.java | 7 +-
.../server/{ => channel}/ChannelSessionAware.java | 3 +-
.../ServerChannelSessionHolder.java} | 14 +--
.../server/command/AbstractCommandSupport.java | 4 +-
.../command/AbstractDelegatingCommandFactory.java | 15 +--
.../ServerSessionAware.java} | 6 +-
.../apache/sshd/server/shell/InvertedShell.java | 14 +--
.../sshd/server/shell/InvertedShellWrapper.java | 6 +-
.../org/apache/sshd/server/shell/ProcessShell.java | 8 +-
.../server/shell/InvertedShellWrapperTest.java | 8 +-
.../sshd/util/test/AsyncEchoShellFactory.java | 2 +-
.../apache/sshd/util/test/BogusInvertedShell.java | 2 +-
.../apache/sshd/git/AbstractGitCommandFactory.java | 7 +-
.../org/apache/sshd/scp/server/ScpCommand.java | 16 ++-
.../apache/sshd/scp/server/ScpCommandFactory.java | 6 +-
.../java/org/apache/sshd/scp/server/ScpShell.java | 36 ++++---
.../java/org/apache/sshd/scp/client/ScpTest.java | 8 +-
.../sftp/server/AbstractSftpSubsystemHelper.java | 10 +-
.../org/apache/sshd/sftp/server/SftpSubsystem.java | 110 ++++++++++-----------
.../sshd/sftp/server/SftpSubsystemEnvironment.java | 3 +-
.../sshd/sftp/server/SftpSubsystemFactory.java | 2 +-
.../apache/sshd/sftp/client/SftpVersionsTest.java | 4 +-
.../helpers/SpaceAvailableExtensionImplTest.java | 2 +-
.../openssh/helpers/OpenSSHExtensionsTest.java | 2 +-
27 files changed, 162 insertions(+), 143 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index 942ed01..6e44df8 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -14,6 +14,8 @@
## Major code re-factoring
+* [SSHD-1133](https://issues.apache.org/jira/browse/SSHD-1133) Re-factored locations and names of `ServerSession` and server-side `ChannelSession` related classes
+
## Minor code helpers
* [SSHD-525](https://issues.apache.org/jira/browse/SSHD-525) Added support for SFTP **client-side** ["posix-rename@openssh.com"
diff --git a/sshd-cli/src/test/java/org/apache/sshd/cli/server/SshFsMounter.java b/sshd-cli/src/test/java/org/apache/sshd/cli/server/SshFsMounter.java
index d7e29b7..4a55cdf 100644
--- a/sshd-cli/src/test/java/org/apache/sshd/cli/server/SshFsMounter.java
+++ b/sshd-cli/src/test/java/org/apache/sshd/cli/server/SshFsMounter.java
@@ -49,7 +49,6 @@ import org.apache.sshd.common.util.threads.ThreadUtils;
import org.apache.sshd.scp.server.ScpCommandFactory;
import org.apache.sshd.server.Environment;
import org.apache.sshd.server.ExitCallback;
-import org.apache.sshd.server.SessionAware;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.auth.password.AcceptAllPasswordAuthenticator;
import org.apache.sshd.server.channel.ChannelSession;
@@ -58,6 +57,7 @@ import org.apache.sshd.server.command.CommandFactory;
import org.apache.sshd.server.forward.AcceptAllForwardingFilter;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.server.session.ServerSession;
+import org.apache.sshd.server.session.ServerSessionAware;
import org.apache.sshd.server.shell.ShellFactory;
import org.apache.sshd.sftp.server.SftpSubsystemFactory;
import org.apache.sshd.util.test.CommonTestSupportUtils;
@@ -69,7 +69,7 @@ import org.apache.sshd.util.test.CoreTestSupportUtils;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public final class SshFsMounter extends SshServerCliSupport {
- public static class MounterCommand extends AbstractLoggingBean implements Command, SessionAware, Runnable {
+ public static class MounterCommand extends AbstractLoggingBean implements Command, ServerSessionAware, Runnable {
private final String command;
private final String cmdName;
private final List<String> args;
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelDataReceiver.java b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelDataReceiver.java
index 1049cc3..da0d1ab 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelDataReceiver.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelDataReceiver.java
@@ -33,11 +33,11 @@ import java.io.IOException;
* command wants to do a callback-driven I/O for the data it receives from the client, it can call
* {@link ChannelSession#setDataReceiver(ChannelDataReceiver)} to do so. (And to grab a reference to
* {@link ChannelSession}, a {@link org.apache.sshd.server.command.Command} should implement
- * {@link org.apache.sshd.server.ChannelSessionAware}.)
+ * {@link org.apache.sshd.server.channel.ChannelSessionAware}.)
* </p>
*
* @see ChannelSession#setDataReceiver(ChannelDataReceiver)
- * @see org.apache.sshd.server.ChannelSessionAware
+ * @see org.apache.sshd.server.channel.ChannelSessionAware
*/
public interface ChannelDataReceiver extends Closeable {
/**
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java
index 86b4bbf..adae173 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java
@@ -62,10 +62,8 @@ import org.apache.sshd.common.util.closeable.IoBaseCloseable;
import org.apache.sshd.common.util.io.IoUtils;
import org.apache.sshd.common.util.io.LoggingFilterOutputStream;
import org.apache.sshd.core.CoreModuleProperties;
-import org.apache.sshd.server.ChannelSessionAware;
import org.apache.sshd.server.Environment;
import org.apache.sshd.server.ServerFactoryManager;
-import org.apache.sshd.server.SessionAware;
import org.apache.sshd.server.Signal;
import org.apache.sshd.server.StandardEnvironment;
import org.apache.sshd.server.command.AsyncCommandInputStreamAware;
@@ -75,6 +73,7 @@ import org.apache.sshd.server.command.CommandFactory;
import org.apache.sshd.server.forward.AgentForwardingFilter;
import org.apache.sshd.server.forward.X11ForwardingFilter;
import org.apache.sshd.server.session.ServerSession;
+import org.apache.sshd.server.session.ServerSessionAware;
import org.apache.sshd.server.shell.ShellFactory;
import org.apache.sshd.server.subsystem.SubsystemFactory;
import org.apache.sshd.server.x11.X11ForwardSupport;
@@ -707,8 +706,8 @@ public class ChannelSession extends AbstractServerChannel {
Session session = getSession();
addEnvVariable(Environment.ENV_USER, session.getUsername());
// If the shell wants to be aware of the session, let's do that
- if (command instanceof SessionAware) {
- ((SessionAware) command).setSession((ServerSession) session);
+ if (command instanceof ServerSessionAware) {
+ ((ServerSessionAware) command).setSession((ServerSession) session);
}
if (command instanceof ChannelSessionAware) {
((ChannelSessionAware) command).setChannelSession(this);
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/ChannelSessionAware.java b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSessionAware.java
similarity index 93%
rename from sshd-core/src/main/java/org/apache/sshd/server/ChannelSessionAware.java
rename to sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSessionAware.java
index 5936ed2..949c934 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/ChannelSessionAware.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSessionAware.java
@@ -16,9 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.sshd.server;
+package org.apache.sshd.server.channel;
-import org.apache.sshd.server.channel.ChannelSession;
import org.apache.sshd.server.command.Command;
/**
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/SessionAware.java b/sshd-core/src/main/java/org/apache/sshd/server/channel/ServerChannelSessionHolder.java
similarity index 67%
copy from sshd-core/src/main/java/org/apache/sshd/server/SessionAware.java
copy to sshd-core/src/main/java/org/apache/sshd/server/channel/ServerChannelSessionHolder.java
index 4070096..ebb87c0 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/SessionAware.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/channel/ServerChannelSessionHolder.java
@@ -16,19 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.sshd.server;
-import org.apache.sshd.server.session.ServerSession;
+package org.apache.sshd.server.channel;
/**
- * Interface that can be implemented by a command to be able to access the server session in which this command will be
- * used.
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
@FunctionalInterface
-public interface SessionAware {
-
- /**
- * @param session The {@link ServerSession} in which this shell will be executed.
- */
- void setSession(ServerSession session);
+public interface ServerChannelSessionHolder {
+ ChannelSession getServerChannelSession();
}
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/command/AbstractCommandSupport.java b/sshd-core/src/main/java/org/apache/sshd/server/command/AbstractCommandSupport.java
index 4511e29..b09bf4d 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/command/AbstractCommandSupport.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/command/AbstractCommandSupport.java
@@ -34,9 +34,9 @@ import org.apache.sshd.common.util.threads.ExecutorServiceCarrier;
import org.apache.sshd.common.util.threads.ThreadUtils;
import org.apache.sshd.server.Environment;
import org.apache.sshd.server.ExitCallback;
-import org.apache.sshd.server.SessionAware;
import org.apache.sshd.server.channel.ChannelSession;
import org.apache.sshd.server.session.ServerSession;
+import org.apache.sshd.server.session.ServerSessionAware;
import org.apache.sshd.server.session.ServerSessionHolder;
/**
@@ -46,7 +46,7 @@ import org.apache.sshd.server.session.ServerSessionHolder;
*/
public abstract class AbstractCommandSupport
extends AbstractLoggingBean
- implements Command, Runnable, ExecutorServiceCarrier, SessionAware,
+ implements Command, Runnable, ExecutorServiceCarrier, ServerSessionAware,
SessionHolder<ServerSession>, ServerSessionHolder {
protected volatile Thread cmdRunner;
protected CloseableExecutorService executorService;
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/command/AbstractDelegatingCommandFactory.java b/sshd-core/src/main/java/org/apache/sshd/server/command/AbstractDelegatingCommandFactory.java
index c94e910..3833e0e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/command/AbstractDelegatingCommandFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/command/AbstractDelegatingCommandFactory.java
@@ -26,7 +26,7 @@ import org.apache.sshd.common.util.logging.AbstractLoggingBean;
import org.apache.sshd.server.channel.ChannelSession;
/**
- * TODO Add javadoc
+ * A {@link CommandFactory} wrapper that delegates calls to a proxy
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
@@ -58,8 +58,8 @@ public abstract class AbstractDelegatingCommandFactory extends AbstractLoggingBe
@Override
public Command createCommand(ChannelSession channel, String command) throws IOException {
- if (isSupportedCommand(command)) {
- return executeSupportedCommand(command);
+ if (isSupportedCommand(channel, command)) {
+ return executeSupportedCommand(channel, command);
}
CommandFactory factory = getDelegateCommandFactory();
@@ -67,19 +67,20 @@ public abstract class AbstractDelegatingCommandFactory extends AbstractLoggingBe
return factory.createCommand(channel, command);
}
- return createUnsupportedCommand(command);
+ return createUnsupportedCommand(channel, command);
}
/**
+ * @param channel The {@link ChannelSession} through which the command was received
* @param command The command about to be executed
* @return {@code true} if this command is supported by the command factory, {@code false} if it will be
* passed on to the {@link #getDelegateCommandFactory() delegate} factory
*/
- public abstract boolean isSupportedCommand(String command);
+ public abstract boolean isSupportedCommand(ChannelSession channel, String command);
- protected abstract Command executeSupportedCommand(String command);
+ protected abstract Command executeSupportedCommand(ChannelSession channel, String command);
- protected Command createUnsupportedCommand(String command) {
+ protected Command createUnsupportedCommand(ChannelSession channel, String command) {
throw new IllegalArgumentException("Unknown command to execute: " + command);
}
}
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/SessionAware.java b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionAware.java
similarity index 90%
rename from sshd-core/src/main/java/org/apache/sshd/server/SessionAware.java
rename to sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionAware.java
index 4070096..5fc4d94 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/SessionAware.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionAware.java
@@ -16,16 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.sshd.server;
-
-import org.apache.sshd.server.session.ServerSession;
+package org.apache.sshd.server.session;
/**
* Interface that can be implemented by a command to be able to access the server session in which this command will be
* used.
*/
@FunctionalInterface
-public interface SessionAware {
+public interface ServerSessionAware {
/**
* @param session The {@link ServerSession} in which this shell will be executed.
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShell.java b/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShell.java
index 2d5cfe0..6c84e1f 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShell.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShell.java
@@ -22,10 +22,10 @@ import java.io.InputStream;
import java.io.OutputStream;
import org.apache.sshd.common.session.SessionHolder;
-import org.apache.sshd.server.SessionAware;
-import org.apache.sshd.server.channel.ChannelSession;
+import org.apache.sshd.server.channel.ServerChannelSessionHolder;
import org.apache.sshd.server.command.CommandLifecycle;
import org.apache.sshd.server.session.ServerSession;
+import org.apache.sshd.server.session.ServerSessionAware;
import org.apache.sshd.server.session.ServerSessionHolder;
/**
@@ -37,9 +37,9 @@ import org.apache.sshd.server.session.ServerSessionHolder;
*/
public interface InvertedShell
extends SessionHolder<ServerSession>,
- ServerSessionHolder,
+ ServerSessionHolder, ServerChannelSessionHolder,
CommandLifecycle,
- SessionAware {
+ ServerSessionAware {
@Override
default ServerSession getSession() {
@@ -47,12 +47,6 @@ public interface InvertedShell
}
/**
- * @return The {@link ChannelSession} instance through which the shell was created - may be {@code null} if shell
- * not started yet
- */
- ChannelSession getChannelSession();
-
- /**
* Returns the output stream used to feed the shell. This method is called after the shell has been started.
*
* @return The {@link OutputStream} used to feed the shell
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShellWrapper.java b/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShellWrapper.java
index 201f8c0..29b6573 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShellWrapper.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShellWrapper.java
@@ -34,10 +34,10 @@ import org.apache.sshd.common.util.threads.ThreadUtils;
import org.apache.sshd.core.CoreModuleProperties;
import org.apache.sshd.server.Environment;
import org.apache.sshd.server.ExitCallback;
-import org.apache.sshd.server.SessionAware;
import org.apache.sshd.server.channel.ChannelSession;
import org.apache.sshd.server.command.Command;
import org.apache.sshd.server.session.ServerSession;
+import org.apache.sshd.server.session.ServerSessionAware;
/**
* A shell implementation that wraps an instance of {@link InvertedShell} as a {@link Command}. This is useful when
@@ -46,7 +46,7 @@ import org.apache.sshd.server.session.ServerSession;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class InvertedShellWrapper extends AbstractLoggingBean implements Command, SessionAware {
+public class InvertedShellWrapper extends AbstractLoggingBean implements Command, ServerSessionAware {
private final InvertedShell shell;
private final Executor executor;
@@ -203,7 +203,7 @@ public class InvertedShellWrapper extends AbstractLoggingBean implements Command
} catch (Throwable e) {
boolean debugEnabled = log.isDebugEnabled();
try {
- shell.destroy(shell.getChannelSession());
+ shell.destroy(shell.getServerChannelSession());
} catch (Throwable err) {
warn("pumpStreams({}) failed ({}) to destroy shell: {}",
this, e.getClass().getSimpleName(), e.getMessage(), e);
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/shell/ProcessShell.java b/sshd-core/src/main/java/org/apache/sshd/server/shell/ProcessShell.java
index 3965c84..0bb881c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/shell/ProcessShell.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/shell/ProcessShell.java
@@ -48,7 +48,7 @@ public class ProcessShell extends AbstractLoggingBean implements InvertedShell {
private final List<String> command;
private String cmdValue;
private ServerSession session;
- private ChannelSession channel;
+ private ChannelSession channelSession;
private Process process;
private TtyFilterOutputStream in;
private TtyFilterInputStream out;
@@ -81,13 +81,13 @@ public class ProcessShell extends AbstractLoggingBean implements InvertedShell {
}
@Override
- public ChannelSession getChannelSession() {
- return channel;
+ public ChannelSession getServerChannelSession() {
+ return channelSession;
}
@Override
public void start(ChannelSession channel, Environment env) throws IOException {
- this.channel = channel;
+ this.channelSession = channel;
Map<String, String> varsMap = resolveShellEnvironment(env.getEnv());
for (int i = 0; i < command.size(); i++) {
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/shell/InvertedShellWrapperTest.java b/sshd-core/src/test/java/org/apache/sshd/server/shell/InvertedShellWrapperTest.java
index 6eb52e6..1a600d7 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/shell/InvertedShellWrapperTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/shell/InvertedShellWrapperTest.java
@@ -93,8 +93,8 @@ public class InvertedShellWrapperTest extends BaseTestSupport {
}
@Override
- public ChannelSession getChannelSession() {
- return bogusShell.getChannelSession();
+ public ChannelSession getServerChannelSession() {
+ return bogusShell.getServerChannelSession();
}
@Override
@@ -210,12 +210,12 @@ public class InvertedShellWrapperTest extends BaseTestSupport {
return session;
}
- ChannelSession channel = getChannelSession();
+ ChannelSession channel = getServerChannelSession();
return (channel == null) ? null : channel.getServerSession();
}
@Override
- public ChannelSession getChannelSession() {
+ public ChannelSession getServerChannelSession() {
return channel;
}
diff --git a/sshd-core/src/test/java/org/apache/sshd/util/test/AsyncEchoShellFactory.java b/sshd-core/src/test/java/org/apache/sshd/util/test/AsyncEchoShellFactory.java
index 7218ffd..2373539 100644
--- a/sshd-core/src/test/java/org/apache/sshd/util/test/AsyncEchoShellFactory.java
+++ b/sshd-core/src/test/java/org/apache/sshd/util/test/AsyncEchoShellFactory.java
@@ -29,11 +29,11 @@ import org.apache.sshd.common.io.IoInputStream;
import org.apache.sshd.common.io.IoOutputStream;
import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
-import org.apache.sshd.server.ChannelSessionAware;
import org.apache.sshd.server.Environment;
import org.apache.sshd.server.ExitCallback;
import org.apache.sshd.server.channel.ChannelDataReceiver;
import org.apache.sshd.server.channel.ChannelSession;
+import org.apache.sshd.server.channel.ChannelSessionAware;
import org.apache.sshd.server.command.AsyncCommand;
import org.apache.sshd.server.command.Command;
import org.apache.sshd.server.shell.ShellFactory;
diff --git a/sshd-core/src/test/java/org/apache/sshd/util/test/BogusInvertedShell.java b/sshd-core/src/test/java/org/apache/sshd/util/test/BogusInvertedShell.java
index ce5ccdc..2b64789 100644
--- a/sshd-core/src/test/java/org/apache/sshd/util/test/BogusInvertedShell.java
+++ b/sshd-core/src/test/java/org/apache/sshd/util/test/BogusInvertedShell.java
@@ -59,7 +59,7 @@ public class BogusInvertedShell implements InvertedShell {
}
@Override
- public ChannelSession getChannelSession() {
+ public ChannelSession getServerChannelSession() {
return channel;
}
diff --git a/sshd-git/src/main/java/org/apache/sshd/git/AbstractGitCommandFactory.java b/sshd-git/src/main/java/org/apache/sshd/git/AbstractGitCommandFactory.java
index ee66947..2c02708 100644
--- a/sshd-git/src/main/java/org/apache/sshd/git/AbstractGitCommandFactory.java
+++ b/sshd-git/src/main/java/org/apache/sshd/git/AbstractGitCommandFactory.java
@@ -25,6 +25,7 @@ import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.threads.CloseableExecutorService;
import org.apache.sshd.common.util.threads.ExecutorServiceProvider;
+import org.apache.sshd.server.channel.ChannelSession;
import org.apache.sshd.server.command.AbstractDelegatingCommandFactory;
import org.apache.sshd.server.command.Command;
import org.apache.sshd.server.command.CommandFactory;
@@ -90,7 +91,7 @@ public abstract class AbstractGitCommandFactory
}
@Override
- public boolean isSupportedCommand(String command) {
+ public boolean isSupportedCommand(ChannelSession channel, String command) {
if (GenericUtils.isEmpty(command)) {
return false;
}
@@ -100,12 +101,12 @@ public abstract class AbstractGitCommandFactory
}
@Override
- protected Command executeSupportedCommand(String command) {
+ protected Command executeSupportedCommand(ChannelSession channel, String command) {
return createGitCommand(command);
}
@Override
- protected Command createUnsupportedCommand(String command) {
+ protected Command createUnsupportedCommand(ChannelSession channel, String command) {
return new UnknownCommand(command);
}
diff --git a/sshd-scp/src/main/java/org/apache/sshd/scp/server/ScpCommand.java b/sshd-scp/src/main/java/org/apache/sshd/scp/server/ScpCommand.java
index 329940c..a3a588a 100644
--- a/sshd-scp/src/main/java/org/apache/sshd/scp/server/ScpCommand.java
+++ b/sshd-scp/src/main/java/org/apache/sshd/scp/server/ScpCommand.java
@@ -20,6 +20,7 @@ package org.apache.sshd.scp.server;
import java.io.IOException;
import java.util.Collections;
+import java.util.Objects;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.threads.CloseableExecutorService;
@@ -33,6 +34,7 @@ import org.apache.sshd.scp.common.helpers.ScpAckInfo;
import org.apache.sshd.server.Environment;
import org.apache.sshd.server.ExitCallback;
import org.apache.sshd.server.channel.ChannelSession;
+import org.apache.sshd.server.channel.ServerChannelSessionHolder;
import org.apache.sshd.server.command.AbstractFileSystemCommand;
import org.apache.sshd.server.session.ServerSession;
@@ -42,7 +44,7 @@ import org.apache.sshd.server.session.ServerSession;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class ScpCommand extends AbstractFileSystemCommand {
+public class ScpCommand extends AbstractFileSystemCommand implements ServerChannelSessionHolder {
protected final int sendBufferSize;
protected final int receiveBufferSize;
protected final ScpFileOpener opener;
@@ -55,7 +57,10 @@ public class ScpCommand extends AbstractFileSystemCommand {
protected IOException error;
protected ScpTransferEventListener listener;
+ private final ChannelSession channelSession;
+
/**
+ * @param channelSession The {@link ChannelSession} through which the command was received
* @param command The command to be executed
* @param executorService An {@link CloseableExecutorService} to be used when
* {@code start(ChannelSession, Environment)}-ing execution. If {@code null} an ad-hoc
@@ -68,12 +73,14 @@ public class ScpCommand extends AbstractFileSystemCommand {
* @see ScpHelper#MIN_SEND_BUFFER_SIZE
* @see ScpHelper#MIN_RECEIVE_BUFFER_SIZE
*/
- public ScpCommand(String command,
+ public ScpCommand(ChannelSession channelSession, String command,
CloseableExecutorService executorService,
int sendSize, int receiveSize,
ScpFileOpener fileOpener, ScpTransferEventListener eventListener) {
super(command, executorService);
+ this.channelSession = Objects.requireNonNull(channelSession, "No channel session provided");
+
if (sendSize < ScpHelper.MIN_SEND_BUFFER_SIZE) {
throw new IllegalArgumentException(
"<ScpCommmand>(" + command + ") send buffer size "
@@ -148,6 +155,11 @@ public class ScpCommand extends AbstractFileSystemCommand {
}
@Override
+ public ChannelSession getServerChannelSession() {
+ return channelSession;
+ }
+
+ @Override
public void start(ChannelSession channel, Environment env) throws IOException {
if (error != null) {
throw error;
diff --git a/sshd-scp/src/main/java/org/apache/sshd/scp/server/ScpCommandFactory.java b/sshd-scp/src/main/java/org/apache/sshd/scp/server/ScpCommandFactory.java
index 6e9b348..569bf8a 100644
--- a/sshd-scp/src/main/java/org/apache/sshd/scp/server/ScpCommandFactory.java
+++ b/sshd-scp/src/main/java/org/apache/sshd/scp/server/ScpCommandFactory.java
@@ -211,7 +211,7 @@ public class ScpCommandFactory
}
@Override
- public boolean isSupportedCommand(String command) {
+ public boolean isSupportedCommand(ChannelSession channel, String command) {
if (GenericUtils.isEmpty(command)) {
return false;
}
@@ -220,9 +220,9 @@ public class ScpCommandFactory
}
@Override
- protected Command executeSupportedCommand(String command) {
+ protected Command executeSupportedCommand(ChannelSession channel, String command) {
return new ScpCommand(
- command,
+ channel, command,
resolveExecutorService(command),
getSendBufferSize(), getReceiveBufferSize(),
getScpFileOpener(), listenerProxy);
diff --git a/sshd-scp/src/main/java/org/apache/sshd/scp/server/ScpShell.java b/sshd-scp/src/main/java/org/apache/sshd/scp/server/ScpShell.java
index dedde72..ca413be 100644
--- a/sshd-scp/src/main/java/org/apache/sshd/scp/server/ScpShell.java
+++ b/sshd-scp/src/main/java/org/apache/sshd/scp/server/ScpShell.java
@@ -20,6 +20,7 @@ package org.apache.sshd.scp.server;
import java.io.IOError;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InterruptedIOException;
import java.io.OutputStream;
import java.io.Reader;
@@ -64,6 +65,7 @@ import org.apache.sshd.scp.common.helpers.DefaultScpFileOpener;
import org.apache.sshd.scp.common.helpers.ScpAckInfo;
import org.apache.sshd.server.Environment;
import org.apache.sshd.server.channel.ChannelSession;
+import org.apache.sshd.server.channel.ServerChannelSessionHolder;
import org.apache.sshd.server.command.AbstractFileSystemCommand;
/**
@@ -71,7 +73,7 @@ import org.apache.sshd.server.command.AbstractFileSystemCommand;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class ScpShell extends AbstractFileSystemCommand {
+public class ScpShell extends AbstractFileSystemCommand implements ServerChannelSessionHolder {
public static final String STATUS = "status";
@@ -86,7 +88,6 @@ public class ScpShell extends AbstractFileSystemCommand {
*/
public static final String ENV_LANG = "LANG";
- protected final ChannelSession channel;
protected final Map<String, Object> variables = new HashMap<>();
protected final Charset nameEncodingCharset;
@@ -97,13 +98,15 @@ public class ScpShell extends AbstractFileSystemCommand {
protected Path currentDir;
protected Path homeDir;
- public ScpShell(ChannelSession channel, CloseableExecutorService executorService,
+ private final ChannelSession channelSession;
+
+ public ScpShell(ChannelSession channelSession, CloseableExecutorService executorService,
int sendSize, int receiveSize,
ScpFileOpener fileOpener, ScpTransferEventListener eventListener) {
super(null, executorService);
- this.channel = channel;
+ this.channelSession = Objects.requireNonNull(channelSession, "No channel session provided");
- nameEncodingCharset = ScpModuleProperties.NAME_ENCODING_CHARSET.getRequired(channel);
+ nameEncodingCharset = ScpModuleProperties.NAME_ENCODING_CHARSET.getRequired(channelSession);
if (sendSize < ScpHelper.MIN_SEND_BUFFER_SIZE) {
throw new IllegalArgumentException(
@@ -126,6 +129,11 @@ public class ScpShell extends AbstractFileSystemCommand {
}
@Override
+ public ChannelSession getServerChannelSession() {
+ return channelSession;
+ }
+
+ @Override
public void setFileSystemFactory(FileSystemFactory factory, SessionContext session) throws IOException {
homeDir = factory.getUserHomeDir(session);
super.setFileSystemFactory(factory, session);
@@ -136,7 +144,7 @@ public class ScpShell extends AbstractFileSystemCommand {
String s = x.toString();
if (log.isDebugEnabled()) {
log.debug("println({})[{}]: {}",
- channel, cmd, s.replace('\n', ' ').replace('\t', ' '));
+ getServerChannelSession(), cmd, s.replace('\n', ' ').replace('\t', ' '));
}
out.write(s.getBytes(cs));
// always write LF even if running on Windows
@@ -151,7 +159,7 @@ public class ScpShell extends AbstractFileSystemCommand {
}
protected void signalError(String cmd, String errorMsg, Charset cs) {
- log.warn("{}[{}]: {}", channel, cmd, errorMsg);
+ log.warn("{}[{}]: {}", getServerChannelSession(), cmd, errorMsg);
println(cmd, errorMsg, getErrorStream(), cs);
variables.put(STATUS, 1);
}
@@ -162,6 +170,7 @@ public class ScpShell extends AbstractFileSystemCommand {
variables.put(STATUS, 0);
boolean debugEnabled = log.isDebugEnabled();
+ ChannelSession channel = getServerChannelSession();
try {
// TODO find some better alternative
if (homeDir == null) {
@@ -177,7 +186,8 @@ public class ScpShell extends AbstractFileSystemCommand {
prepareEnvironment(getEnvironment());
// Use a special stream reader so that the stream can be used with the scp command
- try (Reader r = new InputStreamReader(getInputStream(), StandardCharsets.UTF_8)) {
+ try (InputStream inputStream = getInputStream();
+ Reader r = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
for (int executedCommands = 0;; executedCommands++) {
command = readLine(r);
if (GenericUtils.isEmpty(command)) {
@@ -239,7 +249,7 @@ public class ScpShell extends AbstractFileSystemCommand {
protected boolean handleCommandLine(String command) throws Exception {
if (log.isDebugEnabled()) {
- log.debug("handleCommandLine({}) {}", channel, command);
+ log.debug("handleCommandLine({}) {}", getServerChannelSession(), command);
}
List<String[]> cmds = parse(command);
@@ -298,7 +308,7 @@ public class ScpShell extends AbstractFileSystemCommand {
}
protected void handleUnsupportedCommand(String command, String[] argv) throws Exception {
- log.warn("handleUnsupportedCommand({}) unsupported: {}", channel, command);
+ log.warn("handleUnsupportedCommand({}) unsupported: {}", getServerChannelSession(), command);
variables.put(STATUS, 127);
getErrorStream().write(("command not found: " + argv[0] + "\n").getBytes(StandardCharsets.US_ASCII));
}
@@ -373,7 +383,7 @@ public class ScpShell extends AbstractFileSystemCommand {
}
if (log.isDebugEnabled()) {
- log.debug("printenv({}) {}={}", channel, varName, varValue);
+ log.debug("printenv({}) {}={}", getServerChannelSession(), varName, varValue);
}
println(argv[0], varValue, stdout, StandardCharsets.US_ASCII);
@@ -395,7 +405,7 @@ public class ScpShell extends AbstractFileSystemCommand {
String varName = argv[1];
String varValue = envValues.remove(varName);
if (log.isDebugEnabled()) {
- log.debug("unset({}) {}={}", channel, varName, varValue);
+ log.debug("unset({}) {}={}", getServerChannelSession(), varName, varValue);
}
variables.put(STATUS, (varValue == null) ? 1 : 0);
}
@@ -464,6 +474,7 @@ public class ScpShell extends AbstractFileSystemCommand {
String path, boolean optR, boolean optT, boolean optF, boolean optD, boolean optP)
throws Exception {
try {
+ ChannelSession channel = getServerChannelSession();
ScpHelper helper = new ScpHelper(
channel.getSession(), getInputStream(), getOutputStream(),
fileSystem, opener, listener);
@@ -637,6 +648,7 @@ public class ScpShell extends AbstractFileSystemCommand {
}
}
+ // TODO see what optDirAsPlain means
doLs(argv[0], path, optListAll, optLong, optFullTime);
}
diff --git a/sshd-scp/src/test/java/org/apache/sshd/scp/client/ScpTest.java b/sshd-scp/src/test/java/org/apache/sshd/scp/client/ScpTest.java
index 214fe0a..6f6c095 100644
--- a/sshd-scp/src/test/java/org/apache/sshd/scp/client/ScpTest.java
+++ b/sshd-scp/src/test/java/org/apache/sshd/scp/client/ScpTest.java
@@ -722,12 +722,12 @@ public class ScpTest extends AbstractScpTestSupport {
@Test // see SSHD-628
public void testScpExitStatusPropagation() throws Exception {
- final int testExitValue = 7365;
+ int testExitValue = 7365;
class InternalScpCommand extends ScpCommand {
- InternalScpCommand(String command, CloseableExecutorService executorService,
+ InternalScpCommand(ChannelSession channel, String command, CloseableExecutorService executorService,
int sendSize, int receiveSize, ScpFileOpener opener, ScpTransferEventListener eventListener) {
- super(command, executorService, sendSize, receiveSize, opener, eventListener);
+ super(channel, command, executorService, sendSize, receiveSize, opener, eventListener);
}
@Override
@@ -750,7 +750,7 @@ public class ScpTest extends AbstractScpTestSupport {
ValidateUtils.checkTrue(
command.startsWith(ScpHelper.SCP_COMMAND_PREFIX), "Bad SCP command: %s", command);
return new InternalScpCommand(
- command,
+ channel, command,
resolveExecutorService(command),
getSendBufferSize(), getReceiveBufferSize(),
DefaultScpFileOpener.INSTANCE,
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 4a5288b..0d539fb 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
@@ -86,6 +86,7 @@ import org.apache.sshd.common.util.buffer.BufferUtils;
import org.apache.sshd.common.util.io.FileInfoExtractor;
import org.apache.sshd.common.util.io.IoUtils;
import org.apache.sshd.common.util.logging.AbstractLoggingBean;
+import org.apache.sshd.server.channel.ChannelSession;
import org.apache.sshd.server.session.ServerSession;
import org.apache.sshd.sftp.SftpModuleProperties;
import org.apache.sshd.sftp.common.SftpConstants;
@@ -141,13 +142,15 @@ public abstract class AbstractSftpSubsystemHelper
SftpConstants.SSH_ACL_CAP_AUDIT,
SftpConstants.SSH_ACL_CAP_ALARM)));
+ private final ChannelSession channelSession;
private final UnsupportedAttributePolicy unsupportedAttributePolicy;
private final Collection<SftpEventListener> sftpEventListeners = new CopyOnWriteArraySet<>();
private final SftpEventListener sftpEventListenerProxy;
private final SftpFileSystemAccessor fileSystemAccessor;
private final SftpErrorStatusDataHandler errorStatusDataHandler;
- protected AbstractSftpSubsystemHelper(SftpSubsystemConfigurator configurator) {
+ protected AbstractSftpSubsystemHelper(ChannelSession channelSession, SftpSubsystemConfigurator configurator) {
+ this.channelSession = Objects.requireNonNull(channelSession, "No channel session provided");
unsupportedAttributePolicy = Objects.requireNonNull(configurator.getUnsupportedAttributePolicy(),
"No unsupported attribute policy provided");
fileSystemAccessor = Objects.requireNonNull(configurator.getFileSystemAccessor(), "No file system accessor");
@@ -157,6 +160,11 @@ public abstract class AbstractSftpSubsystemHelper
}
@Override
+ public ChannelSession getServerChannelSession() {
+ return channelSession;
+ }
+
+ @Override
public UnsupportedAttributePolicy getUnsupportedAttributePolicy() {
return unsupportedAttributePolicy;
}
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 03c8936..923ff94 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
@@ -64,12 +64,11 @@ import org.apache.sshd.common.util.io.IoUtils;
import org.apache.sshd.common.util.threads.CloseableExecutorService;
import org.apache.sshd.common.util.threads.ExecutorServiceCarrier;
import org.apache.sshd.common.util.threads.ThreadUtils;
-import org.apache.sshd.server.ChannelSessionAware;
import org.apache.sshd.server.Environment;
import org.apache.sshd.server.ExitCallback;
-import org.apache.sshd.server.SessionAware;
import org.apache.sshd.server.channel.ChannelDataReceiver;
import org.apache.sshd.server.channel.ChannelSession;
+import org.apache.sshd.server.channel.ChannelSessionAware;
import org.apache.sshd.server.command.AsyncCommand;
import org.apache.sshd.server.command.AsyncCommandErrorStreamAware;
import org.apache.sshd.server.command.Command;
@@ -87,8 +86,8 @@ import org.apache.sshd.sftp.common.SftpHelper;
*/
public class SftpSubsystem
extends AbstractSftpSubsystemHelper
- implements Command, Runnable, SessionAware, FileSystemAware, ExecutorServiceCarrier,
- AsyncCommand, ChannelSessionAware, ChannelDataReceiver {
+ implements Command, Runnable, FileSystemAware, ExecutorServiceCarrier,
+ AsyncCommand, ChannelDataReceiver {
protected static final Buffer CLOSE = new ByteArrayBuffer(null, 0, 0);
@@ -98,7 +97,6 @@ public class SftpSubsystem
protected final Map<String, Handle> handles = new ConcurrentHashMap<>();
protected final Buffer buffer = new ByteArrayBuffer(1024);
protected final BlockingQueue<Buffer> requests = new LinkedBlockingQueue<>();
- protected final ChannelDataReceiver errorDataChannelReceiver;
protected ExitCallback callback;
protected IoOutputStream out;
@@ -113,39 +111,14 @@ public class SftpSubsystem
protected int version;
protected ServerSession serverSession;
- protected ChannelSession channelSession;
protected CloseableExecutorService executorService;
/**
+ * @param channel The {@link ChannelSession} through which the command was received
* @param configurator The {@link SftpSubsystemConfigurator} to use
*/
- public SftpSubsystem(SftpSubsystemConfigurator configurator) {
- super(configurator);
-
- ChannelDataReceiver receiver = configurator.getErrorChannelDataReceiver();
- if (receiver == null) {
- errorDataChannelReceiver = new ChannelDataReceiver() {
- @Override
- @SuppressWarnings("synthetic-access")
- public void close() throws IOException {
- if (log.isDebugEnabled()) {
- log.debug("stderrData({}) closing", getSession());
- }
-
- }
-
- @Override
- @SuppressWarnings("synthetic-access")
- public int data(ChannelSession channel, byte[] buf, int start, int len) throws IOException {
- if (log.isDebugEnabled()) {
- log.debug("stderrData({}) received {} data bytes", channel, len);
- }
- return len;
- }
- };
- } else {
- errorDataChannelReceiver = receiver;
- }
+ public SftpSubsystem(ChannelSession channel, SftpSubsystemConfigurator configurator) {
+ super(channel, configurator);
CloseableExecutorService executorService = configurator.getExecutorService();
if (executorService == null) {
@@ -153,6 +126,40 @@ public class SftpSubsystem
} else {
this.executorService = executorService;
}
+
+ initializeSessionRelatedMember(channel);
+
+ ChannelDataReceiver errorDataChannelReceiver
+ = resolveErrorDataChannelReceiver(channel, configurator.getErrorChannelDataReceiver());
+ channel.setDataReceiver(this);
+ channel.setExtendedDataWriter(errorDataChannelReceiver);
+
+ SftpErrorStatusDataHandler errHandler = getErrorStatusDataHandler();
+ if (errHandler instanceof ChannelSessionAware) {
+ ((ChannelSessionAware) errHandler).setChannelSession(channel);
+ }
+ }
+
+ protected ChannelDataReceiver resolveErrorDataChannelReceiver(ChannelSession channelSession, ChannelDataReceiver receiver) {
+ return (receiver != null) ? receiver : new ChannelDataReceiver() {
+ @Override
+ @SuppressWarnings("synthetic-access")
+ public void close() throws IOException {
+ if (log.isDebugEnabled()) {
+ log.debug("stderrData({}) closing", getSession());
+ }
+
+ }
+
+ @Override
+ @SuppressWarnings("synthetic-access")
+ public int data(ChannelSession channel, byte[] buf, int start, int len) throws IOException {
+ if (log.isDebugEnabled()) {
+ log.debug("stderrData({}) received {} data bytes", channel, len);
+ }
+ return len;
+ }
+ };
}
@Override
@@ -170,16 +177,15 @@ public class SftpSubsystem
return executorService;
}
- @Override
- public void setSession(ServerSession session) {
- this.serverSession = Objects.requireNonNull(session, "No session");
+ protected void initializeSessionRelatedMember(ChannelSession channel) {
+ serverSession = Objects.requireNonNull(channel.getServerSession(), "No session associated with the channel");
- FactoryManager manager = session.getFactoryManager();
+ FactoryManager manager = serverSession.getFactoryManager();
Factory<? extends Random> factory = manager.getRandomFactory();
this.randomizer = factory.create();
- this.fileHandleSize = SftpModuleProperties.FILE_HANDLE_SIZE.getRequired(session);
- this.maxFileHandleRounds = SftpModuleProperties.MAX_FILE_HANDLE_RAND_ROUNDS.getRequired(session);
+ this.fileHandleSize = SftpModuleProperties.FILE_HANDLE_SIZE.getRequired(channel);
+ this.maxFileHandleRounds = SftpModuleProperties.MAX_FILE_HANDLE_RAND_ROUNDS.getRequired(channel);
if (workBuf.length < this.fileHandleSize) {
workBuf = new byte[this.fileHandleSize];
@@ -192,18 +198,6 @@ public class SftpSubsystem
}
@Override
- public void setChannelSession(ChannelSession session) {
- this.channelSession = session;
- session.setDataReceiver(this);
- session.setExtendedDataWriter(errorDataChannelReceiver);
-
- SftpErrorStatusDataHandler errHandler = getErrorStatusDataHandler();
- if (errHandler instanceof ChannelSessionAware) {
- ((ChannelSessionAware) errHandler).setChannelSession(session);
- }
- }
-
- @Override
public void setFileSystem(FileSystem fileSystem) {
// reference check on purpose
if (fileSystem != this.fileSystem) {
@@ -242,8 +236,9 @@ public class SftpSubsystem
@Override
public void setIoOutputStream(IoOutputStream out) {
- int channelId = channelSession.getId();
- this.out = new BufferedIoOutputStream("sftp-out@" + channelId, channelId, out, channelSession);
+ ChannelSession channel = getServerChannelSession();
+ int channelId = channel.getId();
+ this.out = new BufferedIoOutputStream("sftp-out@" + channelId, channelId, out, channel);
}
@Override
@@ -290,22 +285,25 @@ public class SftpSubsystem
@Override
public void run() {
int exitCode = 0;
+ long buffersCount = 0L;
try {
+ ChannelSession channel = getServerChannelSession();
+ Window localWindow = channel.getLocalWindow();
while (true) {
Buffer buffer = requests.take();
if (buffer == CLOSE) {
break;
}
int len = buffer.available();
+ buffersCount++;
process(buffer);
- Window localWindow = channelSession.getLocalWindow();
localWindow.consumeAndCheck(len);
}
} catch (Throwable t) {
if (!closed.get()) { // Ignore
Session session = getServerSession();
- error("run({}) {} caught in SFTP subsystem: {}",
- session, t.getClass().getSimpleName(), t.getMessage(), t);
+ error("run({}) {} caught in SFTP subsystem after {} buffers: {}",
+ session, t.getClass().getSimpleName(), buffersCount, t.getMessage(), t);
exitCode = -1;
}
} finally {
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystemEnvironment.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystemEnvironment.java
index 037f1e0..5a15821 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystemEnvironment.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystemEnvironment.java
@@ -27,6 +27,7 @@ import java.util.stream.IntStream;
import org.apache.sshd.common.session.SessionHolder;
import org.apache.sshd.common.util.GenericUtils;
+import org.apache.sshd.server.channel.ServerChannelSessionHolder;
import org.apache.sshd.server.session.ServerSession;
import org.apache.sshd.server.session.ServerSessionHolder;
import org.apache.sshd.sftp.common.SftpConstants;
@@ -35,7 +36,7 @@ import org.apache.sshd.sftp.common.SftpConstants;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public interface SftpSubsystemEnvironment
- extends SessionHolder<ServerSession>, ServerSessionHolder,
+ extends SessionHolder<ServerSession>, ServerSessionHolder, ServerChannelSessionHolder,
SftpFileSystemAccessorProvider, SftpUnsupportedAttributePolicyProvider {
int LOWER_SFTP_IMPL = SftpConstants.SFTP_V3; // Working implementation from v3
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystemFactory.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystemFactory.java
index 444d7ca..a5ab56e 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystemFactory.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystemFactory.java
@@ -168,7 +168,7 @@ public class SftpSubsystemFactory
@Override
public Command createSubsystem(ChannelSession channel) throws IOException {
- SftpSubsystem subsystem = new SftpSubsystem(this);
+ SftpSubsystem subsystem = new SftpSubsystem(channel, this);
GenericUtils.forEach(getRegisteredListeners(), subsystem::addSftpEventListener);
return subsystem;
}
diff --git a/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/SftpVersionsTest.java b/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/SftpVersionsTest.java
index de54873..e71510e 100644
--- a/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/SftpVersionsTest.java
+++ b/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/SftpVersionsTest.java
@@ -227,7 +227,7 @@ public class SftpVersionsTest extends AbstractSftpClientTestSupport {
SftpSubsystemFactory factory = new SftpSubsystemFactory() {
@Override
public Command createSubsystem(ChannelSession channel) throws IOException {
- SftpSubsystem subsystem = new SftpSubsystem(this) {
+ SftpSubsystem subsystem = new SftpSubsystem(channel, this) {
@Override
protected NavigableMap<String, Object> resolveFileAttributes(Path file, int flags, LinkOption... options)
throws IOException {
@@ -346,7 +346,7 @@ public class SftpVersionsTest extends AbstractSftpClientTestSupport {
SftpSubsystemFactory factory = new SftpSubsystemFactory() {
@Override
public Command createSubsystem(ChannelSession channel) throws IOException {
- SftpSubsystem subsystem = new SftpSubsystem(this) {
+ SftpSubsystem subsystem = new SftpSubsystem(channel, this) {
@Override
protected NavigableMap<String, Object> resolveFileAttributes(Path file, int flags, LinkOption... options)
throws IOException {
diff --git a/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/extensions/helpers/SpaceAvailableExtensionImplTest.java b/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/extensions/helpers/SpaceAvailableExtensionImplTest.java
index bca6be7..7eaa8f4 100644
--- a/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/extensions/helpers/SpaceAvailableExtensionImplTest.java
+++ b/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/extensions/helpers/SpaceAvailableExtensionImplTest.java
@@ -71,7 +71,7 @@ public class SpaceAvailableExtensionImplTest extends AbstractSftpClientTestSuppo
sshd.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory() {
@Override
public Command createSubsystem(ChannelSession channel) throws IOException {
- return new SftpSubsystem(this) {
+ return new SftpSubsystem(channel, this) {
@Override
protected SpaceAvailableExtensionInfo doSpaceAvailable(int id, String path) throws IOException {
if (!queryPath.equals(path)) {
diff --git a/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/extensions/openssh/helpers/OpenSSHExtensionsTest.java b/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/extensions/openssh/helpers/OpenSSHExtensionsTest.java
index 4525534..4a81808 100644
--- a/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/extensions/openssh/helpers/OpenSSHExtensionsTest.java
+++ b/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/extensions/openssh/helpers/OpenSSHExtensionsTest.java
@@ -120,7 +120,7 @@ public class OpenSSHExtensionsTest extends AbstractSftpClientTestSupport {
sshd.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory() {
@Override
public Command createSubsystem(ChannelSession channel) throws IOException {
- return new SftpSubsystem(this) {
+ return new SftpSubsystem(channel, this) {
@Override
protected List<OpenSSHExtension> resolveOpenSSHExtensions(ServerSession session) {
List<OpenSSHExtension> original = super.resolveOpenSSHExtensions(session);