Use base64 encoding for netconf device passwords
[netconf.git] / apps / netconf-topology / src / main / java / org / opendaylight / netconf / topology / spi / AbstractNetconfTopology.java
index c61f0fe7002ed29368028ed35090e6c170e53daa..ffb03877ec54a663decd6045fa6e1b48103789bc 100644 (file)
@@ -10,14 +10,11 @@ package org.opendaylight.netconf.topology.spi;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.VisibleForTesting;
-import io.netty.util.concurrent.EventExecutor;
+import io.netty.util.Timer;
 import java.util.HashMap;
 import java.util.NoSuchElementException;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Executor;
-import java.util.concurrent.ScheduledExecutorService;
-import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
-import org.opendaylight.controller.config.threadpool.ThreadPool;
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
@@ -28,7 +25,7 @@ import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceHandler;
 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceId;
 import org.opendaylight.netconf.client.mdsal.api.SchemaResourceManager;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.optional.rev221225.NetconfNodeAugmentedOptional;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev231121.NetconfNode;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
@@ -45,29 +42,26 @@ public abstract class AbstractNetconfTopology {
 
     private final HashMap<NodeId, NetconfNodeHandler> activeConnectors = new HashMap<>();
     private final NetconfClientFactory clientFactory;
-    private final EventExecutor eventExecutor;
     private final DeviceActionFactory deviceActionFactory;
     private final SchemaResourceManager schemaManager;
     private final BaseNetconfSchemas baseSchemas;
     private final NetconfClientConfigurationBuilderFactory builderFactory;
+    private final Timer timer;
 
-    protected final ScheduledExecutorService scheduledExecutor;
     protected final Executor processingExecutor;
     protected final DataBroker dataBroker;
     protected final DOMMountPointService mountPointService;
     protected final String topologyId;
 
-    protected AbstractNetconfTopology(final String topologyId, final NetconfClientFactory clientDispatcher,
-            final EventExecutor eventExecutor, final ScheduledThreadPool scheduledThreadPool,
-            final ThreadPool processingThreadPool, final SchemaResourceManager schemaManager,
+    protected AbstractNetconfTopology(final String topologyId, final NetconfClientFactory clientFactory,
+            final Timer timer, final Executor processingExecutor, final SchemaResourceManager schemaManager,
             final DataBroker dataBroker, final DOMMountPointService mountPointService,
             final NetconfClientConfigurationBuilderFactory builderFactory,
             final DeviceActionFactory deviceActionFactory, final BaseNetconfSchemas baseSchemas) {
         this.topologyId = requireNonNull(topologyId);
-        this.clientFactory = clientDispatcher;
-        this.eventExecutor = eventExecutor;
-        this.scheduledExecutor = scheduledThreadPool.getExecutor();
-        this.processingExecutor = processingThreadPool.getExecutor();
+        this.clientFactory = requireNonNull(clientFactory);
+        this.timer = requireNonNull(timer);
+        this.processingExecutor = requireNonNull(processingExecutor);
         this.schemaManager = requireNonNull(schemaManager);
         this.deviceActionFactory = deviceActionFactory;
         this.dataBroker = requireNonNull(dataBroker);
@@ -117,7 +111,9 @@ public abstract class AbstractNetconfTopology {
             return;
         }
 
-        LOG.info("Connecting RemoteDevice{{}}, with config {}", nodeId, hideCredentials(node));
+        if (LOG.isInfoEnabled()) {
+            LOG.info("Connecting RemoteDevice{{}}, with config {}", nodeId, hideCredentials(node));
+        }
 
         // Instantiate the handler ...
         final var nodeOptional = node.augmentation(NetconfNodeAugmentedOptional.class);
@@ -125,9 +121,8 @@ public abstract class AbstractNetconfTopology {
 
         final NetconfNodeHandler nodeHandler;
         try {
-            nodeHandler = new NetconfNodeHandler(clientFactory, scheduledExecutor, baseSchemas,
-                schemaManager, processingExecutor, builderFactory, deviceActionFactory, deviceSalFacade,
-                deviceId, nodeId, netconfNode, nodeOptional);
+            nodeHandler = new NetconfNodeHandler(clientFactory, timer, baseSchemas, schemaManager, processingExecutor,
+                builderFactory, deviceActionFactory, deviceSalFacade, deviceId, nodeId, netconfNode, nodeOptional);
         } catch (IllegalArgumentException e) {
             // This is a workaround for NETCONF-1114 where the encrypted password's lexical structure is not enforced
             // in the datastore and it ends up surfacing when we decrypt the password.
@@ -175,9 +170,12 @@ public abstract class AbstractNetconfTopology {
      */
     @VisibleForTesting
     static final String hideCredentials(final Node nodeConfiguration) {
-        final var netconfNodeAugmentation = nodeConfiguration.augmentation(NetconfNode.class);
-        final var nodeCredentials = netconfNodeAugmentation.getCredentials().toString();
         final var nodeConfigurationString = nodeConfiguration.toString();
-        return nodeConfigurationString.replace(nodeCredentials, "***");
+        final var netconfNodeAugmentation = nodeConfiguration.augmentation(NetconfNode.class);
+        if (netconfNodeAugmentation != null && netconfNodeAugmentation.getCredentials() != null) {
+            final var nodeCredentials = netconfNodeAugmentation.getCredentials().toString();
+            return nodeConfigurationString.replace(nodeCredentials, "***");
+        }
+        return nodeConfigurationString;
     }
 }