Make negotiationFuture final
[netconf.git] / netconf / callhome-protocol / src / main / java / org / opendaylight / netconf / callhome / protocol / NetconfCallHomeServer.java
index 62b37ddb72babba6d0e86004d79e4b6cc691c960..2e4f3607430e82c2deb64ada6290db23049dcf30 100644 (file)
@@ -18,12 +18,10 @@ import org.apache.sshd.client.SshClient;
 import org.apache.sshd.client.future.AuthFuture;
 import org.apache.sshd.client.keyverifier.ServerKeyVerifier;
 import org.apache.sshd.client.session.ClientSession;
-import org.apache.sshd.client.session.ClientSessionImpl;
 import org.apache.sshd.client.session.SessionFactory;
 import org.apache.sshd.common.future.SshFutureListener;
 import org.apache.sshd.common.io.IoAcceptor;
 import org.apache.sshd.common.io.IoServiceFactory;
-import org.apache.sshd.common.kex.KeyExchange;
 import org.apache.sshd.common.session.Session;
 import org.apache.sshd.common.session.SessionListener;
 import org.apache.sshd.netty.NettyIoServiceFactory;
@@ -82,7 +80,7 @@ public class NetconfCallHomeServer implements AutoCloseable, ServerKeyVerifier {
                         doAuth(clientSession);
                         break;
                     case Authenticated:
-                        doPostAuth(clientSession);
+                        CallHomeSessionContext.getFrom(clientSession).openNetconfChannel();
                         break;
                     default:
                         break;
@@ -102,23 +100,21 @@ public class NetconfCallHomeServer implements AutoCloseable, ServerKeyVerifier {
                 }
                 LOG.debug("SSH Session {} closed", session);
             }
-        };
-    }
-
-    private static void doPostAuth(final ClientSession session) {
-        CallHomeSessionContext.getFrom(session).openNetconfChannel();
-    }
 
-    private void doAuth(final ClientSession session) {
-        try {
-            final AuthFuture authFuture = CallHomeSessionContext.getFrom(session).authorize();
-            authFuture.addListener(newAuthSshFutureListener(session));
-        } catch (IOException e) {
-            LOG.error("Failed to authorize session {}", session, e);
-        }
+            private void doAuth(final ClientSession session) {
+                try {
+                    final AuthFuture authFuture = CallHomeSessionContext.getFrom(session).authorize();
+                    authFuture.addListener(newAuthSshFutureListener(session));
+                } catch (IOException e) {
+                    LOG.error("Failed to authorize session {}", session, e);
+                }
+            }
+        };
     }
 
     private SshFutureListener<AuthFuture> newAuthSshFutureListener(final ClientSession session) {
+        final PublicKey serverKey = session.getKex().getServerKey();
+
         return new SshFutureListener<AuthFuture>() {
             @Override
             public void operationComplete(final AuthFuture authFuture) {
@@ -137,13 +133,8 @@ public class NetconfCallHomeServer implements AutoCloseable, ServerKeyVerifier {
             }
 
             private void onFailure(final Throwable throwable) {
-                ClientSessionImpl impl = (ClientSessionImpl) session;
                 LOG.error("Authorize failed for session {}", session, throwable);
-
-                KeyExchange kex = impl.getKex();
-                PublicKey key = kex.getServerKey();
-                recorder.reportFailedAuth(key);
-
+                recorder.reportFailedAuth(serverKey);
                 session.close(true);
             }
 
@@ -180,7 +171,7 @@ public class NetconfCallHomeServer implements AutoCloseable, ServerKeyVerifier {
             client.start();
             acceptor.bind(bindAddress);
         } catch (IOException e) {
-            LOG.error("Unable to start NETCONF CallHome Service", e);
+            LOG.error("Unable to start NETCONF CallHome Service on {}", bindAddress, e);
             throw e;
         }
     }