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 2019/08/07 11:20:02 UTC
[mina-sshd] 03/03: [SSHD-937] Provide session instance when
invoking a ChannelFactory
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 065d713bdc7728ac94df289497ff6b679b2392f1
Author: Lyor Goldstein <lg...@apache.org>
AuthorDate: Wed Aug 7 07:03:01 2019 +0300
[SSHD-937] Provide session instance when invoking a ChannelFactory
---
CHANGES.md | 5 +++-
.../org/apache/sshd/agent/SshAgentFactory.java | 7 ++---
.../agent/local/ChannelAgentForwardingFactory.java | 5 +++-
.../apache/sshd/agent/local/LocalAgentFactory.java | 9 +++---
.../apache/sshd/agent/local/ProxyAgentFactory.java | 5 ++--
.../agent/unix/ChannelAgentForwardingFactory.java | 8 +++--
.../apache/sshd/agent/unix/UnixAgentFactory.java | 13 ++++----
.../java/org/apache/sshd/client/ClientBuilder.java | 4 +--
.../java/org/apache/sshd/client/SshClient.java | 13 ++++----
.../java/org/apache/sshd/common/BaseBuilder.java | 6 ++--
.../org/apache/sshd/common/FactoryManager.java | 6 ++--
.../apache/sshd/common/channel/ChannelFactory.java | 35 ++++++++++++++++++----
.../common/helpers/AbstractFactoryManager.java | 9 +++---
.../session/helpers/AbstractConnectionService.java | 10 ++++---
.../java/org/apache/sshd/server/ServerBuilder.java | 6 ++--
.../apache/sshd/server/channel/ChannelSession.java | 29 ++++++++++++------
.../sshd/server/channel/ChannelSessionFactory.java | 5 +++-
.../sshd/server/forward/TcpipServerChannel.java | 5 ++--
.../java/org/apache/sshd/client/ClientTest.java | 2 +-
.../org/apache/sshd/common/channel/WindowTest.java | 2 +-
.../sshd/client/subsystem/sftp/ClientTest.java | 2 +-
21 files changed, 116 insertions(+), 70 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index 57d62a7..62f36db 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -25,6 +25,9 @@ has been made
* `UserAuthFactory` is a proper interface and it has been refactored to contain a
`createUserAuth` method that accepts the session instance through which the request is made.
+* `ChannelFactory` is a proper interface and it has been refactored to contain a
+`createChannel` method that accepts the session instance through which the request is made.
+
## Minor code helpers
* `SessionListener` supports `sessionPeerIdentificationReceived` that is invoked once successful
@@ -39,4 +42,4 @@ for the server's identification before sending its own.
* [SSHD-934](https://issues.apache.org/jira/browse/SSHD-934) - Fixed ECDSA public key encoding into OpenSSH format.
-* [SSHD-937](https://issues.apache.org/jira/browse/SSHD-937) - Provide session instance when creating a subsystem or user authentication.
\ No newline at end of file
+* [SSHD-937](https://issues.apache.org/jira/browse/SSHD-937) - Provide session instance when creating a subsystem, user authentication, channel.
\ No newline at end of file
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentFactory.java b/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentFactory.java
index 9b44d27..23e63cb 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentFactory.java
@@ -22,8 +22,7 @@ import java.io.IOException;
import java.util.List;
import org.apache.sshd.common.FactoryManager;
-import org.apache.sshd.common.NamedFactory;
-import org.apache.sshd.common.channel.Channel;
+import org.apache.sshd.common.channel.ChannelFactory;
import org.apache.sshd.common.session.ConnectionService;
/**
@@ -48,9 +47,9 @@ public interface SshAgentFactory {
* either local or through another proxy.
*
* @param manager The {@link FactoryManager} through which the request is made
- * @return The (named) channel factories used to create channels on the client side
+ * @return The {@link ChannelFactory}-ies used to create channels on the client side
*/
- List<NamedFactory<Channel>> getChannelForwardingFactories(FactoryManager manager);
+ List<ChannelFactory> getChannelForwardingFactories(FactoryManager manager);
/**
* Create an SshAgent that can be used on the client side by the authentication
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/local/ChannelAgentForwardingFactory.java b/sshd-core/src/main/java/org/apache/sshd/agent/local/ChannelAgentForwardingFactory.java
index 40f9135..cacca91 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/local/ChannelAgentForwardingFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/local/ChannelAgentForwardingFactory.java
@@ -19,8 +19,11 @@
package org.apache.sshd.agent.local;
+import java.io.IOException;
+
import org.apache.sshd.common.channel.Channel;
import org.apache.sshd.common.channel.ChannelFactory;
+import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.util.ValidateUtils;
/**
@@ -43,7 +46,7 @@ public class ChannelAgentForwardingFactory implements ChannelFactory {
}
@Override
- public Channel create() {
+ public Channel createChannel(Session session) throws IOException {
return new ChannelAgentForwarding(null);
}
}
\ No newline at end of file
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/local/LocalAgentFactory.java b/sshd-core/src/main/java/org/apache/sshd/agent/local/LocalAgentFactory.java
index 99d8c11..afbb4bf 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/local/LocalAgentFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/local/LocalAgentFactory.java
@@ -28,14 +28,13 @@ import org.apache.sshd.agent.SshAgentFactory;
import org.apache.sshd.agent.SshAgentServer;
import org.apache.sshd.agent.common.AgentDelegate;
import org.apache.sshd.common.FactoryManager;
-import org.apache.sshd.common.NamedFactory;
-import org.apache.sshd.common.channel.Channel;
+import org.apache.sshd.common.channel.ChannelFactory;
import org.apache.sshd.common.session.ConnectionService;
public class LocalAgentFactory implements SshAgentFactory {
- public static final List<NamedFactory<Channel>> DEFAULT_FORWARDING_CHANNELS =
+ public static final List<ChannelFactory> DEFAULT_FORWARDING_CHANNELS =
Collections.unmodifiableList(
- Arrays.<NamedFactory<Channel>>asList(
+ Arrays.asList(
ChannelAgentForwardingFactory.OPENSSH,
ChannelAgentForwardingFactory.IETF));
@@ -54,7 +53,7 @@ public class LocalAgentFactory implements SshAgentFactory {
}
@Override
- public List<NamedFactory<Channel>> getChannelForwardingFactories(FactoryManager manager) {
+ public List<ChannelFactory> getChannelForwardingFactories(FactoryManager manager) {
return DEFAULT_FORWARDING_CHANNELS;
}
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/local/ProxyAgentFactory.java b/sshd-core/src/main/java/org/apache/sshd/agent/local/ProxyAgentFactory.java
index ab19539..54d884d 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/local/ProxyAgentFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/local/ProxyAgentFactory.java
@@ -30,10 +30,9 @@ import org.apache.sshd.agent.SshAgentServer;
import org.apache.sshd.agent.unix.AprLibrary;
import org.apache.sshd.agent.unix.UnixAgentFactory;
import org.apache.sshd.common.FactoryManager;
-import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.PropertyResolver;
import org.apache.sshd.common.PropertyResolverUtils;
-import org.apache.sshd.common.channel.Channel;
+import org.apache.sshd.common.channel.ChannelFactory;
import org.apache.sshd.common.session.ConnectionService;
import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.util.GenericUtils;
@@ -52,7 +51,7 @@ public class ProxyAgentFactory implements SshAgentFactory {
}
@Override
- public List<NamedFactory<Channel>> getChannelForwardingFactories(FactoryManager manager) {
+ public List<ChannelFactory> getChannelForwardingFactories(FactoryManager manager) {
return isPreferredUnixAgent(manager)
? UnixAgentFactory.DEFAULT_FORWARDING_CHANNELS
: LocalAgentFactory.DEFAULT_FORWARDING_CHANNELS;
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/unix/ChannelAgentForwardingFactory.java b/sshd-core/src/main/java/org/apache/sshd/agent/unix/ChannelAgentForwardingFactory.java
index 6811770..8c6dc7b 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/unix/ChannelAgentForwardingFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/unix/ChannelAgentForwardingFactory.java
@@ -18,9 +18,12 @@
*/
package org.apache.sshd.agent.unix;
+import java.io.IOException;
+
import org.apache.sshd.common.Factory;
import org.apache.sshd.common.channel.Channel;
import org.apache.sshd.common.channel.ChannelFactory;
+import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.threads.CloseableExecutorService;
@@ -51,8 +54,9 @@ public class ChannelAgentForwardingFactory implements ChannelFactory {
}
@Override
- public Channel create() {
- CloseableExecutorService executorService = executorServiceFactory != null ? executorServiceFactory.create() : null;
+ public Channel createChannel(Session session) throws IOException {
+ CloseableExecutorService executorService =
+ executorServiceFactory != null ? executorServiceFactory.create() : null;
ChannelAgentForwarding channel = new ChannelAgentForwarding(executorService);
return channel;
}
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java b/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java
index b30bbb3..afa136d 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java
@@ -30,9 +30,8 @@ import org.apache.sshd.agent.SshAgentFactory;
import org.apache.sshd.agent.SshAgentServer;
import org.apache.sshd.common.Factory;
import org.apache.sshd.common.FactoryManager;
-import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.SshException;
-import org.apache.sshd.common.channel.Channel;
+import org.apache.sshd.common.channel.ChannelFactory;
import org.apache.sshd.common.session.ConnectionService;
import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.util.GenericUtils;
@@ -44,9 +43,9 @@ import org.apache.sshd.server.session.ServerSession;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public class UnixAgentFactory implements SshAgentFactory {
- public static final List<NamedFactory<Channel>> DEFAULT_FORWARDING_CHANNELS =
+ public static final List<ChannelFactory> DEFAULT_FORWARDING_CHANNELS =
Collections.unmodifiableList(
- Arrays.<NamedFactory<Channel>>asList(
+ Arrays.asList(
ChannelAgentForwardingFactory.OPENSSH,
ChannelAgentForwardingFactory.IETF));
@@ -65,11 +64,11 @@ public class UnixAgentFactory implements SshAgentFactory {
}
@Override
- public List<NamedFactory<Channel>> getChannelForwardingFactories(FactoryManager manager) {
+ public List<ChannelFactory> getChannelForwardingFactories(FactoryManager manager) {
if (executorServiceFactory != null) {
return DEFAULT_FORWARDING_CHANNELS.stream()
- .map(cf -> new ChannelAgentForwardingFactory(cf.getName(), executorServiceFactory))
- .collect(Collectors.toList());
+ .map(cf -> new ChannelAgentForwardingFactory(cf.getName(), executorServiceFactory))
+ .collect(Collectors.toList());
} else {
return DEFAULT_FORWARDING_CHANNELS;
}
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/ClientBuilder.java b/sshd-core/src/main/java/org/apache/sshd/client/ClientBuilder.java
index e720768..7c60a59 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/ClientBuilder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/ClientBuilder.java
@@ -34,7 +34,7 @@ import org.apache.sshd.client.keyverifier.AcceptAllServerKeyVerifier;
import org.apache.sshd.client.keyverifier.ServerKeyVerifier;
import org.apache.sshd.common.BaseBuilder;
import org.apache.sshd.common.NamedFactory;
-import org.apache.sshd.common.channel.Channel;
+import org.apache.sshd.common.channel.ChannelFactory;
import org.apache.sshd.common.channel.RequestHandler;
import org.apache.sshd.common.compression.BuiltinCompressions;
import org.apache.sshd.common.compression.CompressionFactory;
@@ -92,7 +92,7 @@ public class ClientBuilder extends BaseBuilder<SshClient, ClientBuilder> {
public static final List<CompressionFactory> DEFAULT_COMPRESSION_FACTORIES =
Collections.unmodifiableList(Collections.singletonList(BuiltinCompressions.none));
- public static final List<NamedFactory<Channel>> DEFAULT_CHANNEL_FACTORIES =
+ public static final List<ChannelFactory> DEFAULT_CHANNEL_FACTORIES =
Collections.unmodifiableList(Collections.singletonList(ForwardedTcpipFactory.INSTANCE));
public static final List<RequestHandler<ConnectionService>> DEFAULT_GLOBAL_REQUEST_HANDLERS =
Collections.unmodifiableList(Collections.singletonList(OpenSshHostKeysHandler.INSTANCE));
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java b/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
index 300ec3f..f9dbaf4 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
@@ -66,10 +66,9 @@ import org.apache.sshd.client.simple.SimpleClient;
import org.apache.sshd.common.AttributeRepository;
import org.apache.sshd.common.Closeable;
import org.apache.sshd.common.Factory;
-import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.NamedResource;
import org.apache.sshd.common.ServiceFactory;
-import org.apache.sshd.common.channel.Channel;
+import org.apache.sshd.common.channel.ChannelFactory;
import org.apache.sshd.common.config.keys.FilePasswordProvider;
import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.config.keys.PublicKeyEntry;
@@ -366,15 +365,17 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
// Register the additional agent forwarding channel if needed
SshAgentFactory agentFactory = getAgentFactory();
if (agentFactory != null) {
- List<NamedFactory<Channel>> forwarders =
+ List<ChannelFactory> forwarders =
ValidateUtils.checkNotNullAndNotEmpty(
- agentFactory.getChannelForwardingFactories(this), "No agent channel forwarding factories for %s", agentFactory);
- List<NamedFactory<Channel>> factories = getChannelFactories();
+ agentFactory.getChannelForwardingFactories(this),
+ "No agent channel forwarding factories for %s",
+ agentFactory);
+ List<ChannelFactory> factories = getChannelFactories();
if (GenericUtils.isEmpty(factories)) {
factories = forwarders;
} else {
// create a copy in case un-modifiable original
- List<NamedFactory<Channel>> factories2 =
+ List<ChannelFactory> factories2 =
new ArrayList<>(factories.size() + forwarders.size());
factories2.addAll(factories);
factories2.addAll(forwarders);
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/BaseBuilder.java b/sshd-core/src/main/java/org/apache/sshd/common/BaseBuilder.java
index c578e5a..5dc33ce 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/BaseBuilder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/BaseBuilder.java
@@ -23,7 +23,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import org.apache.sshd.common.channel.Channel;
+import org.apache.sshd.common.channel.ChannelFactory;
import org.apache.sshd.common.channel.RequestHandler;
import org.apache.sshd.common.channel.throttle.ChannelStreamPacketWriterResolver;
import org.apache.sshd.common.cipher.BuiltinCiphers;
@@ -134,7 +134,7 @@ public class BaseBuilder<T extends AbstractFactoryManager, S extends BaseBuilder
protected List<NamedFactory<Mac>> macFactories;
protected List<NamedFactory<Signature>> signatureFactories;
protected Factory<Random> randomFactory;
- protected List<NamedFactory<Channel>> channelFactories;
+ protected List<ChannelFactory> channelFactories;
protected FileSystemFactory fileSystemFactory;
protected ForwardingFilterFactory forwarderFactory;
protected List<RequestHandler<ConnectionService>> globalRequestHandlers;
@@ -208,7 +208,7 @@ public class BaseBuilder<T extends AbstractFactoryManager, S extends BaseBuilder
return me();
}
- public S channelFactories(List<NamedFactory<Channel>> channelFactories) {
+ public S channelFactories(List<ChannelFactory> channelFactories) {
this.channelFactories = channelFactories;
return me();
}
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/FactoryManager.java b/sshd-core/src/main/java/org/apache/sshd/common/FactoryManager.java
index aec9f5d..c0c9999 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/FactoryManager.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/FactoryManager.java
@@ -24,7 +24,7 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.apache.sshd.agent.SshAgentFactory;
-import org.apache.sshd.common.channel.Channel;
+import org.apache.sshd.common.channel.ChannelFactory;
import org.apache.sshd.common.channel.ChannelListenerManager;
import org.apache.sshd.common.channel.RequestHandler;
import org.apache.sshd.common.channel.throttle.ChannelStreamPacketWriterResolverManager;
@@ -403,9 +403,9 @@ public interface FactoryManager
/**
* Retrieve the list of named factories for <code>Channel</code> objects.
*
- * @return A list of named <code>Channel</code> factories, never {@code null}
+ * @return A list of {@link ChannelFactory}-ies, never {@code null}
*/
- List<NamedFactory<Channel>> getChannelFactories();
+ List<ChannelFactory> getChannelFactories();
/**
* Retrieve the agent factory for creating <code>SshAgent</code> objects.
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelFactory.java
index a19d56c..e13b0d5 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelFactory.java
@@ -19,13 +19,38 @@
package org.apache.sshd.common.channel;
-import org.apache.sshd.common.NamedFactory;
+import java.io.IOException;
+import java.util.Collection;
+
+import org.apache.sshd.common.NamedResource;
+import org.apache.sshd.common.session.Session;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-// CHECKSTYLE:OFF
-public interface ChannelFactory extends NamedFactory<Channel> {
- // nothing extra
+public interface ChannelFactory extends NamedResource {
+ /**
+ * @param session The {@link Session} through which the request is made
+ * @return The relevant {@link Channel}
+ * @throws IOException If failed to create the requested instance
+ */
+ Channel createChannel(Session session) throws IOException;
+
+ /**
+ * @param session The {@link Session} through which the request is made
+ * @param factories The available factories
+ * @param name The required factory name to use
+ * @return The created {@link Channel} - {@code null} if no match found
+ * @throws IOException If failed to create the requested instance
+ */
+ static Channel createChannel(
+ Session session, Collection<? extends ChannelFactory> factories, String name)
+ throws IOException {
+ ChannelFactory f = NamedResource.findByName(name, String.CASE_INSENSITIVE_ORDER, factories);
+ if (f != null) {
+ return f.createChannel(session);
+ } else {
+ return null;
+ }
+ }
}
-//CHECKSTYLE:ON
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/helpers/AbstractFactoryManager.java b/sshd-core/src/main/java/org/apache/sshd/common/helpers/AbstractFactoryManager.java
index 6549572..86c1963 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/helpers/AbstractFactoryManager.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/helpers/AbstractFactoryManager.java
@@ -35,12 +35,11 @@ import org.apache.sshd.agent.SshAgentFactory;
import org.apache.sshd.common.AttributeRepository;
import org.apache.sshd.common.Factory;
import org.apache.sshd.common.FactoryManager;
-import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.PropertyResolver;
import org.apache.sshd.common.PropertyResolverUtils;
import org.apache.sshd.common.ServiceFactory;
import org.apache.sshd.common.SyspropsMapWrapper;
-import org.apache.sshd.common.channel.Channel;
+import org.apache.sshd.common.channel.ChannelFactory;
import org.apache.sshd.common.channel.ChannelListener;
import org.apache.sshd.common.channel.RequestHandler;
import org.apache.sshd.common.channel.throttle.ChannelStreamPacketWriterResolver;
@@ -73,7 +72,7 @@ public abstract class AbstractFactoryManager extends AbstractKexFactoryManager i
protected IoServiceFactoryFactory ioServiceFactoryFactory;
protected IoServiceFactory ioServiceFactory;
protected Factory<Random> randomFactory;
- protected List<NamedFactory<Channel>> channelFactories;
+ protected List<ChannelFactory> channelFactories;
protected SshAgentFactory agentFactory;
protected ScheduledExecutorService executor;
protected boolean shutdownExecutor;
@@ -208,11 +207,11 @@ public abstract class AbstractFactoryManager extends AbstractKexFactoryManager i
}
@Override
- public List<NamedFactory<Channel>> getChannelFactories() {
+ public List<ChannelFactory> getChannelFactories() {
return channelFactories;
}
- public void setChannelFactories(List<NamedFactory<Channel>> channelFactories) {
+ public void setChannelFactories(List<ChannelFactory> channelFactories) {
this.channelFactories = channelFactories;
}
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractConnectionService.java b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractConnectionService.java
index 77cf06c..284d8c5 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractConnectionService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractConnectionService.java
@@ -41,10 +41,10 @@ import org.apache.sshd.client.channel.AbstractClientChannel;
import org.apache.sshd.client.future.OpenFuture;
import org.apache.sshd.common.Closeable;
import org.apache.sshd.common.FactoryManager;
-import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.channel.AbstractChannel;
import org.apache.sshd.common.channel.Channel;
+import org.apache.sshd.common.channel.ChannelFactory;
import org.apache.sshd.common.channel.RequestHandler;
import org.apache.sshd.common.channel.Window;
import org.apache.sshd.common.channel.exception.SshChannelNotFoundException;
@@ -774,7 +774,7 @@ public abstract class AbstractConnectionService
AbstractSession session = getSession();
FactoryManager manager = Objects.requireNonNull(session.getFactoryManager(), "No factory manager");
- Channel channel = NamedFactory.create(manager.getChannelFactories(), type);
+ Channel channel = ChannelFactory.createChannel(session, manager.getChannelFactories(), type);
if (channel == null) {
// TODO add language tag configurable control
sendChannelOpenFailure(buffer, sender,
@@ -792,7 +792,8 @@ public abstract class AbstractConnectionService
log.debug("operationComplete({}) send SSH_MSG_CHANNEL_OPEN_CONFIRMATION recipient={}, sender={}, window-size={}, packet-size={}",
channel, sender, channelId, window.getSize(), window.getPacketSize());
}
- Buffer buf = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN_CONFIRMATION, Integer.SIZE);
+ Buffer buf =
+ session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN_CONFIRMATION, Integer.SIZE);
buf.putInt(sender); // remote (server side) identifier
buf.putInt(channelId); // local (client side) identifier
buf.putInt(window.getSize());
@@ -813,7 +814,8 @@ public abstract class AbstractConnectionService
AbstractConnectionService.this, future);
}
- Buffer buf = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN_FAILURE, message.length() + Long.SIZE);
+ Buffer buf =
+ session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN_FAILURE, message.length() + Long.SIZE);
sendChannelOpenFailure(buf, sender, reasonCode, message, "");
}
} catch (IOException e) {
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/ServerBuilder.java b/sshd-core/src/main/java/org/apache/sshd/server/ServerBuilder.java
index b6c3144..0510141 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/ServerBuilder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/ServerBuilder.java
@@ -26,7 +26,7 @@ import java.util.function.Function;
import org.apache.sshd.common.BaseBuilder;
import org.apache.sshd.common.NamedFactory;
-import org.apache.sshd.common.channel.Channel;
+import org.apache.sshd.common.channel.ChannelFactory;
import org.apache.sshd.common.channel.RequestHandler;
import org.apache.sshd.common.compression.BuiltinCompressions;
import org.apache.sshd.common.compression.CompressionFactory;
@@ -60,9 +60,9 @@ public class ServerBuilder extends BaseBuilder<SshServer, ServerBuilder> {
? DHGEXServer.newFactory(factory)
: DHGServer.newFactory(factory);
- public static final List<NamedFactory<Channel>> DEFAULT_CHANNEL_FACTORIES =
+ public static final List<ChannelFactory> DEFAULT_CHANNEL_FACTORIES =
Collections.unmodifiableList(
- Arrays.<NamedFactory<Channel>>asList(
+ Arrays.asList(
ChannelSessionFactory.INSTANCE,
DirectTcpipFactory.INSTANCE
));
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 00c2ca3..1987d5d 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
@@ -83,7 +83,7 @@ import org.apache.sshd.server.x11.X11ForwardSupport;
*/
public class ChannelSession extends AbstractServerChannel {
public static final List<ChannelRequestHandler> DEFAULT_HANDLERS =
- Collections.<ChannelRequestHandler>singletonList(PuttyRequestHandler.INSTANCE);
+ Collections.singletonList(PuttyRequestHandler.INSTANCE);
/**
* Maximum amount of extended (a.k.a. STDERR) data allowed to be accumulated
@@ -743,7 +743,8 @@ public class ChannelSession extends AbstractServerChannel {
if (extendedDataBuffer != null) {
if (extendedDataWriter == null) {
- throw new UnsupportedOperationException("No extended data writer available though " + extendedDataBuffer.available() + " bytes accumulated");
+ throw new UnsupportedOperationException(
+ "No extended data writer available though " + extendedDataBuffer.available() + " bytes accumulated");
}
Buffer buffer = extendedDataBuffer;
@@ -755,7 +756,8 @@ public class ChannelSession extends AbstractServerChannel {
try {
closeShell(exitValue);
if (log.isDebugEnabled()) {
- log.debug("onExit({}) code={} message='{}' shell closed", ChannelSession.this, exitValue, exitMessage);
+ log.debug("onExit({}) code={} message='{}' shell closed",
+ ChannelSession.this, exitValue, exitMessage);
}
} catch (IOException e) {
log.warn("onExit({}) code={} message='{}' {} closing shell: {}",
@@ -771,10 +773,14 @@ public class ChannelSession extends AbstractServerChannel {
return v != null ? v.intValue() : 0;
}
- protected RequestHandler.Result handleAgentForwarding(String requestType, Buffer buffer, boolean wantReply) throws IOException {
+ protected RequestHandler.Result handleAgentForwarding(
+ String requestType, Buffer buffer, boolean wantReply)
+ throws IOException {
ServerSession session = getServerSession();
PropertyResolverUtils.updateProperty(session, FactoryManager.AGENT_FORWARDING_TYPE, requestType);
- FactoryManager manager = Objects.requireNonNull(session.getFactoryManager(), "No session factory manager");
+
+ FactoryManager manager =
+ Objects.requireNonNull(session.getFactoryManager(), "No session factory manager");
AgentForwardingFilter filter = manager.getAgentForwardingFilter();
SshAgentFactory factory = manager.getAgentFactory();
boolean debugEnabled = log.isDebugEnabled();
@@ -808,14 +814,17 @@ public class ChannelSession extends AbstractServerChannel {
return RequestHandler.Result.ReplySuccess;
}
- protected RequestHandler.Result handleX11Forwarding(String requestType, Buffer buffer, boolean wantReply) throws IOException {
+ protected RequestHandler.Result handleX11Forwarding(
+ String requestType, Buffer buffer, boolean wantReply)
+ throws IOException {
ServerSession session = getServerSession();
boolean singleConnection = buffer.getBoolean();
String authProtocol = buffer.getString();
String authCookie = buffer.getString();
int screenId = buffer.getInt();
- FactoryManager manager = Objects.requireNonNull(session.getFactoryManager(), "No factory manager");
+ FactoryManager manager =
+ Objects.requireNonNull(session.getFactoryManager(), "No factory manager");
X11ForwardingFilter filter = manager.getX11ForwardingFilter();
boolean debugEnabled = log.isDebugEnabled();
try {
@@ -844,7 +853,8 @@ public class ChannelSession extends AbstractServerChannel {
return RequestHandler.Result.ReplyFailure;
}
- String display = x11Forward.createDisplay(singleConnection, authProtocol, authCookie, screenId);
+ String display =
+ x11Forward.createDisplay(singleConnection, authProtocol, authCookie, screenId);
if (debugEnabled) {
log.debug("handleX11Forwarding({}) single={}, protocol={}, cookie={}, screen={} - display='{}'",
this, singleConnection, authProtocol, authCookie, screenId, display);
@@ -858,7 +868,8 @@ public class ChannelSession extends AbstractServerChannel {
}
protected void addEnvVariable(String name, String value) {
- getEnvironment().set(name, value);
+ StandardEnvironment e = getEnvironment();
+ e.set(name, value);
}
public StandardEnvironment getEnvironment() {
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSessionFactory.java b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSessionFactory.java
index f1df61f..e8d9a81 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSessionFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSessionFactory.java
@@ -18,8 +18,11 @@
*/
package org.apache.sshd.server.channel;
+import java.io.IOException;
+
import org.apache.sshd.common.channel.Channel;
import org.apache.sshd.common.channel.ChannelFactory;
+import org.apache.sshd.common.session.Session;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
@@ -37,7 +40,7 @@ public class ChannelSessionFactory implements ChannelFactory {
}
@Override
- public Channel create() {
+ public Channel createChannel(Session session) throws IOException {
return new ChannelSession();
}
}
\ No newline at end of file
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java b/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
index ea0e365..b621353 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
@@ -87,9 +87,8 @@ public class TcpipServerChannel extends AbstractServerChannel implements Forward
}
@Override
- public Channel create() {
- TcpipServerChannel channel = new TcpipServerChannel(getType(), ThreadUtils.noClose(getExecutorService()));
- return channel;
+ public Channel createChannel(Session session) throws IOException {
+ return new TcpipServerChannel(getType(), ThreadUtils.noClose(getExecutorService()));
}
}
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
index 015e0c7..434ac66 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
@@ -196,7 +196,7 @@ public class ClientTest extends BaseTestSupport {
sshd.setChannelFactories(Arrays.asList(
new ChannelSessionFactory() {
@Override
- public Channel create() {
+ public Channel createChannel(Session session) throws IOException {
return new ChannelSession() {
@SuppressWarnings("synthetic-access")
@Override
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java
index c294b11..5c8a641 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java
@@ -109,7 +109,7 @@ public class WindowTest extends BaseTestSupport {
sshd.setChannelFactories(Arrays.asList(
new ChannelSessionFactory() {
@Override
- public Channel create() {
+ public Channel createChannel(Session session) throws IOException {
return new ChannelSession() {
@SuppressWarnings("synthetic-access")
@Override
diff --git a/sshd-sftp/src/test/java/org/apache/sshd/client/subsystem/sftp/ClientTest.java b/sshd-sftp/src/test/java/org/apache/sshd/client/subsystem/sftp/ClientTest.java
index 2affc1b..c72b876 100644
--- a/sshd-sftp/src/test/java/org/apache/sshd/client/subsystem/sftp/ClientTest.java
+++ b/sshd-sftp/src/test/java/org/apache/sshd/client/subsystem/sftp/ClientTest.java
@@ -146,7 +146,7 @@ public class ClientTest extends BaseTestSupport {
sshd.setChannelFactories(Arrays.asList(
new ChannelSessionFactory() {
@Override
- public Channel create() {
+ public Channel createChannel(Session session) throws IOException {
return new ChannelSession() {
@SuppressWarnings("synthetic-access")
@Override