mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-20 00:04:27 +01:00
[i444] Support nonProxyHosts parameter in settings.xml
This commit is contained in:
@@ -667,6 +667,7 @@ public abstract class BaseDependencyCheckMojo extends AbstractMojo implements Ma
|
|||||||
final String password = proxy.getPassword();
|
final String password = proxy.getPassword();
|
||||||
Settings.setStringIfNotNull(Settings.KEYS.PROXY_USERNAME, userName);
|
Settings.setStringIfNotNull(Settings.KEYS.PROXY_USERNAME, userName);
|
||||||
Settings.setStringIfNotNull(Settings.KEYS.PROXY_PASSWORD, password);
|
Settings.setStringIfNotNull(Settings.KEYS.PROXY_PASSWORD, password);
|
||||||
|
Settings.setStringIfNotNull(Settings.KEYS.PROXY_NON_PROXY_HOSTS, proxy.getNonProxyHosts());
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings.setStringIfNotEmpty(Settings.KEYS.CONNECTION_TIMEOUT, connectionTimeout);
|
Settings.setStringIfNotEmpty(Settings.KEYS.CONNECTION_TIMEOUT, connectionTimeout);
|
||||||
|
|||||||
@@ -165,6 +165,10 @@ public final class Settings {
|
|||||||
* The properties key for the proxy password.
|
* The properties key for the proxy password.
|
||||||
*/
|
*/
|
||||||
public static final String PROXY_PASSWORD = "proxy.password";
|
public static final String PROXY_PASSWORD = "proxy.password";
|
||||||
|
/**
|
||||||
|
* The properties key for the non proxy hosts.
|
||||||
|
*/
|
||||||
|
public static final String PROXY_NON_PROXY_HOSTS = "proxy.nonproxyhosts";
|
||||||
/**
|
/**
|
||||||
* The properties key for the connection timeout.
|
* The properties key for the connection timeout.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -53,13 +53,15 @@ public final class URLConnectionFactory {
|
|||||||
public static HttpURLConnection createHttpURLConnection(URL url) throws URLConnectionFailureException {
|
public static HttpURLConnection createHttpURLConnection(URL url) throws URLConnectionFailureException {
|
||||||
HttpURLConnection conn = null;
|
HttpURLConnection conn = null;
|
||||||
final String proxyUrl = Settings.getString(Settings.KEYS.PROXY_SERVER);
|
final String proxyUrl = Settings.getString(Settings.KEYS.PROXY_SERVER);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (proxyUrl != null) {
|
if (proxyUrl != null && !skipProxy(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);
|
||||||
|
|
||||||
final String username = Settings.getString(Settings.KEYS.PROXY_USERNAME);
|
final String username = Settings.getString(Settings.KEYS.PROXY_USERNAME);
|
||||||
final String password = Settings.getString(Settings.KEYS.PROXY_PASSWORD);
|
final String password = Settings.getString(Settings.KEYS.PROXY_PASSWORD);
|
||||||
|
|
||||||
if (username != null && password != null) {
|
if (username != null && password != null) {
|
||||||
final Authenticator auth = new Authenticator() {
|
final Authenticator auth = new Authenticator() {
|
||||||
@Override
|
@Override
|
||||||
@@ -94,6 +96,24 @@ public final class URLConnectionFactory {
|
|||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks of for the given URL the proxy shall be used or not checking the nonProxyHosts configuration.
|
||||||
|
* @param url The URL to check.
|
||||||
|
* @return If the proxy shall be skip for the given URL or not.
|
||||||
|
*/
|
||||||
|
private static boolean skipProxy(URL url) {
|
||||||
|
boolean skip = false;
|
||||||
|
final String nonProxySettings = Settings.getString(Settings.KEYS.PROXY_NON_PROXY_HOSTS);
|
||||||
|
String[] nonProxyHosts = nonProxySettings.split(",");
|
||||||
|
for (int i = 0; i < nonProxyHosts.length; i++) {
|
||||||
|
if (url.getHost().matches(nonProxyHosts[i])) {
|
||||||
|
skip = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return skip;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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