public static String getPrivateKeyPath(final BundleContext context) { return getPropertyValue(context, getPrivateKeyKey()); }
/** * @param context from which properties are being read. * @param infixProp either tcp or ssh * @return value if address and port are present and valid, Optional.absent otherwise. * @throws IllegalStateException if address or port are invalid, or configuration is missing */ public static Optional<InetSocketAddress> extractNetconfServerAddress(final BundleContext context, final InfixProp infixProp) { final Optional<String> address = getProperty(context, getNetconfServerAddressKey(infixProp)); final Optional<String> port = getProperty(context, PREFIX_PROP + infixProp + PORT_SUFFIX_PROP); if (address.isPresent() && port.isPresent()) { try { return Optional.of(parseAddress(address, port)); } catch (final RuntimeException e) { LOG.warn("Unable to parse {} netconf address from {}:{}, fallback to default", infixProp, address, port, e); } } return Optional.absent(); }
@Override public void start(BundleContext context) { final Optional<InetSocketAddress> maybeAddress = NetconfConfigUtil.extractNetconfServerAddress(context, InfixProp.tcp); if (maybeAddress.isPresent() == false) { LOG.debug("Netconf tcp server is not configured to start"); return; } InetSocketAddress address = maybeAddress.get(); if (address.getAddress().isAnyLocalAddress()) { LOG.warn("Unprotected netconf TCP address is configured to ANY local address. This is a security risk. Consider changing {} to 127.0.0.1", NetconfConfigUtil.getNetconfServerAddressKey(InfixProp.tcp)); } LOG.info("Starting TCP netconf server at {}", address); proxyServer = new ProxyServer(address, NetconfConfigUtil.getNetconfLocalAddress()); }
@Override public void start(final BundleContext context) { AggregatedNetconfOperationServiceFactory factoriesListener = new AggregatedNetconfOperationServiceFactory(); startOperationServiceFactoryTracker(context, factoriesListener); SessionIdProvider idProvider = new SessionIdProvider(); timer = new HashedWheelTimer(); long connectionTimeoutMillis = NetconfConfigUtil.extractTimeoutMillis(context); commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer()); NetconfMonitoringService monitoringService = startMonitoringService(context, factoriesListener); NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory( timer, factoriesListener, idProvider, connectionTimeoutMillis, commitNot, monitoringService); eventLoopGroup = new NioEventLoopGroup(); NetconfServerDispatcherImpl.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcherImpl.ServerChannelInitializer( serverNegotiatorFactory); NetconfServerDispatcherImpl dispatch = new NetconfServerDispatcherImpl(serverChannelInitializer, eventLoopGroup, eventLoopGroup); LocalAddress address = NetconfConfigUtil.getNetconfLocalAddress(); LOG.trace("Starting local netconf server at {}", address); dispatch.createLocalServer(address); }