Skip to content

Commit

Permalink
[FIXED JENKINS-31915] Proxy settings in plugins page are ignored (#1955)
Browse files Browse the repository at this point in the history
[FIXED JENKINS-31915] Proxy settings in plugins page are ignored
(cherry picked from commit 81e00cc)
  • Loading branch information
escoem authored and olivergondza committed Jun 19, 2016
1 parent 7e02f1d commit 95c3f27
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
38 changes: 34 additions & 4 deletions core/src/main/java/hudson/ProxyConfiguration.java
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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());
}
}
}
}
1 change: 1 addition & 0 deletions core/src/main/resources/hudson/Messages.properties
Expand Up @@ -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
Expand Down
@@ -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.

Expand Down

0 comments on commit 95c3f27

Please sign in to comment.