Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-1955

Proxy authentication doesn't fully work when using system properties

    XMLWordPrintableJSON

    Details

      Description

      Repro:

      1. Set up an authenticating HTTP proxy (I used Squid)
      2. Specify the https.proxyHost, https.proxyPort, https.proxyUser and https.proxyPassword system properties
      3. Specify useSystemProperties when creating the client
      4. Make a call (to an HTTPS target)

      Result:

      The call fails with a 407.

      Expected:
      That the client would be able to authenticate towards the proxy.

      Example code:

        System.setProperty("https.proxyHost" , "localhost");
        System.setProperty("https.proxyPort" , "3128");
        System.setProperty("https.proxyUser", "squid");
        System.setProperty("https.proxyPassword", "squid");
      
        CloseableHttpClient httpclient = HttpClients.custom().useSystemProperties().build();
        HttpGet httpGet = new HttpGet("https://www.google.com");
        CloseableHttpResponse res = httpclient.execute(httpGet);
        System.out.println(res.getStatusLine());
      

      Technical:
      The reason that it doesn't work is that the AuthScope given to SystemDefaultCredentialsProvider uses "http" as scope (the SystemDefaultRoutePlanner always selects "http") but SystemDefaultCredentialsProvider uses this protocol as part of the name of the system properties from which to retrieve credentials and therefore looks for http.proxyHost, http.proxyPort, http.proxyUser and http.proxyPassword.

      (a workaround is thus to specify all eight parameters, with both the http. and https. prefixes but that doesn't seem like a good solution)

      I'll make a pull request with a suggested fix.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                jens.borgland Jens Borgland
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: