Search in sources :

Example 11 with IProxyData

use of org.eclipse.core.net.proxy.IProxyData in project tycho by eclipse.

the class ProxyServiceFacadeImpl method configureProxy.

@Override
public void configureProxy(String protocol, String host, int port, String user, String password, String nonProxyHosts) {
    ProxyData proxyData = new ProxyData(getProxyType(protocol));
    proxyData.setHost(host);
    proxyData.setPort(port);
    proxyData.setUserid(user);
    proxyData.setPassword(password);
    proxyData.setSource(MAVEN_SETTINGS_SOURCE);
    try {
        proxyService.setProxyData(new IProxyData[] { proxyData });
        if (nonProxyHosts != null && nonProxyHosts.trim().length() > 0) {
            proxyService.setNonProxiedHosts(NON_PROXY_DELIMITERS.split(nonProxyHosts.trim()));
        }
    } catch (CoreException e) {
        throw new RuntimeException(e);
    }
    // have to register authenticator manually as this is provided as extension point in
    // org.eclipse.ui.net only ...
    registerAuthenticator(user, password);
    proxyService.setProxiesEnabled(true);
    // disable the eclipse native proxy providers
    proxyService.setSystemProxiesEnabled(false);
}
Also used : ProxyData(org.eclipse.core.internal.net.ProxyData) IProxyData(org.eclipse.core.net.proxy.IProxyData) CoreException(org.eclipse.core.runtime.CoreException)

Example 12 with IProxyData

use of org.eclipse.core.net.proxy.IProxyData in project gfm_viewer by satyagraha.

the class WebProxyConfigDefault method getWebProxyData.

@Override
public WebProxyData getWebProxyData(URI uri) {
    WebProxyData webProxyData = null;
    if (proxyService != null) {
        IProxyData[] proxyDataList = proxyService.select(uri);
        LOGGER.fine("for: " + uri + " proxyDataList: " + Arrays.asList(proxyDataList));
        for (IProxyData proxyData : proxyDataList) {
            if (proxyData.getType() != null) {
                webProxyData = new WebProxyDataDefault(proxyData);
                break;
            }
        }
    }
    LOGGER.fine("for: " + uri + " proxy: " + webProxyData);
    return webProxyData;
}
Also used : IProxyData(org.eclipse.core.net.proxy.IProxyData)

Example 13 with IProxyData

use of org.eclipse.core.net.proxy.IProxyData in project epp.mpc by eclipse.

the class ProxyAuthenticator method getPasswordAuthentication.

@Override
protected PasswordAuthentication getPasswordAuthentication() {
    IProxyService proxyService = ProxyHelper.getProxyService();
    if (proxyService != null && proxyService.isProxiesEnabled()) {
        URL requestingURL = getRequestingURL();
        IProxyData[] proxies;
        if (requestingURL == null) {
            proxies = proxyService.getProxyData();
        } else {
            try {
                proxies = proxyService.select(requestingURL.toURI());
            } catch (URISyntaxException e) {
                proxies = proxyService.getProxyData();
            }
        }
        for (IProxyData proxyData : proxies) {
            // make sure we don't hand out credentials to the wrong proxy
            if (proxyData.isRequiresAuthentication() && proxyData.getPort() == getRequestingPort() && hostMatches(proxyData)) {
                String userId = proxyData.getUserId();
                String password = proxyData.getPassword();
                if (userId != null && password != null) {
                    return new PasswordAuthentication(userId, password.toCharArray());
                }
            }
        }
    }
    if (delegate != null) {
        // Eclipse UI bundle registers one to query credentials from user
        try {
            Authenticator.setDefault(delegate);
            String requestingHost = getRequestingHost();
            InetAddress requestingSite = getRequestingSite();
            int requestingPort = getRequestingPort();
            String requestingProtocol = getRequestingProtocol();
            String requestingPrompt = getRequestingPrompt();
            String requestingScheme = getRequestingScheme();
            URL requestingURL = getRequestingURL();
            RequestorType requestorType = getRequestorType();
            if (requestingSite == null) {
                try {
                    requestingSite = InetAddress.getByName(requestingHost);
                } catch (Exception ex) {
                // ignore
                }
            }
            if (requestingPrompt == null) {
                // Help the Eclipse UI password dialog with its prompt
                String promptHost = // $NON-NLS-1$
                requestingSite == null ? // $NON-NLS-1$
                String.format("%s:%s", requestingHost, requestingPort) : requestingHost == null ? requestingSite.getHostName() : requestingHost;
                String promptType = requestorType.toString().toLowerCase();
                requestingPrompt = MessageFormat.format(Messages.ProxyAuthenticator_prompt, requestingScheme, promptType, promptHost);
            }
            return Authenticator.requestPasswordAuthentication(requestingHost, requestingSite, requestingPort, requestingProtocol, requestingPrompt, requestingScheme, requestingURL, requestorType);
        } finally {
            Authenticator.setDefault(this);
        }
    }
    return null;
}
Also used : IProxyData(org.eclipse.core.net.proxy.IProxyData) URISyntaxException(java.net.URISyntaxException) InetAddress(java.net.InetAddress) IProxyService(org.eclipse.core.net.proxy.IProxyService) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) UnknownHostException(java.net.UnknownHostException) PasswordAuthentication(java.net.PasswordAuthentication)

Example 14 with IProxyData

use of org.eclipse.core.net.proxy.IProxyData in project epp.mpc by eclipse.

the class HttpClientProxyUtil method proxyAuthentication.

public static Executor proxyAuthentication(Executor executor, URI uri) throws IOException {
    IProxyData proxy = ProxyHelper.getProxyData(uri);
    if (proxy != null) {
        HttpHost proxyHost = new HttpHost(proxy.getHost(), proxy.getPort());
        String proxyUserID = proxy.getUserId();
        if (proxyUserID != null) {
            String domainUserID = getNTLMUserName(proxyUserID);
            String password = proxy.getPassword();
            String domain = getNTLMUserDomain(proxyUserID);
            if (domain != null || !proxyUserID.equals(domainUserID)) {
                String workstation = getNTLMWorkstation();
                executor.auth(new AuthScope(proxyHost, AuthScope.ANY_REALM, "ntlm"), new NTCredentials(domainUserID, password, workstation, domain));
            }
            return executor.auth(new AuthScope(proxyHost, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME), new UsernamePasswordCredentials(proxyUserID, password));
        }
    }
    return executor;
}
Also used : IProxyData(org.eclipse.core.net.proxy.IProxyData) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) NTCredentials(org.apache.http.auth.NTCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 15 with IProxyData

use of org.eclipse.core.net.proxy.IProxyData in project epp.mpc by eclipse.

the class ProxyConfigurationTest method assertConsistentProxyConfiguration.

private void assertConsistentProxyConfiguration(String protocol) {
    String proxyHost = System.getProperty(protocol + ".proxyHost");
    String proxyPort = System.getProperty(protocol + ".proxyPort");
    assumeNotNull(proxyHost, proxyPort);
    IProxyData[] proxyDatas = proxyService.select(URI.create(protocol + "://github.com"));
    assertNotNull(proxyDatas);
    assertEquals(1, proxyDatas.length);
    IProxyData proxyData = proxyDatas[0];
    assertEquals(proxyHost, proxyData.getHost());
    assertNotNull(proxyPort);
    assertEquals(proxyPort, String.valueOf(proxyData.getPort()));
}
Also used : IProxyData(org.eclipse.core.net.proxy.IProxyData)

Aggregations

IProxyData (org.eclipse.core.net.proxy.IProxyData)18 IProxyService (org.eclipse.core.net.proxy.IProxyService)11 URI (java.net.URI)8 URISyntaxException (java.net.URISyntaxException)8 HttpHost (org.apache.http.HttpHost)5 CoreException (org.eclipse.core.runtime.CoreException)4 AuthScope (org.apache.http.auth.AuthScope)3 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)3 PasswordAuthentication (java.net.PasswordAuthentication)2 Authenticator (java.net.Authenticator)1 InetAddress (java.net.InetAddress)1 Proxy (java.net.Proxy)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 ProxyHost (org.apache.commons.httpclient.ProxyHost)1 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)1 NTCredentials (org.apache.http.auth.NTCredentials)1 CredentialsProvider (org.apache.http.client.CredentialsProvider)1