# 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

## Nested Class Summary

### Nested classes/interfaces inherited from class Authenticator

`Authenticator.RequestorType`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`PASSWORD_PROP`
System property supplying basic authentication password ("star.basicauth.password").
`static final String`
`USER_PROP`
System property supplying basic authentication username ("star.basicauth.user").

## Constructor Summary

Constructors
Constructor
Description
`PropertyAuthenticator()`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`static PasswordAuthentication`
`createAuthentication()`
Returns a PasswordAuthentication instance suitable for use with PropertyAuthenticator.
`PasswordAuthentication`
`getPasswordAuthentication()`
`static boolean`
`installInstance(boolean offerAdvice)`
Installs an instance of PropertyAuthenticator so that it is used automatically in response to all 401 Unauthorized HTTP responses.

### Methods inherited from class Authenticator

`getDefault, getRequestingHost, getRequestingPort, getRequestingPrompt, getRequestingProtocol, getRequestingScheme, getRequestingSite, getRequestingURL, getRequestorType, requestPasswordAuthentication, requestPasswordAuthentication, requestPasswordAuthentication, requestPasswordAuthentication, requestPasswordAuthenticationInstance, setDefault`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### USER_PROP

public static final String USER_PROP
System property supplying basic authentication username ("star.basicauth.user").

See Also:
  - Constant Field Values

### PASSWORD_PROP

public static final String PASSWORD_PROP
System property supplying basic authentication password ("star.basicauth.password").

See Also:
  - Constant Field Values

## 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:
  - `Authenticator.setDefault(Authenticator)`