From 95c3f27e261bed384c3f96cc616cb7b1ee096cbf Mon Sep 17 00:00:00 2001 From: Emilio Escobar Date: Thu, 2 Jun 2016 19:57:40 +0200 Subject: [PATCH] [FIXED JENKINS-31915] Proxy settings in plugins page are ignored (#1955) [FIXED JENKINS-31915] Proxy settings in plugins page are ignored (cherry picked from commit 81e00cc67957018b0d355740a1eeb2bcd21c0609) --- .../main/java/hudson/ProxyConfiguration.java | 38 +++++++++++++++++-- .../main/resources/hudson/Messages.properties | 1 + .../hudson/ProxyConfiguration/help-name.html | 2 +- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/hudson/ProxyConfiguration.java b/core/src/main/java/hudson/ProxyConfiguration.java index efee245641..f7ce804f5e 100644 --- a/core/src/main/java/hudson/ProxyConfiguration.java +++ b/core/src/main/java/hudson/ProxyConfiguration.java @@ -40,6 +40,7 @@ import java.io.Serializable; 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.JenkinsJVM; 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 final class ProxyConfiguration extends AbstractDescribableImpl 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 final class ProxyConfiguration extends AbstractDescribableImpl= 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()); + } + } } } diff --git a/core/src/main/resources/hudson/Messages.properties b/core/src/main/resources/hudson/Messages.properties index 85c7803bfb..6722b6b940 100644 --- a/core/src/main/resources/hudson/Messages.properties +++ b/core/src/main/resources/hudson/Messages.properties @@ -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 diff --git a/core/src/main/resources/hudson/ProxyConfiguration/help-name.html b/core/src/main/resources/hudson/ProxyConfiguration/help-name.html index 53291af38d..62f93846e9 100644 --- a/core/src/main/resources/hudson/ProxyConfiguration/help-name.html +++ b/core/src/main/resources/hudson/ProxyConfiguration/help-name.html @@ -1,7 +1,7 @@
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 - (See JDK networking properties for more details) + (See JDK networking properties for more details) 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.