JDK-4941958 : HttpURLConnection per instance Authenticator
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 1.4.2,6u23
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2003-10-22
  • Updated: 2016-12-02
  • Resolved: 2016-12-02
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Description
Name: rmT116609			Date: 10/22/2003


A DESCRIPTION OF THE REQUEST :
Currently, a JVM cam have at most one 'live' Authenticator object at any
given time; i.e. the one set using Authenticator.setDefault().  This causes
problems in some applications.  I propose that a new method be added to
the URLConnection API:

    void setAuthenticator(java.net.Authenticator auth)
       throws InvalidStateException;

This method would allow an application to bind a specific Authenticator
to an unconnected URLConnection object to be used instead of the JVM-wide
default Authenticator.

JUSTIFICATION :
This method will make it possible to do a number of things that are otherwise
hard to implement in a multi-threaded application.  For example, if a URL has
a 'userinfo' componenent, the application can create a once-off Authenticator
for the URL's username and password and attach it to the URLConnection.  It does not need to worrying about interfering with (or leaking passwords to) other
threads.
(Incident Review ID: 216097) 
======================================================================

Comments
Please see the new HttpURLConnection::setAuthenticator method added by JDK-8169495
02-12-2016

EVALUATION Reopened to study the impact "If applications contains few third party plugins and each plugin use its own Authenticator what we should do ? Each invocation of "Authenticator.setDefault()" method rewrite previously defined Authenticator..""
09-07-2007

EVALUATION For the sample in description section, it could be done by registering an Authenticator which returns appropriate PasswordAuthentication instance for that specific URL and 'userinfo' component. Basically Authenticator is bound to host, port, protocol, scheme, etc., not HttpURLConnection instance. It doesn't make much sense to set an Authenticator on a HttpURLConnection. Will not fix.
09-01-2007

EVALUATION Could be a useful feature. Too late for Tiger, will consider for Mustang. ###@###.### 2003-10-30
30-10-2003