From: Maros Marsalek Date: Wed, 3 Sep 2014 15:26:11 +0000 (+0200) Subject: Fix netconf testtool after recent changes to auth in netconf X-Git-Tag: release/helium~151^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=342cb43285c509aaba0ea8a7652ec16ed1f9068e Fix netconf testtool after recent changes to auth in netconf Change-Id: I924057380d2a63d062ef33a4d9bc29af61265dc3 Signed-off-by: Maros Marsalek --- diff --git a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/AcceptingAuthProvider.java b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/AcceptingAuthProvider.java index 35f2345248..4721acf209 100644 --- a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/AcceptingAuthProvider.java +++ b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/AcceptingAuthProvider.java @@ -8,29 +8,13 @@ package org.opendaylight.controller.netconf.test.tool; -import java.io.File; -import java.io.IOException; -import org.opendaylight.controller.netconf.ssh.authentication.AuthProvider; -import org.opendaylight.controller.netconf.ssh.authentication.PEMGenerator; +import org.opendaylight.controller.netconf.auth.AuthProvider; class AcceptingAuthProvider implements AuthProvider { - private final String privateKeyPEMString; - - public AcceptingAuthProvider() { - try { - this.privateKeyPEMString = PEMGenerator.readOrGeneratePK(new File("PK")); - } catch (final IOException e) { - throw new RuntimeException(e); - } - } @Override public synchronized boolean authenticated(final String username, final String password) { return true; } - @Override - public char[] getPEMAsCharArray() { - return privateKeyPEMString.toCharArray(); - } } diff --git a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java index 3a52f0a85e..2cd5b19bd1 100644 --- a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java +++ b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java @@ -23,6 +23,7 @@ import io.netty.channel.local.LocalAddress; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.util.HashedWheelTimer; import java.io.Closeable; +import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.lang.management.ManagementFactory; @@ -55,6 +56,7 @@ import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceSnapshot; import org.opendaylight.controller.netconf.monitoring.osgi.NetconfMonitoringOperationService; import org.opendaylight.controller.netconf.ssh.NetconfSSHServer; +import org.opendaylight.controller.netconf.ssh.authentication.PEMGenerator; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException; import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation; @@ -165,7 +167,8 @@ public class NetconfDeviceSimulator implements Closeable { server = dispatcher.createLocalServer(tcpLocalAddress); try { - NetconfSSHServer.start(currentPort, tcpLocalAddress, new AcceptingAuthProvider(), nettyThreadgroup); + final NetconfSSHServer sshServer = NetconfSSHServer.start(currentPort, tcpLocalAddress, nettyThreadgroup, getPemArray()); + sshServer.setAuthProvider(new AcceptingAuthProvider()); } catch (final Exception e) { LOG.warn("Cannot start simulated device on {}, skipping", address, e); // Close local server and continue @@ -219,6 +222,14 @@ public class NetconfDeviceSimulator implements Closeable { return openDevices; } + private char[] getPemArray() { + try { + return PEMGenerator.readOrGeneratePK(new File("PK")).toCharArray(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } + private Map parseSchemasToModuleBuilders(final Main.Params params) { final SharedSchemaRepository consumer = new SharedSchemaRepository("netconf-simulator"); consumer.registerSchemaSourceListener(TextToASTTransformer.create(consumer, consumer));