Menu

#1729 Authentication is unnecessary sent

Latest SVN
closed
RBRi
None
1
2016-08-17
2015-11-17
No

For the below code, authentication is send to the second website, even if it is not the specified host.

Possible area is MainClientExec.execute()

    try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
        DefaultCredentialsProvider credentials = new DefaultCredentialsProvider();
        credentials.addCredentials("httpwatch", "hi", "www.httpwatch.com", -1, null);
        webClient.setCredentialsProvider(credentials);

        String url = "https://www.httpwatch.com/httpgallery/authentication/authenticatedimage/default.aspx?0.8471780607942492";
        webClient.getPage(url);
        System.out.println("---------------------------------------");

        // authentication is also sent here
        webClient.getPage("http://htmlunit.sf.net");
    }

Discussion

  • RBRi

    RBRi - 2016-03-10

    Did some debugging for this. The root of the problem seems to be the reuse of the HttpContext for different hosts/ports/realms/schemes.

     
  • Hartmut Arlt

    Hartmut Arlt - 2016-08-04

    Exactly Ronald. But a feasible fix might be to unconditionally remove the target auth state from the context and use a shared authentication cache for all threads of a web client such that authentication is done only once (if needed). Patch attached.

    Tests with this modification worked fine for me.

    In case the proxy (and its authentication) is expected to change during the lifetime of a web-client instance, the proxy auth state needs to be removed as well.

    Thx,
    H

     
  • RBRi

    RBRi - 2016-08-15
    • status: open --> accepted
    • assigned_to: RBRi
     
  • RBRi

    RBRi - 2016-08-15

    Patch applied

     
    • Hartmut Arlt

      Hartmut Arlt - 2016-08-17

      Thanks Ronald. Looks good to me.

       
      • RBRi

        RBRi - 2016-08-17

        Great, will close this.

         
  • RBRi

    RBRi - 2016-08-17
    • status: accepted --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB