mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-25 02:21:28 +01:00
[i444] Support nonProxyHosts parameter in settings.xml
This commit is contained in:
@@ -139,6 +139,10 @@ Copyright (c) 2014 - Jeremy Long. All Rights Reserved.
|
|||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
<artifactId>commons-io</artifactId>
|
<artifactId>commons-io</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
package org.owasp.dependencycheck.utils;
|
package org.owasp.dependencycheck.utils;
|
||||||
|
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Authenticator;
|
import java.net.Authenticator;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
@@ -55,7 +57,7 @@ public final class URLConnectionFactory {
|
|||||||
final String proxyUrl = Settings.getString(Settings.KEYS.PROXY_SERVER);
|
final String proxyUrl = Settings.getString(Settings.KEYS.PROXY_SERVER);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (proxyUrl != null && !skipProxy(url)) {
|
if (proxyUrl != null && !matchNonProxy(url)) {
|
||||||
final int proxyPort = Settings.getInt(Settings.KEYS.PROXY_PORT);
|
final int proxyPort = Settings.getInt(Settings.KEYS.PROXY_PORT);
|
||||||
final SocketAddress address = new InetSocketAddress(proxyUrl, proxyPort);
|
final SocketAddress address = new InetSocketAddress(proxyUrl, proxyPort);
|
||||||
|
|
||||||
@@ -97,23 +99,47 @@ public final class URLConnectionFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks of for the given URL the proxy shall be used or not checking the nonProxyHosts configuration.
|
* Check if hostname matches nonProxy settings
|
||||||
* @param url The URL to check.
|
*
|
||||||
* @return If the proxy shall be skip for the given URL or not.
|
* @param url the url to connect to
|
||||||
|
* @return matching result. true: match nonProxy
|
||||||
*/
|
*/
|
||||||
private static boolean skipProxy(URL url) {
|
private static boolean matchNonProxy(final URL url) {
|
||||||
boolean skip = false;
|
String host = url.getHost();
|
||||||
final String nonProxySettings = Settings.getString(Settings.KEYS.PROXY_NON_PROXY_HOSTS);
|
|
||||||
String[] nonProxyHosts = nonProxySettings.split(",");
|
// code partially from org.apache.maven.plugins.site.AbstractDeployMojo#getProxyInfo
|
||||||
for (int i = 0; i < nonProxyHosts.length; i++) {
|
final String nonProxyHosts = Settings.getString(Settings.KEYS.PROXY_NON_PROXY_HOSTS);
|
||||||
if (url.getHost().matches(nonProxyHosts[i])) {
|
if (null != nonProxyHosts) {
|
||||||
skip = true;
|
final String[] nonProxies = nonProxyHosts.split( "(,)|(;)|(\\|)" );
|
||||||
break;
|
for (final String nonProxyHost : nonProxies) {
|
||||||
|
//if ( StringUtils.contains( nonProxyHost, "*" ) )
|
||||||
|
if (null != nonProxyHost && nonProxyHost.contains("*")) {
|
||||||
|
// Handle wildcard at the end, beginning or middle of the nonProxyHost
|
||||||
|
final int pos = nonProxyHost.indexOf('*');
|
||||||
|
String nonProxyHostPrefix = nonProxyHost.substring(0, pos);
|
||||||
|
String nonProxyHostSuffix = nonProxyHost.substring(pos + 1);
|
||||||
|
// prefix*
|
||||||
|
if (!StringUtils.isEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix) && StringUtils.isEmpty(nonProxyHostSuffix)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// *suffix
|
||||||
|
if (StringUtils.isEmpty(nonProxyHostPrefix) && !StringUtils.isEmpty(nonProxyHostSuffix) && host.endsWith(nonProxyHostSuffix)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// prefix*suffix
|
||||||
|
if (!StringUtils.isEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix) && !StringUtils.isEmpty(nonProxyHostSuffix) && host.endsWith(nonProxyHostSuffix)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (host.equals(nonProxyHost)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return skip;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility method to create an HttpURLConnection. The use of a proxy here is optional as there may be cases where a proxy is
|
* Utility method to create an HttpURLConnection. The use of a proxy here is optional as there may be cases where a proxy is
|
||||||
* configured but we don't want to use it (for example, if there's an internal repository configured)
|
* configured but we don't want to use it (for example, if there's an internal repository configured)
|
||||||
|
|||||||
Reference in New Issue
Block a user