private List<ProxyConfig.Proxy> proxies(Config conf) { if (conf.hasPath("proxy")) { return Arrays.asList(new ProxyConfig.Proxy(conf.getString("proxy.id"), conf.getString("proxy.protocol"), conf.getString("proxy.host"), conf.getInt("proxy.port"), conf.getString("proxy.username"), conf.getString("proxy.password"), conf.getString("proxy.nonProxyHosts"))); } return Collections.emptyList(); }
private static List<String> buildArguments(ProxyConfig proxyConfig, String npmRegistryURL) { List<String> arguments = new ArrayList<String>(); if(npmRegistryURL != null && !npmRegistryURL.isEmpty()){ arguments.add ("--registry=" + npmRegistryURL); } if(!proxyConfig.isEmpty()){ Proxy proxy = null; if(npmRegistryURL != null && !npmRegistryURL.isEmpty()){ proxy = proxyConfig.getProxyForUrl(npmRegistryURL); } if(proxy == null){ proxy = proxyConfig.getSecureProxy(); } if(proxy == null){ proxy = proxyConfig.getInsecureProxy(); } arguments.add("--https-proxy=" + proxy.getUri().toString()); arguments.add("--proxy=" + proxy.getUri().toString()); } return arguments; } }
public Proxy getProxyForUrl(String requestUrl) { if (proxies.isEmpty()) { LOGGER.info("No proxies configured"); return null; } final URI uri = URI.create(requestUrl); for (Proxy proxy : proxies) { if (!proxy.isNonProxyHost(uri.getHost())) { return proxy; } } LOGGER.info("Could not find matching proxy for host: {}", uri.getHost()); return null; }
static ProxyConfig getProxyConfig(MavenSession mavenSession, SettingsDecrypter decrypter) { if (mavenSession == null || mavenSession.getSettings() == null || mavenSession.getSettings().getProxies() == null || mavenSession.getSettings().getProxies().isEmpty()) { return new ProxyConfig(Collections.<ProxyConfig.Proxy>emptyList()); } else { final List<Proxy> mavenProxies = mavenSession.getSettings().getProxies(); final List<ProxyConfig.Proxy> proxies = new ArrayList<ProxyConfig.Proxy>(mavenProxies.size()); for (Proxy mavenProxy : mavenProxies) { if (mavenProxy.isActive()) { mavenProxy = decryptProxy(mavenProxy, decrypter); proxies.add(new ProxyConfig.Proxy(mavenProxy.getId(), mavenProxy.getProtocol(), mavenProxy.getHost(), mavenProxy.getPort(), mavenProxy.getUsername(), mavenProxy.getPassword(), mavenProxy.getNonProxyHosts())); } } LOGGER.info("Found proxies: {}", proxies); return new ProxyConfig(proxies); } }
public static ProxyConfig getProxyConfig(MavenSession mavenSession, SettingsDecrypter decrypter) { if (mavenSession == null || mavenSession.getSettings() == null || mavenSession.getSettings().getProxies() == null || mavenSession.getSettings().getProxies().isEmpty()) { return new ProxyConfig(Collections.<ProxyConfig.Proxy>emptyList()); } else { final List<Proxy> mavenProxies = mavenSession.getSettings().getProxies(); final List<ProxyConfig.Proxy> proxies = new ArrayList<>(mavenProxies.size()); for (Proxy mavenProxy : mavenProxies) { if (mavenProxy.isActive()) { mavenProxy = decryptProxy(mavenProxy, decrypter); proxies.add(new ProxyConfig.Proxy(mavenProxy.getId(), mavenProxy.getProtocol(), mavenProxy.getHost(), mavenProxy.getPort(), mavenProxy.getUsername(), mavenProxy.getPassword(), mavenProxy.getNonProxyHosts())); } } return new ProxyConfig(proxies); } }
private ProxyConfig.Proxy createProxy(Proxy proxy) { return new ProxyConfig.Proxy(proxy.getId(), proxy.getProtocol(), proxy.getHost(), proxy.getPort(), proxy.getUsername(), proxy.getPassword(), proxy.getNonProxyHosts()); } }
private CloseableHttpResponse execute(String requestUrl, String userName, String password) throws IOException { CloseableHttpResponse response; Proxy proxy = proxyConfig.getProxyForUrl(requestUrl); if (proxy != null) { LOGGER.info("Downloading via proxy " + proxy.toString()); return executeViaProxy(proxy, requestUrl); } else { LOGGER.info("No proxy was configured, downloading directly"); if (StringUtils.isNotEmpty(userName) && StringUtils.isNotEmpty(password)) { LOGGER.info("Using credentials (" + userName + ") from settings.xml"); // Auth target host URL aURL = new URL(requestUrl); HttpClientContext localContext = makeLocalContext(aURL); CredentialsProvider credentialsProvider = makeCredentialsProvider( aURL.getHost(), aURL.getPort(), userName, password); response = buildHttpClient(credentialsProvider).execute(new HttpGet(requestUrl),localContext); } else { response = buildHttpClient(null).execute(new HttpGet(requestUrl)); } } return response; }
private static List<String> buildArguments(ProxyConfig proxyConfig, String npmRegistryURL) { List<String> arguments = new ArrayList<>(); if (npmRegistryURL != null && !npmRegistryURL.isEmpty()) { arguments.add("--registry=" + npmRegistryURL); } if (!proxyConfig.isEmpty()) { Proxy proxy = null; if (npmRegistryURL != null && !npmRegistryURL.isEmpty()) { proxy = proxyConfig.getProxyForUrl(npmRegistryURL); } if (proxy == null) { proxy = proxyConfig.getSecureProxy(); } if (proxy == null) { proxy = proxyConfig.getInsecureProxy(); } arguments.add("--https-proxy=" + proxy.getUri().toString()); arguments.add("--proxy=" + proxy.getUri().toString()); } return arguments; } }
static ProxyConfig getProxyConfig(MavenSession mavenSession, SettingsDecrypter decrypter) { if (mavenSession == null || mavenSession.getSettings() == null || mavenSession.getSettings().getProxies() == null || mavenSession.getSettings().getProxies().isEmpty()) { return new ProxyConfig(Collections.<ProxyConfig.Proxy>emptyList()); } else { final List<Proxy> mavenProxies = mavenSession.getSettings().getProxies(); final List<ProxyConfig.Proxy> proxies = new ArrayList<ProxyConfig.Proxy>(mavenProxies.size()); for (Proxy mavenProxy : mavenProxies) { if (mavenProxy.isActive()) { mavenProxy = decryptProxy(mavenProxy, decrypter); proxies.add(new ProxyConfig.Proxy(mavenProxy.getId(), mavenProxy.getProtocol(), mavenProxy.getHost(), mavenProxy.getPort(), mavenProxy.getUsername(), mavenProxy.getPassword(), mavenProxy.getNonProxyHosts())); } } LOGGER.info("Found proxies: {}", proxies); return new ProxyConfig(proxies); } }
private static List<String> buildArguments(ProxyConfig proxyConfig) { List<String> arguments = new ArrayList<String>(); if (!proxyConfig.isEmpty()) { ProxyConfig.Proxy secureProxy = proxyConfig.getSecureProxy(); if (secureProxy != null){ arguments.add("--config.https-proxy=" + secureProxy.getUri().toString()); } ProxyConfig.Proxy insecureProxy = proxyConfig.getInsecureProxy(); if (insecureProxy != null) { arguments.add("--config.proxy=" + insecureProxy.getUri().toString()); } } return arguments; } }
private CloseableHttpResponse executeViaProxy(Proxy proxy, String requestUrl) throws IOException { final CloseableHttpClient proxyClient; if (proxy.useAuthentication()){ proxyClient = buildHttpClient(makeCredentialsProvider(proxy.host,proxy.port,proxy.username,proxy.password)); } else { proxyClient = buildHttpClient(null); } final HttpHost proxyHttpHost = new HttpHost(proxy.host, proxy.port); final RequestConfig requestConfig = RequestConfig.custom().setProxy(proxyHttpHost).build(); final HttpGet request = new HttpGet(requestUrl); request.setConfig(requestConfig); return proxyClient.execute(request); }
public URI getUri() { String authentication = useAuthentication() ? username + ":" + password : null; try { // Proxies should be schemed with http, even if the protocol is https return new URI("http", authentication, host, port, null, null, null); } catch (URISyntaxException e) { throw new ProxyConfigException("Invalid proxy settings", e); } }
@Override public String toString() { return id + "{" + "protocol='" + protocol + '\'' + ", host='" + host + '\'' + ", port=" + port + (useAuthentication()? ", with username/passport authentication" : "") + '}'; } }
public Proxy getSecureProxy() { for (Proxy proxy : proxies) { if (proxy.isSecure()) { return proxy; } } return null; }
public Proxy getInsecureProxy() { for (Proxy proxy : proxies) { if (!proxy.isSecure()) { return proxy; } } return null; }