7b5308a36f3d544cc6f15941237f81a765c7d921
[netconf.git] / netconf / netconf-netty-util / src / main / java / org / opendaylight / netconf / nettyutil / handler / ssh / client / NetconfSshClient.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netconf.nettyutil.handler.ssh.client;
9
10 import com.google.common.annotations.Beta;
11 import org.opendaylight.netconf.shaded.sshd.client.SshClient;
12 import org.opendaylight.netconf.shaded.sshd.common.Factory;
13 import org.opendaylight.netconf.shaded.sshd.common.forward.PortForwardingEventListener;
14 import org.opendaylight.netconf.shaded.sshd.common.util.net.SshdSocketAddress;
15
16 /**
17  * An extension to {@link SshClient} which uses {@link NetconfSessionFactory} to create sessions (leading towards
18  * {@link NetconfClientSessionImpl}.
19  */
20 @Beta
21 public class NetconfSshClient extends SshClient {
22     public static final Factory<SshClient> DEFAULT_NETCONF_SSH_CLIENT_FACTORY = NetconfSshClient::new;
23
24     /*
25      * This is a workaround for sshd-core's instantiation of Proxies. AbstractFactoryManager (which is our superclass)
26      * is calling Proxy.newProxyInstance() with getClass().getClassLoader(), i.e. our class loader.
27      *
28      * Since we are not using PortForwardingEventListener, our classloader does not see it (because we do not import
29      * that package), which leads to an instantiation failure.
30      *
31      * Having these dumb fields alleviates the problem, as it forces the packages to be imported by our bundle.
32      *
33      * FIXME: Remove this once we have an SSHD version with  https://issues.apache.org/jira/browse/SSHD-975 fixed
34      */
35     static final class Sshd975Workarounds {
36         static final PortForwardingEventListener PFEL = null;
37         static final SshdSocketAddress SSA = null;
38     }
39
40     @Override
41     protected NetconfSessionFactory createSessionFactory() {
42         return new NetconfSessionFactory(this);
43     }
44 }