|
|
|
|
|
|
|
|
import org.eclipse.jgit.transport.sshd.KeyCache; |
|
|
import org.eclipse.jgit.transport.sshd.KeyCache; |
|
|
import org.eclipse.jgit.transport.sshd.ProxyData; |
|
|
import org.eclipse.jgit.transport.sshd.ProxyData; |
|
|
import org.eclipse.jgit.transport.sshd.ProxyDataFactory; |
|
|
import org.eclipse.jgit.transport.sshd.ProxyDataFactory; |
|
|
import org.slf4j.Logger; |
|
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Customized {@link SshClient} for JGit. It creates specialized |
|
|
* Customized {@link SshClient} for JGit. It creates specialized |
|
|
|
|
|
|
|
|
* were created for, and it loads all KeyPair identities lazily. |
|
|
* were created for, and it loads all KeyPair identities lazily. |
|
|
*/ |
|
|
*/ |
|
|
public class JGitSshClient extends SshClient { |
|
|
public class JGitSshClient extends SshClient { |
|
|
private static Logger LOG = LoggerFactory.getLogger(JGitSshClient.class); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* We need access to this during the constructor of the ClientSession, |
|
|
* We need access to this during the constructor of the ClientSession, |
|
|
* before setConnectAddress() can have been called. So we have to remember |
|
|
* before setConnectAddress() can have been called. So we have to remember |
|
|
|
|
|
|
|
|
setAttribute(HOST_CONFIG_ENTRY, hostConfig); |
|
|
setAttribute(HOST_CONFIG_ENTRY, hostConfig); |
|
|
setAttribute(ORIGINAL_REMOTE_ADDRESS, address); |
|
|
setAttribute(ORIGINAL_REMOTE_ADDRESS, address); |
|
|
// Proxy support |
|
|
// Proxy support |
|
|
ProxyData proxy = getProxyData(hostConfig, address); |
|
|
|
|
|
|
|
|
ProxyData proxy = getProxyData(address); |
|
|
if (proxy != null) { |
|
|
if (proxy != null) { |
|
|
address = configureProxy(proxy, address); |
|
|
address = configureProxy(proxy, address); |
|
|
proxy.clearPassword(); |
|
|
proxy.clearPassword(); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private ProxyData getProxyData(HostConfigEntry hostConfig, |
|
|
|
|
|
InetSocketAddress remoteAddress) { |
|
|
|
|
|
|
|
|
private ProxyData getProxyData(InetSocketAddress remoteAddress) { |
|
|
ProxyDataFactory factory = getProxyDatabase(); |
|
|
ProxyDataFactory factory = getProxyDatabase(); |
|
|
return factory == null ? null : factory.get(hostConfig, remoteAddress); |
|
|
|
|
|
|
|
|
return factory == null ? null : factory.get(remoteAddress); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private InetSocketAddress configureProxy(ProxyData proxyData, |
|
|
private InetSocketAddress configureProxy(ProxyData proxyData, |
|
|
|
|
|
|
|
|
proxyData.getUser(), proxyData.getPassword())); |
|
|
proxyData.getUser(), proxyData.getPassword())); |
|
|
return address; |
|
|
return address; |
|
|
default: |
|
|
default: |
|
|
LOG.warn(format(SshdText.get().unknownProxyProtocol, |
|
|
|
|
|
|
|
|
log.warn(format(SshdText.get().unknownProxyProtocol, |
|
|
proxy.type().name())); |
|
|
proxy.type().name())); |
|
|
return remoteAddress; |
|
|
return remoteAddress; |
|
|
} |
|
|
} |