Enable public key based authentication for netconf
[netconf.git] / netconf / netconf-topology-singleton / src / main / java / org / opendaylight / netconf / topology / singleton / impl / RemoteDeviceConnectorImpl.java
index f242558f051736bf43a05c37b610a90103c717d7..57bd458bf514e1614ba6c2589f4d29b9aa384bd2 100644 (file)
@@ -33,7 +33,7 @@ import org.opendaylight.netconf.client.conf.NetconfClientConfiguration;
 import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration;
 import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfigurationBuilder;
 import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
-import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPassword;
+import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.PublicKeyAuth;
 import org.opendaylight.netconf.sal.connect.api.RemoteDevice;
 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
 import org.opendaylight.netconf.sal.connect.netconf.LibraryModulesSchemas;
@@ -78,6 +78,8 @@ public class RemoteDeviceConnectorImpl implements RemoteDeviceConnector {
     private final RemoteDeviceId remoteDeviceId;
     private final DOMMountPointService mountService;
     private final Timeout actorResponseWaitTime;
+    private final String privateKeyPath;
+    private final String privateKeyPassphrase;
 
     private NetconfConnectorDTO deviceCommunicatorDTO;
 
@@ -89,6 +91,8 @@ public class RemoteDeviceConnectorImpl implements RemoteDeviceConnector {
         this.remoteDeviceId = remoteDeviceId;
         this.actorResponseWaitTime = actorResponseWaitTime;
         this.mountService = mountService;
+        this.privateKeyPath = netconfTopologyDeviceSetup.getPrivateKeyPath();
+        this.privateKeyPassphrase = netconfTopologyDeviceSetup.getPrivateKeyPassphrase();
     }
 
     @Override
@@ -276,11 +280,12 @@ public class RemoteDeviceConnectorImpl implements RemoteDeviceConnector {
         final Credentials credentials = node.getCredentials();
         if (credentials instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf
                 .node.credentials.credentials.LoginPassword) {
-            authHandler = new LoginPassword(
+            authHandler = new PublicKeyAuth(
                     ((org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf
                             .node.credentials.credentials.LoginPassword) credentials).getUsername(),
                     ((org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf
-                            .node.credentials.credentials.LoginPassword) credentials).getPassword());
+                            .node.credentials.credentials.LoginPassword) credentials).getPassword(),
+                    this.privateKeyPath, this.privateKeyPassphrase);
         } else {
             throw new IllegalStateException(remoteDeviceId + ": Only login/password authentication is supported");
         }