use of java.net.Authenticator in project eclipse.jdt.ls by eclipse.
the class JavaLanguageServerPlugin method configureProxy.
private void configureProxy() {
if (Boolean.getBoolean("jdt.ls.disableProxies")) {
ProxySelector.setActiveProvider(DIRECT);
return;
}
// It seems there is no way to set a proxy provider type (manual, native or
// direct) without the Eclipse UI.
// The org.eclipse.core.net plugin removes the http., https. system properties
// when setting its preferences and a proxy provider isn't manual.
// We save these parameters and set them after starting the
// org.eclipse.core.net plugin.
String httpHost = System.getProperty(HTTP_PROXY_HOST);
String httpPort = System.getProperty(HTTP_PROXY_PORT);
String httpUser = System.getProperty(HTTP_PROXY_USER);
String httpPassword = System.getProperty(HTTP_PROXY_PASSWORD);
String httpsHost = System.getProperty(HTTPS_PROXY_HOST);
String httpsPort = System.getProperty(HTTPS_PROXY_PORT);
String httpsUser = System.getProperty(HTTPS_PROXY_USER);
String httpsPassword = System.getProperty(HTTPS_PROXY_PASSWORD);
String httpsNonProxyHosts = System.getProperty(HTTPS_NON_PROXY_HOSTS);
String httpNonProxyHosts = System.getProperty(HTTP_NON_PROXY_HOSTS);
if (StringUtils.isNotBlank(httpUser) || StringUtils.isNotBlank(httpsUser)) {
try {
Platform.getBundle("org.eclipse.core.net").start(Bundle.START_TRANSIENT);
} catch (BundleException e) {
logException(e.getMessage(), e);
}
if (StringUtils.isNotBlank(httpUser) && StringUtils.isNotBlank(httpPassword)) {
Authenticator.setDefault(new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(httpUser, httpPassword.toCharArray());
}
});
}
IProxyService proxyService = getProxyService();
if (proxyService != null) {
ProxySelector.setActiveProvider(MANUAL);
IProxyData[] proxies = proxyService.getProxyData();
for (IProxyData proxy : proxies) {
if ("HTTP".equals(proxy.getType())) {
proxy.setHost(httpHost);
proxy.setPort(httpPort == null ? -1 : Integer.valueOf(httpPort));
proxy.setPassword(httpPassword);
proxy.setUserid(httpUser);
}
if ("HTTPS".equals(proxy.getType())) {
proxy.setHost(httpsHost);
proxy.setPort(httpsPort == null ? -1 : Integer.valueOf(httpsPort));
proxy.setPassword(httpsPassword);
proxy.setUserid(httpsUser);
}
}
try {
proxyService.setProxyData(proxies);
if (httpHost != null) {
System.setProperty(HTTP_PROXY_HOST, httpHost);
}
if (httpPort != null) {
System.setProperty(HTTP_PROXY_PORT, httpPort);
}
if (httpUser != null) {
System.setProperty(HTTP_PROXY_USER, httpUser);
}
if (httpPassword != null) {
System.setProperty(HTTP_PROXY_PASSWORD, httpPassword);
}
if (httpsHost != null) {
System.setProperty(HTTPS_PROXY_HOST, httpsHost);
}
if (httpsPort != null) {
System.setProperty(HTTPS_PROXY_PORT, httpsPort);
}
if (httpsUser != null) {
System.setProperty(HTTPS_PROXY_USER, httpsUser);
}
if (httpsPassword != null) {
System.setProperty(HTTPS_PROXY_PASSWORD, httpsPassword);
}
if (httpsNonProxyHosts != null) {
System.setProperty(HTTPS_NON_PROXY_HOSTS, httpsNonProxyHosts);
}
if (httpNonProxyHosts != null) {
System.setProperty(HTTP_NON_PROXY_HOSTS, httpNonProxyHosts);
}
} catch (CoreException e) {
logException(e.getMessage(), e);
}
}
} else {
ProxySelector.setActiveProvider(NATIVE);
return;
}
}
use of java.net.Authenticator in project java by wavefrontHQ.
the class APIContainer method configureHttpProxy.
private void configureHttpProxy() {
if (proxyConfig.getProxyHost() != null) {
System.setProperty("http.proxyHost", proxyConfig.getProxyHost());
System.setProperty("https.proxyHost", proxyConfig.getProxyHost());
System.setProperty("http.proxyPort", String.valueOf(proxyConfig.getProxyPort()));
System.setProperty("https.proxyPort", String.valueOf(proxyConfig.getProxyPort()));
}
if (proxyConfig.getProxyUser() != null && proxyConfig.getProxyPassword() != null) {
Authenticator.setDefault(new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
if (getRequestorType() == RequestorType.PROXY) {
return new PasswordAuthentication(proxyConfig.getProxyUser(), proxyConfig.getProxyPassword().toCharArray());
} else {
return null;
}
}
});
}
}
use of java.net.Authenticator in project incubator-gobblin by apache.
the class AbstractJobLauncher method setDefaultAuthenticator.
/**
* Set default {@link Authenticator} to the one provided in {@link ConfigurationKeys#DEFAULT_AUTHENTICATOR_CLASS},
* calling the constructor using the provided {@link Properties}
*/
public static void setDefaultAuthenticator(Properties properties) {
String authenticatorClass = properties.getProperty(ConfigurationKeys.DEFAULT_AUTHENTICATOR_CLASS);
if (!Strings.isNullOrEmpty(authenticatorClass)) {
Authenticator authenticator = GobblinConstructorUtils.invokeConstructor(Authenticator.class, authenticatorClass, properties);
Authenticator.setDefault(authenticator);
}
}
Aggregations