Update for sshd-2.3.0 changes 67/85267/3
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 16 Sep 2019 02:24:45 +0000 (04:24 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 20 Oct 2019 09:24:44 +0000 (11:24 +0200)
sshd-2.3.0 changed APIs slightly, this makes the simple migration
of our code.

Change-Id: Ic525b317356a8d9ee3b0ad0b8a0fa78e10d2b482
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 74a5603f11edae5a6c071d35e8a2c33845440df9)

netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/RemoteNetconfCommand.java

index 36313786b16b82552822c193d5b3ed9a06609375..8e2d7565eb2cdd19e6cb8b5ec01a02356fca39f9 100644 (file)
@@ -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;
  * <p>
  * 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<Command> {
 
         public static final String NETCONF = "netconf";
@@ -185,5 +186,4 @@ public class RemoteNetconfCommand implements AsyncCommand, SessionAware {
             return new RemoteNetconfCommand(clientBootstrap, localAddress);
         }
     }
-
 }