X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fcallhome-protocol%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fcallhome%2Fprotocol%2FNetconfCallHomeServer.java;h=75b390f3beaf434e35e14e7b3c65863aece1e508;hb=6975248489c083942ec93131dac8e6eb95d66806;hp=62b37ddb72babba6d0e86004d79e4b6cc691c960;hpb=af2124dc59e2a6402108c7603245eb575858a5b0;p=netconf.git diff --git a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/NetconfCallHomeServer.java b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/NetconfCallHomeServer.java index 62b37ddb72..75b390f3be 100644 --- a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/NetconfCallHomeServer.java +++ b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/NetconfCallHomeServer.java @@ -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 newAuthSshFutureListener(final ClientSession session) { + final PublicKey serverKey = session.getKex().getServerKey(); + return new SshFutureListener() { @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; } }