Bump odlparent to 6.0.0
[netconf.git] / netconf / callhome-protocol / src / main / java / org / opendaylight / netconf / callhome / protocol / NetconfCallHomeServer.java
index 62b37ddb72babba6d0e86004d79e4b6cc691c960..75b390f3beaf434e35e14e7b3c65863aece1e508 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.netconf.callhome.protocol;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.VisibleForTesting;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
@@ -18,12 +19,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 +81,7 @@ public class NetconfCallHomeServer implements AutoCloseable, ServerKeyVerifier {
                         doAuth(clientSession);
                         break;
                     case Authenticated:
-                        doPostAuth(clientSession);
+                        CallHomeSessionContext.getFrom(clientSession).openNetconfChannel();
                         break;
                     default:
                         break;
@@ -102,23 +101,23 @@ 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);
+                }
+            }
+        };
     }
 
+    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
+            justification = "https://github.com/spotbugs/spotbugs/issues/811")
     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 +136,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 +174,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;
         }
     }