Class ThreadLocalAuthenticator


  • public class ThreadLocalAuthenticator
    extends Authenticator
    This is a thread local implementation of an Authenticator for java.net classes. Each concurrent thread can use different credentials.

    Example usage:

     ThreadLocalAuthenticator.setAsDefault();
     ThreadLocalAuthenticator.setServerAuth(username,password);
     URL url=new URL("http://webmailer.mycompany.de");
     InputStream stream=url.openConnection().getInputStream();
     
    Author:
    Stefan Frings, http://stefanfrings.de/javautils
    • Method Detail

      • setServerAuth

        public static void setServerAuth​(String username,
                                         String password)
        Set credentials for web server authentication.
        Parameters:
        username - Username
        password - Password
      • setProxyAuth

        public static void setProxyAuth​(String username,
                                        String password)
        Set credentials for proxy server authentication.
        Parameters:
        username - Username
        password - Password
      • getInstance

        public static ThreadLocalAuthenticator getInstance()
        Get the single instance of this class.
        Returns:
        The ThreadLocalAuthenticator
      • setAsDefault

        public static void setAsDefault()
        Set this Authenticator as default.