Search in sources :

Example 1 with Proxy

use of org.eclipse.ecf.core.util.Proxy in project ecf by eclipse.

the class HttpClientProxyCredentialProvider method getCredentials.

public Credentials getCredentials(AuthScope authscope) {
    // $NON-NLS-1$
    Trace.entering(Activator.PLUGIN_ID, DebugOptions.METHODS_ENTERING, HttpClientProxyCredentialProvider.class, "getCredentials " + authscope);
    // First check to see whether given authscope matches any authscope
    // already cached.
    Credentials result = matchCredentials(this.cachedCredentials, authscope);
    // If we have a match, return credentials
    if (result != null)
        return result;
    // If we don't have a match, first get ECF proxy, if any
    Proxy proxy = getECFProxy();
    if (proxy == null)
        return null;
    // Make sure that authscope and proxy host and port match
    if (!matchAuthScopeAndProxy(authscope, proxy))
        return null;
    // Then match scheme, and get credentials from proxy (if it's scheme we know about)
    Credentials credentials = null;
    if ("ntlm".equalsIgnoreCase(authscope.getScheme())) {
        // $NON-NLS-1$
        credentials = getNTLMCredentials(proxy);
    } else if (// $NON-NLS-1$
    "basic".equalsIgnoreCase(authscope.getScheme()) || "digest".equalsIgnoreCase(authscope.getScheme())) {
        // $NON-NLS-1$
        final String proxyUsername = proxy.getUsername();
        final String proxyPassword = proxy.getPassword();
        // If credentials present for proxy then we're done
        if (proxyUsername != null) {
            credentials = new UsernamePasswordCredentials(proxyUsername, proxyPassword);
        }
    } else if ("negotiate".equalsIgnoreCase(authscope.getScheme())) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        Trace.trace(Activator.PLUGIN_ID, "SPNEGO is not supported, if you can contribute support, please do so.");
    } else {
        // $NON-NLS-1$
        Trace.trace(Activator.PLUGIN_ID, "Unrecognized authentication scheme.");
    }
    // Put found credentials in cache for next time
    if (credentials != null)
        cachedCredentials.put(authscope, credentials);
    return credentials;
}
Also used : Proxy(org.eclipse.ecf.core.util.Proxy) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 2 with Proxy

use of org.eclipse.ecf.core.util.Proxy in project ecf by eclipse.

the class ScpUtil method setupProxy.

/**
 */
void setupProxy() {
    com.jcraft.jsch.Proxy jProxy = null;
    final Proxy proxy = handler.getProxy();
    if (proxy != null) {
        final String hostname = proxy.getAddress().getHostName();
        final int port = proxy.getAddress().getPort();
        if (proxy.getType().equals(Proxy.Type.HTTP)) {
            if (port == -1)
                jProxy = new ProxyHTTP(hostname);
            else
                jProxy = new ProxyHTTP(hostname, port);
        } else if (proxy.getType().equals(Proxy.Type.SOCKS)) {
            if (port == -1)
                jProxy = new ProxySOCKS5(hostname);
            else
                jProxy = new ProxySOCKS5(hostname, port);
        }
        if (jProxy != null)
            session.setProxy(jProxy);
    }
}
Also used : Proxy(org.eclipse.ecf.core.util.Proxy) com.jcraft.jsch(com.jcraft.jsch)

Example 3 with Proxy

use of org.eclipse.ecf.core.util.Proxy in project ecf by eclipse.

the class ProxySetupHelper method getProxy.

public static Proxy getProxy(String url) {
    Proxy proxy = null;
    try {
        IProxyService proxyService = Activator.getDefault().getProxyService();
        // Only do this if platform service exists
        if (proxyService != null && proxyService.isProxiesEnabled()) {
            // Setup via proxyService entry
            URI uri = new URI(url);
            final IProxyData[] proxies = proxyService.select(uri);
            IProxyData selectedProxy = selectProxyFromProxies(uri.getScheme(), proxies);
            if (selectedProxy != null) {
                proxy = new Proxy(((selectedProxy.getType().equalsIgnoreCase(IProxyData.SOCKS_PROXY_TYPE)) ? Proxy.Type.SOCKS : Proxy.Type.HTTP), new ProxyAddress(selectedProxy.getHost(), selectedProxy.getPort()), selectedProxy.getUserId(), selectedProxy.getPassword());
            }
        }
    } catch (Exception e) {
        // If we don't even have the classes for this (i.e. the org.eclipse.core.net plugin not available)
        // then we simply log and ignore
        Activator.logNoProxyWarning(e);
    } catch (NoClassDefFoundError e) {
        Activator.logNoProxyWarning(e);
    }
    return proxy;
}
Also used : Proxy(org.eclipse.ecf.core.util.Proxy) IProxyData(org.eclipse.core.net.proxy.IProxyData) ProxyAddress(org.eclipse.ecf.core.util.ProxyAddress) URI(java.net.URI) IProxyService(org.eclipse.core.net.proxy.IProxyService)

Example 4 with Proxy

use of org.eclipse.ecf.core.util.Proxy in project ecf by eclipse.

the class HttpClientBrowseFileTransferFactory method newInstance.

public IRemoteFileSystemBrowser newInstance() {
    return new IRemoteFileSystemBrowser() {

        private Proxy proxy;

        private IConnectContext connectContext;

        public Namespace getBrowseNamespace() {
            return IDFactory.getDefault().getNamespaceByName(FileTransferNamespace.PROTOCOL);
        }

        public IRemoteFileSystemRequest sendBrowseRequest(IFileID directoryOrFileId, IRemoteFileSystemListener listener) throws RemoteFileSystemException {
            Assert.isNotNull(directoryOrFileId);
            Assert.isNotNull(listener);
            URL url;
            try {
                url = directoryOrFileId.getURL();
            } catch (final MalformedURLException e) {
                // $NON-NLS-1$
                throw new RemoteFileSystemException(NLS.bind("Exception creating URL for {0}", directoryOrFileId));
            }
            HttpClientFileSystemBrowser browser = new HttpClientFileSystemBrowser(new SNIAwareHttpClient(), directoryOrFileId, listener, url, connectContext, proxy);
            return browser.sendBrowseRequest();
        }

        public void setConnectContextForAuthentication(IConnectContext connectContext) {
            this.connectContext = connectContext;
        }

        public void setProxy(Proxy proxy) {
            this.proxy = proxy;
        }

        public Object getAdapter(Class adapter) {
            return null;
        }
    };
}
Also used : IConnectContext(org.eclipse.ecf.core.security.IConnectContext) RemoteFileSystemException(org.eclipse.ecf.filetransfer.RemoteFileSystemException) IRemoteFileSystemBrowser(org.eclipse.ecf.filetransfer.service.IRemoteFileSystemBrowser) Proxy(org.eclipse.ecf.core.util.Proxy) MalformedURLException(java.net.MalformedURLException) IFileID(org.eclipse.ecf.filetransfer.identity.IFileID) IRemoteFileSystemListener(org.eclipse.ecf.filetransfer.IRemoteFileSystemListener) URL(java.net.URL)

Example 5 with Proxy

use of org.eclipse.ecf.core.util.Proxy in project ecf by eclipse.

the class ScpBrowseFileTransferFactory method newInstance.

public IRemoteFileSystemBrowser newInstance() {
    return new IRemoteFileSystemBrowser() {

        private Proxy proxy;

        private IConnectContext connectContext;

        public Namespace getBrowseNamespace() {
            return IDFactory.getDefault().getNamespaceByName(FileTransferNamespace.PROTOCOL);
        }

        public IRemoteFileSystemRequest sendBrowseRequest(IFileID directoryOrFileId, IRemoteFileSystemListener listener) throws RemoteFileSystemException {
            Assert.isNotNull(directoryOrFileId);
            Assert.isNotNull(listener);
            URL url;
            try {
                url = directoryOrFileId.getURL();
            } catch (final MalformedURLException e) {
                throw new RemoteFileSystemException(NLS.bind("Exception creating URL for {0}", // $NON-NLS-1$
                directoryOrFileId));
            }
            ScpFileSystemBrowser browser = new ScpFileSystemBrowser(directoryOrFileId, listener, url, connectContext, proxy);
            return browser.sendBrowseRequest();
        }

        public void setConnectContextForAuthentication(IConnectContext connectContext) {
            this.connectContext = connectContext;
        }

        public void setProxy(Proxy proxy) {
            this.proxy = proxy;
        }

        public Object getAdapter(Class adapter) {
            return null;
        }
    };
}
Also used : IConnectContext(org.eclipse.ecf.core.security.IConnectContext) IRemoteFileSystemBrowser(org.eclipse.ecf.filetransfer.service.IRemoteFileSystemBrowser) Proxy(org.eclipse.ecf.core.util.Proxy) MalformedURLException(java.net.MalformedURLException) IFileID(org.eclipse.ecf.filetransfer.identity.IFileID) URL(java.net.URL)

Aggregations

Proxy (org.eclipse.ecf.core.util.Proxy)6 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 IConnectContext (org.eclipse.ecf.core.security.IConnectContext)2 ProxyAddress (org.eclipse.ecf.core.util.ProxyAddress)2 IFileID (org.eclipse.ecf.filetransfer.identity.IFileID)2 IRemoteFileSystemBrowser (org.eclipse.ecf.filetransfer.service.IRemoteFileSystemBrowser)2 com.jcraft.jsch (com.jcraft.jsch)1 URI (java.net.URI)1 Credentials (org.apache.http.auth.Credentials)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 IProxyData (org.eclipse.core.net.proxy.IProxyData)1 IProxyService (org.eclipse.core.net.proxy.IProxyService)1 IRemoteFileSystemListener (org.eclipse.ecf.filetransfer.IRemoteFileSystemListener)1 RemoteFileSystemException (org.eclipse.ecf.filetransfer.RemoteFileSystemException)1