Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8331889

Allow specifying a custom authenticator for java.net.Socket

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      java.net.Socket supports using proxies, but, unlike java.net.HttpURLConnection, there is no setAuthenticator method. Considering that this method was added to HttpURLConnection in Java 9, I think that it would be appropriate to do the same for the Socket class. Minimal changes are required for this to be possible:
      1. Add a private field named authenticator to java.net.Socket and a public setAuthenticator(Authenticator) method
      2. Modify HttpConnectSocketImpl, the socket implementation for a socket using an http(s) proxy, by setting in the doTunnel method the authenticator of the HttpURLConnection to the one of the delegating socket(this is a one line of code change as HttpURLConnection already has support for setAuthenticator from Java 9)
      3. Modify SocksSocketImpl, the socket implementation for a socket using a socks4/5 proxy, to use the authenticator of the delegating socket in the authenticate method instead of calling Authenticator.requestPasswordAuthentication, which uses the default socket.

      This change is not breaking as the default authenticator of a Socket would still be the default authenticator, which is the current behaviour.


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: