From cbf517ace6588ed532e28e8099ad7e95f50af4e5 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Sat, 2 Apr 2016 10:26:41 +0000 Subject: [PATCH] HTTPCLIENT-1732: SystemDefaultCredentialsProvider to take http.proxyHost and http.proxyPort system properties into account git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/branches/4.5.x@1737485 13f79535-47bb-0310-9956-ffa450edef68 --- .../SystemDefaultCredentialsProvider.java | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultCredentialsProvider.java b/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultCredentialsProvider.java index 69c4fde41..debe142fa 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultCredentialsProvider.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultCredentialsProvider.java @@ -111,12 +111,30 @@ public class SystemDefaultCredentialsProvider implements CredentialsProvider { if (localcreds != null) { return localcreds; } - if (authscope.getHost() != null) { - PasswordAuthentication systemcreds = getSystemCreds( - authscope, Authenticator.RequestorType.SERVER); + final String host = authscope.getHost(); + if (host != null) { + PasswordAuthentication systemcreds = getSystemCreds(authscope, Authenticator.RequestorType.SERVER); if (systemcreds == null) { - systemcreds = getSystemCreds( - authscope, Authenticator.RequestorType.PROXY); + systemcreds = getSystemCreds(authscope, Authenticator.RequestorType.PROXY); + } + if (systemcreds == null) { + final String proxyHost = System.getProperty("http.proxyHost"); + if (proxyHost != null) { + final String proxyPort = System.getProperty("http.proxyPort"); + if (proxyPort != null) { + try { + final AuthScope systemScope = new AuthScope(proxyHost, Integer.parseInt(proxyPort)); + if (authscope.match(systemScope) >= 0) { + final String proxyUser = System.getProperty("http.proxyUser"); + if (proxyUser != null) { + final String proxyPassword = System.getProperty("http.proxyPassword"); + systemcreds = new PasswordAuthentication(proxyUser, proxyPassword != null ? proxyPassword.toCharArray() : new char[] {}); + } + } + } catch (NumberFormatException ex) { + } + } + } } if (systemcreds != null) { final String domain = System.getProperty("http.auth.ntlm.domain");