Skip to content
Permalink
Browse files

[FIXED JENKINS-31915] Proxy settings in plugins page are ignored (#1955)

[FIXED JENKINS-31915] Proxy settings in plugins page are ignored
  • Loading branch information...
escoem authored and oleg-nenashev committed Jun 2, 2016
1 parent 1b2711c commit 81e00cc67957018b0d355740a1eeb2bcd21c0609
@@ -40,6 +40,7 @@
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.Proxy;
import java.net.URL;
@@ -53,6 +54,7 @@
import jenkins.util.SystemProperties;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NTCredentials;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
@@ -340,17 +342,24 @@ public FormValidation doValidateProxy(
if (Util.fixEmptyAndTrim(testUrl) == null) {
return FormValidation.error(Messages.ProxyConfiguration_TestUrlRequired());
}


String host = testUrl;
try {
URL url = new URL(testUrl);
host = url.getHost();
} catch (MalformedURLException e) {
return FormValidation.error(Messages.ProxyConfiguration_MalformedTestUrl(testUrl));
}

GetMethod method = null;
try {
method = new GetMethod(testUrl);
method.getParams().setParameter("http.socket.timeout", DEFAULT_CONNECT_TIMEOUT_MILLIS > 0 ? DEFAULT_CONNECT_TIMEOUT_MILLIS : new Integer(30 * 1000));

HttpClient client = new HttpClient();
if (Util.fixEmptyAndTrim(name) != null) {
if (Util.fixEmptyAndTrim(name) != null && !isNoProxyHost(host, noProxyHost)) {
client.getHostConfiguration().setProxy(name, port);
Credentials credentials =
new UsernamePasswordCredentials(userName, Secret.fromString(password).getPlainText());
Credentials credentials = createCredentials(userName, password);
AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT);
client.getState().setProxyCredentials(scope, credentials);
}
@@ -369,5 +378,26 @@ public FormValidation doValidateProxy(

return FormValidation.ok(Messages.ProxyConfiguration_Success());
}

private boolean isNoProxyHost(String host, String noProxyHost) {
if (host!=null && noProxyHost!=null) {
for (Pattern p : getNoProxyHostPatterns(noProxyHost)) {
if (p.matcher(host).matches()) {
return true;
}
}
}
return false;
}

private Credentials createCredentials(String userName, String password) {
if (userName.indexOf('\\') >= 0){
final String domain = userName.substring(0, userName.indexOf('\\'));
final String user = userName.substring(userName.indexOf('\\') + 1);
return new NTCredentials(user, Secret.fromString(password).getPlainText(), domain, "");
} else {
return new UsernamePasswordCredentials(userName, Secret.fromString(password).getPlainText());
}
}
}
}
@@ -66,6 +66,7 @@ AboutJenkins.DisplayName=About Jenkins
AboutJenkins.Description=See the version and license information.

ProxyConfiguration.TestUrlRequired=Test URL is required.
ProxyConfiguration.MalformedTestUrl=Malformed Test URL {0}.
ProxyConfiguration.FailedToConnectViaProxy=Failed to connect to {0}.
ProxyConfiguration.FailedToConnect=Failed to connect to {0} (code {1}).
ProxyConfiguration.Success=Success
@@ -1,7 +1,7 @@
<div>
If your Jenkins server sits behind a firewall and does not have the direct access to the internet,
and if your server JVM is not configured appropriately
(<a href="http://download.oracle.com/javase/6/docs/technotes/guides/net/properties.html">See JDK networking properties for more details</a>)
(<a href="http://download.oracle.com/javase/7/docs/technotes/guides/net/properties.html">See JDK networking properties for more details</a>)
to enable internet connection, you can specify the HTTP proxy server name in this field to allow Jenkins
to install plugins on behalf of you. Note that Jenkins uses HTTPS to communicate with the update center to download plugins.

0 comments on commit 81e00cc

Please sign in to comment.
You can’t perform that action at this time.