2 * Copyright (c) 2017 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.northbound.netconf;
19 import com.google.inject.Inject;
20 import io.fd.honeycomb.binding.init.ProviderTrait;
21 import io.fd.honeycomb.data.init.ShutdownHandler;
22 import io.fd.honeycomb.northbound.CredentialsConfiguration;
23 import io.fd.honeycomb.northbound.NetconfConfiguration;
24 import io.netty.channel.nio.NioEventLoopGroup;
25 import io.netty.util.concurrent.GlobalEventExecutor;
26 import org.opendaylight.netconf.api.NetconfServerDispatcher;
27 import org.opendaylight.netconf.auth.AuthProvider;
28 import org.opendaylight.netconf.ssh.NetconfNorthboundSshServer;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public final class NetconfSshServerProvider extends ProviderTrait<NetconfNorthboundSshServer> {
34 private static final Logger LOG = LoggerFactory.getLogger(NetconfSshServerProvider.class);
37 private NetconfServerDispatcher dispatcher;
39 private NetconfConfiguration cfgAttributes;
41 private NioEventLoopGroup nettyThreadgroup;
43 private CredentialsConfiguration credentialsCfg;
45 private ShutdownHandler shutdownHandler;
48 protected NetconfNorthboundSshServer create() {
49 if (!cfgAttributes.isNetconfSshEnabled()) {
50 LOG.info("NETCONF SSH disabled, skipping initialization");
53 LOG.info("Starting NETCONF SSH");
55 final NetconfNorthboundSshServer netconfServer = new NetconfNorthboundSshServer(dispatcher, nettyThreadgroup,
56 GlobalEventExecutor.INSTANCE, cfgAttributes.netconfSshBindingAddress.get(),
57 cfgAttributes.netconfSshBindingPort.get().toString(), new SimplelAuthProvider(credentialsCfg));
58 shutdownHandler.register("netconf-northbound-ssh-server", netconfServer::close);
62 private static final class SimplelAuthProvider implements AuthProvider {
64 private final CredentialsConfiguration cfgAttributes;
66 SimplelAuthProvider(final CredentialsConfiguration cfgAttributes) {
67 this.cfgAttributes = cfgAttributes;
71 public boolean authenticated(final String uname, final String passwd) {
72 return cfgAttributes.username.equals(uname) && cfgAttributes.password.equals(passwd);