From: Robert Varga Date: Mon, 16 Sep 2019 02:24:45 +0000 (+0200) Subject: Update for sshd-2.3.0 changes X-Git-Tag: release/neon-sr3~8 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=netconf.git;a=commitdiff_plain;h=9778e2be7f4ae45cbb246b36ee8ddb9318e564d2 Update for sshd-2.3.0 changes sshd-2.3.0 changed APIs slightly, this makes the simple migration of our code. Change-Id: Ic525b317356a8d9ee3b0ad0b8a0fa78e10d2b482 Signed-off-by: Robert Varga (cherry picked from commit 74a5603f11edae5a6c071d35e8a2c33845440df9) --- diff --git a/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/RemoteNetconfCommand.java b/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/RemoteNetconfCommand.java index 36313786b1..8e2d7565eb 100644 --- a/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/RemoteNetconfCommand.java +++ b/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/RemoteNetconfCommand.java @@ -24,7 +24,7 @@ import org.apache.sshd.common.io.IoInputStream; import org.apache.sshd.common.io.IoOutputStream; 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.AsyncCommand; import org.apache.sshd.server.command.Command; import org.apache.sshd.server.session.ServerSession; @@ -39,7 +39,7 @@ import org.slf4j.LoggerFactory; *

* Command is Apache Mina SSH terminology for objects handling ssh data. */ -public class RemoteNetconfCommand implements AsyncCommand, SessionAware { +public class RemoteNetconfCommand implements AsyncCommand { private static final Logger LOG = LoggerFactory.getLogger(RemoteNetconfCommand.class); @@ -102,7 +102,21 @@ public class RemoteNetconfCommand implements AsyncCommand, SessionAware { } @Override - public void start(final Environment env) { + public void start(final ChannelSession channel, final Environment env) { + final ServerSession session = channel.getServerSession(); + final SocketAddress remoteAddress = session.getIoSession().getRemoteAddress(); + final String hostName; + final String port; + if (remoteAddress instanceof InetSocketAddress) { + hostName = ((InetSocketAddress) remoteAddress).getAddress().getHostAddress(); + port = Integer.toString(((InetSocketAddress) remoteAddress).getPort()); + } else { + hostName = ""; + port = ""; + } + netconfHelloMessageAdditionalHeader = new NetconfHelloMessageAdditionalHeader(session.getUsername(), hostName, + port, "ssh", "client"); + LOG.trace("Establishing internal connection to netconf server for client: {}", getClientAddress()); final Bootstrap clientBootstrap = new Bootstrap(); @@ -130,7 +144,7 @@ public class RemoteNetconfCommand implements AsyncCommand, SessionAware { } @Override - public void destroy() { + public void destroy(final ChannelSession channel) { LOG.trace("Releasing internal connection to netconf server for client: {} on channel: {}", getClientAddress(), clientChannel); @@ -149,19 +163,6 @@ public class RemoteNetconfCommand implements AsyncCommand, SessionAware { return netconfHelloMessageAdditionalHeader.getAddress(); } - @Override - public void setSession(final ServerSession session) { - final SocketAddress remoteAddress = session.getIoSession().getRemoteAddress(); - String hostName = ""; - String port = ""; - if (remoteAddress instanceof InetSocketAddress) { - hostName = ((InetSocketAddress) remoteAddress).getAddress().getHostAddress(); - port = Integer.toString(((InetSocketAddress) remoteAddress).getPort()); - } - netconfHelloMessageAdditionalHeader = new NetconfHelloMessageAdditionalHeader( - session.getUsername(), hostName, port, "ssh", "client"); - } - public static class NetconfCommandFactory implements NamedFactory { public static final String NETCONF = "netconf"; @@ -185,5 +186,4 @@ public class RemoteNetconfCommand implements AsyncCommand, SessionAware { return new RemoteNetconfCommand(clientBootstrap, localAddress); } } - }