You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2016/04/02 12:26:42 UTC

svn commit: r1737485 - /httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultCredentialsProvider.java

Author: olegk
Date: Sat Apr  2 10:26:41 2016
New Revision: 1737485

URL: http://svn.apache.org/viewvc?rev=1737485&view=rev
Log:
HTTPCLIENT-1732: SystemDefaultCredentialsProvider to take http.proxyHost and http.proxyPort system properties into account

Modified:
    httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultCredentialsProvider.java

Modified: httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultCredentialsProvider.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultCredentialsProvider.java?rev=1737485&r1=1737484&r2=1737485&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultCredentialsProvider.java (original)
+++ httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultCredentialsProvider.java Sat Apr  2 10:26:41 2016
@@ -111,12 +111,30 @@ public class SystemDefaultCredentialsPro
         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");