Do not require NetconfSessionImpl 27/89427/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 29 Apr 2020 12:14:18 +0000 (14:14 +0200)
committerRobert Varga <nite@hq.sk>
Fri, 15 May 2020 09:17:24 +0000 (09:17 +0000)
Drop the instanceOf checks down to simple null checks, so that
we are not tied to a particular implementation.

JIRA: NETCONF-674
Change-Id: I3b9d123d6034a96e6b2d09d68d3cf5bae117cc78
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit d6d0678d47378b5f7ed1316d34ebd240991f5756)

netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeAuthorization.java
netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContext.java

index 673c932050a917f969438b8820547eeaad9648d1..6bcabfe9179a6c4e79e1cbb62debabdba208600b 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.netconf.callhome.protocol;
 
-import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.collect.ImmutableSet;
@@ -16,7 +15,6 @@ import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
 import org.apache.sshd.client.session.ClientSession;
-import org.apache.sshd.client.session.ClientSessionImpl;
 
 /**
  * Authorization context for incoming call home sessions.
@@ -166,7 +164,6 @@ public abstract class CallHomeAuthorization {
 
         @Override
         protected void applyTo(final ClientSession session) {
-            checkArgument(session instanceof ClientSessionImpl);
             session.setUsername(username);
 
             // First try authentication using server host keys, else try password.
index cf064152d1fc78bc3d13172e20743f7e5097a675..4e7bf41b2b4f6b1df9cccb94d453bc16e3a92de4 100644 (file)
@@ -23,7 +23,6 @@ import org.apache.sshd.client.channel.ClientChannel;
 import org.apache.sshd.client.future.AuthFuture;
 import org.apache.sshd.client.future.OpenFuture;
 import org.apache.sshd.client.session.ClientSession;
-import org.apache.sshd.client.session.ClientSessionImpl;
 import org.apache.sshd.common.future.SshFutureListener;
 import org.apache.sshd.common.session.Session;
 import org.checkerframework.checker.lock.qual.Holding;
@@ -41,7 +40,7 @@ class CallHomeSessionContext implements CallHomeProtocolSessionContext {
 
     private static final String NETCONF = "netconf";
 
-    private final ClientSessionImpl sshSession;
+    private final ClientSession sshSession;
     private final CallHomeAuthorization authorization;
     private final Factory factory;
 
@@ -55,10 +54,8 @@ class CallHomeSessionContext implements CallHomeProtocolSessionContext {
                            final SocketAddress remoteAddress, final Factory factory) {
         this.authorization = requireNonNull(authorization, "authorization");
         checkArgument(this.authorization.isServerAllowed(), "Server was not allowed.");
-        checkArgument(sshSession instanceof ClientSessionImpl,
-                "sshSession must implement ClientSessionImpl");
         this.factory = requireNonNull(factory, "factory");
-        this.sshSession = (ClientSessionImpl) sshSession;
+        this.sshSession = requireNonNull(sshSession, "sshSession");
         this.sshSession.setAttribute(SESSION_KEY, this);
         this.remoteAddress = (InetSocketAddress) this.sshSession.getIoSession().getRemoteAddress();
         this.serverKey = this.sshSession.getKex().getServerKey();