X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Futil%2Fosgi%2FNetconfConfigUtil.java;h=35e17a2a3e4564ffceac32158d00e5f7e6faba39;hp=5c9d823cc0c000606de9bcf7ba0a6ecc5b25d390;hb=3fb02545b8541925b54932e2d67a6360fe77f134;hpb=a92d9d6a21a0f6ca8d2153795721f500eaf29ee9 diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtil.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtil.java index 5c9d823cc0..35e17a2a3e 100644 --- a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtil.java +++ b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtil.java @@ -9,9 +9,10 @@ package org.opendaylight.controller.netconf.util.osgi; import com.google.common.base.Optional; -import org.opendaylight.controller.config.stat.ConfigProvider; import org.opendaylight.protocol.util.SSLUtil; +import org.osgi.framework.BundleContext; +import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import java.io.File; import java.io.FileInputStream; @@ -25,7 +26,7 @@ public class NetconfConfigUtil { private static final String PREFIX_PROP = "netconf."; private enum InfixProp { - tcp, tls + tcp, tls, ssh } private static final String PORT_SUFFIX_PROP = ".port"; @@ -34,19 +35,29 @@ public class NetconfConfigUtil { private static final String NETCONF_TLS_KEYSTORE_PROP = PREFIX_PROP + InfixProp.tls + ".keystore"; private static final String NETCONF_TLS_KEYSTORE_PASSWORD_PROP = NETCONF_TLS_KEYSTORE_PROP + ".password"; - public static Optional extractTCPNetconfAddress(ConfigProvider configProvider) { - return extractSomeNetconfAddress(configProvider, InfixProp.tcp); + public static InetSocketAddress extractTCPNetconfAddress(BundleContext context, String exceptionMessageIfNotFound) { + + Optional inetSocketAddressOptional = extractSomeNetconfAddress(context, InfixProp.tcp); + if (inetSocketAddressOptional.isPresent() == false) { + throw new IllegalStateException("Netconf tcp address not found." + exceptionMessageIfNotFound); + } + return inetSocketAddressOptional.get(); } - public static Optional extractTLSConfiguration(ConfigProvider configProvider) { - Optional address = extractSomeNetconfAddress(configProvider, InfixProp.tls); + public static Optional extractSSHNetconfAddress(BundleContext context) { + return extractSomeNetconfAddress(context, InfixProp.ssh); + } + + + public static Optional extractTLSConfiguration(BundleContext context) { + Optional address = extractSomeNetconfAddress(context, InfixProp.tls); if (address.isPresent()) { - String keystoreFileName = configProvider.getProperty(NETCONF_TLS_KEYSTORE_PROP); + String keystoreFileName = context.getProperty(NETCONF_TLS_KEYSTORE_PROP); File keystoreFile = new File(keystoreFileName); checkState(keystoreFile.exists() && keystoreFile.isFile() && keystoreFile.canRead(), "Keystore file %s does not exist or is not readable file", keystoreFileName); keystoreFile = keystoreFile.getAbsoluteFile(); - String keystorePassword = configProvider.getProperty(NETCONF_TLS_KEYSTORE_PASSWORD_PROP); + String keystorePassword = context.getProperty(NETCONF_TLS_KEYSTORE_PASSWORD_PROP); checkNotNull(keystoreFileName, "Property %s must be defined for tls netconf server", NETCONF_TLS_KEYSTORE_PROP); keystorePassword = keystorePassword != null ? keystorePassword : ""; @@ -69,7 +80,7 @@ public class NetconfConfigUtil { try { try (InputStream keyStoreIS = new FileInputStream(keystoreFile)) { try (InputStream trustStoreIS = new FileInputStream(keystoreFile)) { - sslContext = SSLUtil.initializeSecureContext("password", keyStoreIS, trustStoreIS, "SunX509"); + sslContext = SSLUtil.initializeSecureContext("password", keyStoreIS, trustStoreIS, KeyManagerFactory.getDefaultAlgorithm()); } } } catch (Exception e) { @@ -95,7 +106,7 @@ public class NetconfConfigUtil { } /** - * @param configProvider + * @param context * from which properties are being read. * @param infixProp * either tcp or tls @@ -104,14 +115,14 @@ public class NetconfConfigUtil { * @throws IllegalStateException * if address or port are invalid */ - private static Optional extractSomeNetconfAddress(ConfigProvider configProvider, + private static Optional extractSomeNetconfAddress(BundleContext context, InfixProp infixProp) { - String address = configProvider.getProperty(PREFIX_PROP + infixProp + ADDRESS_SUFFIX_PROP); + String address = context.getProperty(PREFIX_PROP + infixProp + ADDRESS_SUFFIX_PROP); if (address == null) { return Optional.absent(); } String portKey = PREFIX_PROP + infixProp + PORT_SUFFIX_PROP; - String portString = configProvider.getProperty(portKey); + String portString = context.getProperty(portKey); checkNotNull(portString, "Netconf port must be specified in properties file with " + portKey); try { int port = Integer.valueOf(portString);