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);
}
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;
}
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;
}
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;
}
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()));
}
Aggregations