com.jcraft.jsch.ProxySOCKS5 Java Examples

The following examples show how to use com.jcraft.jsch.ProxySOCKS5. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PooledSFTPConnection.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Proxy[] getProxies() {
	String proxyString = authority.getProxyString();
	if (!StringUtils.isEmpty(proxyString)) {
		java.net.Proxy proxy = FileUtils.getProxy(authority.getProxyString());
		if ((proxy != null) && (proxy.type() != Type.DIRECT)) {
			URI proxyUri = URI.create(proxyString);
			String hostName = proxyUri.getHost();
			int port = proxyUri.getPort();
			String userInfo = proxyUri.getUserInfo();
			org.jetel.util.protocols.UserInfo proxyCredentials = null;
			if (userInfo != null) {
				proxyCredentials = new org.jetel.util.protocols.UserInfo(userInfo);
			}
			switch (proxy.type()) {
			case HTTP:
				ProxyHTTP proxyHttp = (port >= 0) ? new ProxyHTTP(hostName, port) : new ProxyHTTP(hostName);
				if (proxyCredentials != null) {
					proxyHttp.setUserPasswd(proxyCredentials.getUser(), proxyCredentials.getPassword());
				}
				return new Proxy[] {proxyHttp};
			case SOCKS:
				ProxySOCKS4 proxySocks4 = (port >= 0) ? new ProxySOCKS4(hostName, port) : new ProxySOCKS4(hostName);
				ProxySOCKS5 proxySocks5 = (port >= 0) ? new ProxySOCKS5(hostName, port) : new ProxySOCKS5(hostName);
				if (proxyCredentials != null) {
					proxySocks4.setUserPasswd(proxyCredentials.getUser(), proxyCredentials.getPassword());
					proxySocks5.setUserPasswd(proxyCredentials.getUser(), proxyCredentials.getPassword());
				}
				return new Proxy[] {proxySocks5, proxySocks4};
			case DIRECT:
				return new Proxy[1];
			}
		}
	}
	
	return new Proxy[1];
}
 
Example #2
Source File: JGitSshSessionFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private com.jcraft.jsch.Proxy createProxy (String proxyHost, int proxyPort) {
    return USE_PROXY_TUNNELING
            ? new ProxyHTTP(proxyHost, proxyPort)
            : new ProxySOCKS5(proxyHost, proxyPort);
}
 
Example #3
Source File: SshConnectionImpl.java    From gerrit-events with MIT License 4 votes vote down vote up
/**
 * Connects the connection.
 * @throws IOException if the unfortunate happens.
 */
@Override
public synchronized void connect() throws IOException {
    logger.debug("connecting...");
    Authentication auth = authentication;
    if (updater != null) {
        Authentication updatedAuth = updater.updateAuthentication(authentication);
        if (updatedAuth != null && auth != updatedAuth) {
            auth = updatedAuth;
        }
    }
    try {
        client = new JSch();
        if (auth.getPrivateKeyPhrase() == null) {
            client.addIdentity(auth.getPrivateKeyFile().getAbsolutePath(),
                    auth.getPrivateKeyFilePassword());
        } else {
            client.addIdentity(auth.getUsername(), auth.getPrivateKeyPhrase(), null,
                    auth.getPrivateKeyFilePassword().getBytes("UTF-8"));
        }
        client.setHostKeyRepository(new BlindHostKeyRepository());
        connectSession = client.getSession(auth.getUsername(), host, port);
        connectSession.setConfig("PreferredAuthentications", "publickey");
        if (proxy != null && !proxy.isEmpty()) {
            String[] splitted = proxy.split(":");
            if (splitted.length > 2 && splitted[1].length() >= PROTO_HOST_DELIM_LENGTH) {
                String pproto = splitted[0];
                String phost = splitted[1].substring(2);
                int pport = Integer.parseInt(splitted[2]);
                if (pproto.equals("socks5") || pproto.equals("http")) {
                    if (pproto.equals("socks5")) {
                         connectSession.setProxy(new ProxySOCKS5(phost, pport));
                    } else {
                         connectSession.setProxy(new ProxyHTTP(phost, pport));
                    }
                } else {
                    throw new MalformedURLException("Only http and socks5 protocols are supported");
                }
            } else {
                throw new MalformedURLException(proxy);
            }
        }
        connectSession.connect(this.connectionTimeout);
        logger.debug("Connected: {}", connectSession.isConnected());
        connectSession.setServerAliveInterval(ALIVE_INTERVAL);
    } catch (JSchException ex) {
        throw new SshException(ex);
    }
}
 
Example #4
Source File: SftpClientFactory.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
private static ProxySOCKS5 createProxySOCKS5(final String proxyHost, final int proxyPort) {
    return proxyPort == 0 ? new ProxySOCKS5(proxyHost) : new ProxySOCKS5(proxyHost, proxyPort);
}