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 b8fadd4ff18bcf20b25387591b66b6b39210d341 Author: Lyor Goldstein <lgoldst...@apache.org> AuthorDate: Thu Oct 17 13:18:58 2019 +0300 [SSHD-842] Updated client ConnectFuture and other ClientSessionHolder(s) hierarchy --- .../password/InteractivePasswordIdentityProvider.java | 12 ++++++++++-- .../main/java/org/apache/sshd/client/auth/UserAuth.java | 2 -- .../sshd/client/channel/AbstractClientChannel.java | 7 ------- .../org/apache/sshd/client/channel/ClientChannel.java | 6 ++++++ .../org/apache/sshd/client/future/ConnectFuture.java | 17 ++++++++++++----- .../sshd/client/kex/AbstractDHClientKeyExchange.java | 7 +++++-- .../sshd/client/session/ClientConnectionService.java | 8 ++++---- .../session/forward/DynamicPortForwardingTracker.java | 3 ++- .../client/session/forward/PortForwardingTracker.java | 12 ++++++++++-- .../sshd/client/subsystem/AbstractSubsystemClient.java | 6 ------ .../apache/sshd/client/subsystem/SubsystemClient.java | 5 ++++- .../java/org/apache/sshd/common/channel/Channel.java | 9 +++------ .../sshd/git/transport/GitSshdSessionFactory.java | 14 ++++++++++++-- .../org/apache/sshd/client/scp/AbstractScpClient.java | 5 ----- .../main/java/org/apache/sshd/client/scp/ScpClient.java | 5 +++++ .../sshd/client/subsystem/sftp/fs/SftpFileSystem.java | 10 +++++++++- 16 files changed, 82 insertions(+), 46 deletions(-) diff --git a/sshd-contrib/src/main/java/org/apache/sshd/client/auth/password/InteractivePasswordIdentityProvider.java b/sshd-contrib/src/main/java/org/apache/sshd/client/auth/password/InteractivePasswordIdentityProvider.java index 4c47058..4106d9d 100644 --- a/sshd-contrib/src/main/java/org/apache/sshd/client/auth/password/InteractivePasswordIdentityProvider.java +++ b/sshd-contrib/src/main/java/org/apache/sshd/client/auth/password/InteractivePasswordIdentityProvider.java @@ -26,6 +26,7 @@ import java.util.concurrent.atomic.AtomicReference; import org.apache.sshd.client.auth.keyboard.UserInteraction; import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.client.session.ClientSessionHolder; +import org.apache.sshd.common.session.SessionHolder; import org.apache.sshd.common.util.GenericUtils; /** @@ -60,7 +61,8 @@ import org.apache.sshd.common.util.GenericUtils; * * @author <a href="mailto:d...@mina.apache.org">Apache MINA SSHD Project</a> */ -public class InteractivePasswordIdentityProvider implements Iterator<String>, ClientSessionHolder { +public class InteractivePasswordIdentityProvider + implements Iterator<String>, SessionHolder<ClientSession>, ClientSessionHolder { /** Special marker to indicate that we exhausted all attempts */ protected static final String EOF = "EOF"; @@ -69,7 +71,8 @@ public class InteractivePasswordIdentityProvider implements Iterator<String>, Cl private String prompt; private AtomicReference<String> nextPassword = new AtomicReference<>(); - public InteractivePasswordIdentityProvider(ClientSession clientSession, UserInteraction userInteraction, String prompt) { + public InteractivePasswordIdentityProvider( + ClientSession clientSession, UserInteraction userInteraction, String prompt) { this.clientSession = Objects.requireNonNull(clientSession, "No client session provided"); this.userInteraction = Objects.requireNonNull(userInteraction, "No user interaction instance configured"); this.prompt = prompt; @@ -80,6 +83,11 @@ public class InteractivePasswordIdentityProvider implements Iterator<String>, Cl return clientSession; } + @Override + public ClientSession getSession() { + return getClientSession(); + } + public UserInteraction getUserInteraction() { return userInteraction; } diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuth.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuth.java index 633e761..03792f4 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuth.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuth.java @@ -28,7 +28,6 @@ import org.apache.sshd.common.util.buffer.Buffer; * @author <a href="mailto:d...@mina.apache.org">Apache MINA SSHD Project</a> */ public interface UserAuth extends ClientSessionHolder, UserAuthInstance<ClientSession> { - /** * @param session The {@link ClientSession} * @param service The requesting service name @@ -50,5 +49,4 @@ public interface UserAuth extends ClientSessionHolder, UserAuthInstance<ClientSe * Called to release any allocated resources */ void destroy(); - } diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java index 611e789..93832c6 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java @@ -34,7 +34,6 @@ import org.apache.sshd.client.channel.exit.ExitSignalChannelRequestHandler; import org.apache.sshd.client.channel.exit.ExitStatusChannelRequestHandler; import org.apache.sshd.client.future.DefaultOpenFuture; import org.apache.sshd.client.future.OpenFuture; -import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.common.Closeable; import org.apache.sshd.common.FactoryManager; import org.apache.sshd.common.SshConstants; @@ -62,7 +61,6 @@ import org.apache.sshd.common.util.io.IoUtils; * @author <a href="mailto:d...@mina.apache.org">Apache MINA SSHD Project</a> */ public abstract class AbstractClientChannel extends AbstractChannel implements ClientChannel { - protected final AtomicBoolean opened = new AtomicBoolean(); protected Streaming streaming; @@ -103,11 +101,6 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C }); } - @Override - public ClientSession getClientSession() { - return (ClientSession) super.getSession(); - } - protected void addChannelSignalRequestHandlers(EventNotifier<String> notifier) { addRequestHandler(new ExitStatusChannelRequestHandler(exitStatusHolder, notifier)); addRequestHandler(new ExitSignalChannelRequestHandler(exitSignalHolder, notifier)); diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ClientChannel.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ClientChannel.java index c5a87c4..73f046b 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ClientChannel.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ClientChannel.java @@ -27,6 +27,7 @@ import java.util.Collection; import java.util.Set; import org.apache.sshd.client.future.OpenFuture; +import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.client.session.ClientSessionHolder; import org.apache.sshd.common.channel.Channel; import org.apache.sshd.common.io.IoInputStream; @@ -46,6 +47,11 @@ public interface ClientChannel extends Channel, ClientSessionHolder { Sync } + @Override + default ClientSession getClientSession() { + return (ClientSession) getSession(); + } + /** * @return The type of channel reported when it was created */ diff --git a/sshd-core/src/main/java/org/apache/sshd/client/future/ConnectFuture.java b/sshd-core/src/main/java/org/apache/sshd/client/future/ConnectFuture.java index 47d4fa9..5db35d4 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/future/ConnectFuture.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/future/ConnectFuture.java @@ -19,19 +19,26 @@ package org.apache.sshd.client.future; import org.apache.sshd.client.session.ClientSession; +import org.apache.sshd.client.session.ClientSessionHolder; import org.apache.sshd.common.future.SshFuture; import org.apache.sshd.common.future.VerifiableFuture; +import org.apache.sshd.common.session.SessionHolder; /** * An {@link SshFuture} for asynchronous connections requests. * * @author <a href="mailto:d...@mina.apache.org">Apache MINA SSHD Project</a> */ -public interface ConnectFuture extends SshFuture<ConnectFuture>, VerifiableFuture<ConnectFuture> { - /** - * @return The referenced {@link ClientSession} - */ - ClientSession getSession(); +public interface ConnectFuture + extends SshFuture<ConnectFuture>, + VerifiableFuture<ConnectFuture>, + SessionHolder<ClientSession>, + ClientSessionHolder { + + @Override + default ClientSession getClientSession() { + return getSession(); + } /** * @return <code>true</code> if the connect operation is finished successfully. diff --git a/sshd-core/src/main/java/org/apache/sshd/client/kex/AbstractDHClientKeyExchange.java b/sshd-core/src/main/java/org/apache/sshd/client/kex/AbstractDHClientKeyExchange.java index 3158a2a..3bbf1e9 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/kex/AbstractDHClientKeyExchange.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/kex/AbstractDHClientKeyExchange.java @@ -30,11 +30,14 @@ import org.apache.sshd.common.util.ValidateUtils; /** * @author <a href="mailto:d...@mina.apache.org">Apache MINA SSHD Project</a> */ -public abstract class AbstractDHClientKeyExchange extends AbstractDHKeyExchange implements ClientSessionHolder { +public abstract class AbstractDHClientKeyExchange + extends AbstractDHKeyExchange + implements ClientSessionHolder { protected PublicKey serverKey; protected AbstractDHClientKeyExchange(Session session) { - super(ValidateUtils.checkInstanceOf(session, ClientSession.class, "Using a client side KeyExchange on a server: %s", session)); + super(ValidateUtils.checkInstanceOf(session, ClientSession.class, + "Using a client side KeyExchange on a server: %s", session)); } @Override diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java index dd472bd..8911cc5 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java @@ -52,11 +52,11 @@ public class ClientConnectionService public ClientConnectionService(AbstractClientSession s) throws SshException { super(s); - heartbeatRequest = this.getStringProperty( + heartbeatRequest = getStringProperty( ClientFactoryManager.HEARTBEAT_REQUEST, ClientFactoryManager.DEFAULT_KEEP_ALIVE_HEARTBEAT_STRING); - heartbeatInterval = this.getLongProperty( + heartbeatInterval = getLongProperty( ClientFactoryManager.HEARTBEAT_INTERVAL, ClientFactoryManager.DEFAULT_HEARTBEAT_INTERVAL); - heartbeatReplyMaxWait = this.getLongProperty( + heartbeatReplyMaxWait = getLongProperty( ClientFactoryManager.HEARTBEAT_REPLY_WAIT, ClientFactoryManager.DEFAULT_HEARTBEAT_REPLY_WAIT); } @@ -65,7 +65,7 @@ public class ClientConnectionService return getSession(); } - @Override + @Override // co-variant return public AbstractClientSession getSession() { return (AbstractClientSession) super.getSession(); } diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/forward/DynamicPortForwardingTracker.java b/sshd-core/src/main/java/org/apache/sshd/client/session/forward/DynamicPortForwardingTracker.java index cb1a977..8755aed 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/session/forward/DynamicPortForwardingTracker.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/session/forward/DynamicPortForwardingTracker.java @@ -29,7 +29,8 @@ import org.apache.sshd.common.util.net.SshdSocketAddress; * @author <a href="mailto:d...@mina.apache.org">Apache MINA SSHD Project</a> */ public class DynamicPortForwardingTracker extends PortForwardingTracker { - public DynamicPortForwardingTracker(ClientSession session, SshdSocketAddress localAddress, SshdSocketAddress boundAddress) { + public DynamicPortForwardingTracker( + ClientSession session, SshdSocketAddress localAddress, SshdSocketAddress boundAddress) { super(session, localAddress, boundAddress); } diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/forward/PortForwardingTracker.java b/sshd-core/src/main/java/org/apache/sshd/client/session/forward/PortForwardingTracker.java index ab6d12a..b1e3785 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/session/forward/PortForwardingTracker.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/session/forward/PortForwardingTracker.java @@ -25,18 +25,21 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.client.session.ClientSessionHolder; +import org.apache.sshd.common.session.SessionHolder; import org.apache.sshd.common.util.net.SshdSocketAddress; /** * @author <a href="mailto:d...@mina.apache.org">Apache MINA SSHD Project</a> */ -public abstract class PortForwardingTracker implements Channel, ClientSessionHolder { +public abstract class PortForwardingTracker + implements Channel, SessionHolder<ClientSession>, ClientSessionHolder { protected final AtomicBoolean open = new AtomicBoolean(true); private final ClientSession session; private final SshdSocketAddress localAddress; private final SshdSocketAddress boundAddress; - protected PortForwardingTracker(ClientSession session, SshdSocketAddress localAddress, SshdSocketAddress boundAddress) { + protected PortForwardingTracker( + ClientSession session, SshdSocketAddress localAddress, SshdSocketAddress boundAddress) { this.session = Objects.requireNonNull(session, "No client session provided"); this.localAddress = Objects.requireNonNull(localAddress, "No local address specified"); this.boundAddress = Objects.requireNonNull(boundAddress, "No bound address specified"); @@ -61,6 +64,11 @@ public abstract class PortForwardingTracker implements Channel, ClientSessionHol } @Override + public ClientSession getSession() { + return getClientSession(); + } + + @Override public String toString() { return getClass().getSimpleName() + "[session=" + getClientSession() diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/AbstractSubsystemClient.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/AbstractSubsystemClient.java index 32e8d26..414f50c 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/AbstractSubsystemClient.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/AbstractSubsystemClient.java @@ -19,7 +19,6 @@ package org.apache.sshd.client.subsystem; -import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.common.util.logging.AbstractLoggingBean; /** @@ -31,11 +30,6 @@ public abstract class AbstractSubsystemClient extends AbstractLoggingBean implem } @Override - public final ClientSession getSession() { - return getClientSession(); - } - - @Override public String toString() { return getClass().getSimpleName() + "[name=" + getName() diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/SubsystemClient.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/SubsystemClient.java index 2cf7399..dd6d02d 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/SubsystemClient.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/SubsystemClient.java @@ -36,5 +36,8 @@ public interface SubsystemClient NamedResource, Channel, ClientChannelHolder { - // nothing extra + @Override + default ClientSession getSession() { + return getClientSession(); + } } diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java index 4f89ce8..968587d 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java @@ -32,6 +32,7 @@ import org.apache.sshd.common.channel.throttle.ChannelStreamPacketWriterResolver import org.apache.sshd.common.io.PacketWriter; import org.apache.sshd.common.session.ConnectionService; import org.apache.sshd.common.session.Session; +import org.apache.sshd.common.session.SessionHolder; import org.apache.sshd.common.util.GenericUtils; import org.apache.sshd.common.util.buffer.Buffer; @@ -42,7 +43,8 @@ import org.apache.sshd.common.util.buffer.Buffer; * @author <a href="mailto:d...@mina.apache.org">Apache MINA SSHD Project</a> */ public interface Channel - extends ChannelListenerManager, + extends SessionHolder<Session>, + ChannelListenerManager, PropertyResolver, AttributeStore, PacketWriter, @@ -63,11 +65,6 @@ public interface Channel */ int getRecipient(); - /** - * @return The channel's underlying {@link Session} - */ - Session getSession(); - Window getLocalWindow(); Window getRemoteWindow(); diff --git a/sshd-git/src/main/java/org/apache/sshd/git/transport/GitSshdSessionFactory.java b/sshd-git/src/main/java/org/apache/sshd/git/transport/GitSshdSessionFactory.java index 75281c5..f619f91 100644 --- a/sshd-git/src/main/java/org/apache/sshd/git/transport/GitSshdSessionFactory.java +++ b/sshd-git/src/main/java/org/apache/sshd/git/transport/GitSshdSessionFactory.java @@ -24,6 +24,7 @@ import java.util.Objects; import org.apache.sshd.client.SshClient; import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.client.session.ClientSessionHolder; +import org.apache.sshd.common.session.SessionHolder; import org.apache.sshd.common.util.GenericUtils; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.transport.CredentialsProvider; @@ -37,7 +38,9 @@ import org.eclipse.jgit.util.FS; * * @author <a href="mailto:d...@mina.apache.org">Apache MINA SSHD Project</a> */ -public class GitSshdSessionFactory extends SshSessionFactory implements ClientSessionHolder { +public class GitSshdSessionFactory + extends SshSessionFactory + implements SessionHolder<ClientSession>, ClientSessionHolder { public static final GitSshdSessionFactory INSTANCE = new GitSshdSessionFactory(); private final SshClient client; @@ -75,7 +78,9 @@ public class GitSshdSessionFactory extends SshSessionFactory implements ClientSe } @Override - public RemoteSession getSession(URIish uri, CredentialsProvider credentialsProvider, FS fs, int tms) throws TransportException { + public RemoteSession getSession( + URIish uri, CredentialsProvider credentialsProvider, FS fs, int tms) + throws TransportException { try { return new GitSshdSession(uri, credentialsProvider, fs, tms) { @Override @@ -133,4 +138,9 @@ public class GitSshdSessionFactory extends SshSessionFactory implements ClientSe public ClientSession getClientSession() { return session; } + + @Override + public ClientSession getSession() { + return getClientSession(); + } } diff --git a/sshd-scp/src/main/java/org/apache/sshd/client/scp/AbstractScpClient.java b/sshd-scp/src/main/java/org/apache/sshd/client/scp/AbstractScpClient.java index bf8aa22..99bc8e4 100644 --- a/sshd-scp/src/main/java/org/apache/sshd/client/scp/AbstractScpClient.java +++ b/sshd-scp/src/main/java/org/apache/sshd/client/scp/AbstractScpClient.java @@ -63,11 +63,6 @@ public abstract class AbstractScpClient extends AbstractLoggingBean implements S } @Override - public final ClientSession getSession() { - return getClientSession(); - } - - @Override public void download(String[] remote, String local, Collection<Option> options) throws IOException { local = ValidateUtils.checkNotNullAndNotEmpty(local, "Invalid argument local: %s", local); remote = ValidateUtils.checkNotNullAndNotEmpty(remote, "Invalid argument remote: %s", (Object) remote); diff --git a/sshd-scp/src/main/java/org/apache/sshd/client/scp/ScpClient.java b/sshd-scp/src/main/java/org/apache/sshd/client/scp/ScpClient.java index 0e98e0c..a03f77b 100644 --- a/sshd-scp/src/main/java/org/apache/sshd/client/scp/ScpClient.java +++ b/sshd-scp/src/main/java/org/apache/sshd/client/scp/ScpClient.java @@ -66,6 +66,11 @@ public interface ScpClient extends SessionHolder<ClientSession>, ClientSessionHo String SCP_EXEC_CHANNEL_EXIT_STATUS_TIMEOUT = "scp-exec-channel-exit-status-timeout"; long DEFAULT_EXEC_CHANNEL_EXIT_STATUS_TIMEOUT = TimeUnit.SECONDS.toMillis(5L); + @Override + default ClientSession getSession() { + return getClientSession(); + } + default void download(String remote, String local, Option... options) throws IOException { download(remote, local, GenericUtils.of(options)); } diff --git a/sshd-sftp/src/main/java/org/apache/sshd/client/subsystem/sftp/fs/SftpFileSystem.java b/sshd-sftp/src/main/java/org/apache/sshd/client/subsystem/sftp/fs/SftpFileSystem.java index 1602e9f..dc76927 100644 --- a/sshd-sftp/src/main/java/org/apache/sshd/client/subsystem/sftp/fs/SftpFileSystem.java +++ b/sshd-sftp/src/main/java/org/apache/sshd/client/subsystem/sftp/fs/SftpFileSystem.java @@ -49,11 +49,14 @@ import org.apache.sshd.client.subsystem.sftp.SftpClientFactory; import org.apache.sshd.client.subsystem.sftp.SftpVersionSelector; import org.apache.sshd.client.subsystem.sftp.impl.AbstractSftpClient; import org.apache.sshd.common.file.util.BaseFileSystem; +import org.apache.sshd.common.session.SessionHolder; import org.apache.sshd.common.subsystem.sftp.SftpConstants; import org.apache.sshd.common.util.GenericUtils; import org.apache.sshd.common.util.buffer.Buffer; -public class SftpFileSystem extends BaseFileSystem<SftpPath> implements ClientSessionHolder { +public class SftpFileSystem + extends BaseFileSystem<SftpPath> + implements SessionHolder<ClientSession>, ClientSessionHolder { public static final String POOL_SIZE_PROP = "sftp-fs-pool-size"; public static final int DEFAULT_POOL_SIZE = 8; @@ -156,6 +159,11 @@ public class SftpFileSystem extends BaseFileSystem<SftpPath> implements ClientSe return clientSession; } + @Override + public ClientSession getSession() { + return getClientSession(); + } + @SuppressWarnings("synthetic-access") public SftpClient getClient() throws IOException { Wrapper wrapper = wrappers.get();