Refactor ClientFactoryManagerConfigurator
[netconf.git] / apps / callhome-provider / src / main / java / org / opendaylight / netconf / topology / callhome / CallHomeSshServer.java
index 27286b818236ff3870c3048712ea40e6577a00b1..49eb4c0174324b9bac01c41ed2425758dccb6be3 100644 (file)
@@ -20,6 +20,7 @@ import java.util.concurrent.TimeoutException;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.netconf.api.TransportConstants;
 import org.opendaylight.netconf.client.NetconfClientSessionNegotiatorFactory;
+import org.opendaylight.netconf.shaded.sshd.client.ClientFactoryManager;
 import org.opendaylight.netconf.shaded.sshd.client.auth.password.UserAuthPasswordFactory;
 import org.opendaylight.netconf.shaded.sshd.client.auth.pubkey.UserAuthPublicKeyFactory;
 import org.opendaylight.netconf.shaded.sshd.client.session.ClientSession;
@@ -68,11 +69,17 @@ public final class CallHomeSshServer implements AutoCloseable {
         // NB actual username will be assigned dynamically but predefined one is required for transport initialization
         final var sshClientParams = new SshClientParametersBuilder().setClientIdentity(
             new ClientIdentityBuilder().setUsername("ignored").build()).build();
-        final ClientFactoryManagerConfigurator configurator = factoryMgr -> {
-            factoryMgr.setServerKeyVerifier(this::verifyServerKey);
-            factoryMgr.addSessionListener(createSessionListener());
-            // supported auth factories
-            factoryMgr.setUserAuthFactories(List.of(new UserAuthPasswordFactory(), new UserAuthPublicKeyFactory()));
+        final var configurator = new ClientFactoryManagerConfigurator() {
+            @Override
+            protected void configureClientFactoryManager(final ClientFactoryManager factoryManager) {
+                factoryManager.setServerKeyVerifier((clientSession, remoteAddress, serverKey)
+                    -> verifyServerKey(clientSession, remoteAddress, serverKey));
+                factoryManager.addSessionListener(createSessionListener());
+                // supported auth factories
+                factoryManager.setUserAuthFactories(List.of(
+                    new UserAuthPasswordFactory(),
+                    new UserAuthPublicKeyFactory()));
+            }
         };
         try {
             client = transportStackFactory.listenClient(TransportConstants.SSH_SUBSYSTEM, transportChannelListener,