Class PropertyAuthenticator

java.lang.Object
java.net.Authenticator
uk.ac.starlink.util.PropertyAuthenticator

public class PropertyAuthenticator extends Authenticator
Authenticator implementation which uses system properties to set fixed username and passwords for HTTP Basic Authentication. The username and password are acquired from the system properties "star.basicauth.user" and "star.basicauth.password". A convenience method installInstance(boolean) is provided to set this authenticator up for use in all HTTP connection attempts.

Since this uses the same username and password for all web sites, it's obviously a bit of a blunt instrument. It may be refined at some point in the future.

Since:
10 Aug 2011
Author:
Mark Taylor
  • Field Details

    • USER_PROP

      public static final String USER_PROP
      System property supplying basic authentication username ("star.basicauth.user").
      See Also:
    • PASSWORD_PROP

      public static final String PASSWORD_PROP
      System property supplying basic authentication password ("star.basicauth.password").
      See Also:
  • Constructor Details

    • PropertyAuthenticator

      public PropertyAuthenticator()
      Constructor.
  • Method Details

    • getPasswordAuthentication

      public PasswordAuthentication getPasswordAuthentication()
      Overrides:
      getPasswordAuthentication in class Authenticator
    • createAuthentication

      public static PasswordAuthentication createAuthentication()
      Returns a PasswordAuthentication instance suitable for use with PropertyAuthenticator. It reads the current values of the properties and keeps them for later.
      Returns:
      authentication
    • installInstance

      public static boolean installInstance(boolean offerAdvice)
      Installs an instance of PropertyAuthenticator so that it is used automatically in response to all 401 Unauthorized HTTP responses. The authenticator is only installed if the properties are present. If the offerAdvice parameter is true, then if the properties are not set up, an authenticator is installed which issues a message advising how to use system properties to get the authenticator working next time.
      Parameters:
      offerAdvice - if true, install an advising authenticator if the property one isn't going to work
      Returns:
      true iff an authenticator was installed; if offerAdvice is true, will always return true
      See Also: