Package uk.ac.starlink.util
Class PropertyAuthenticator
- java.lang.Object
-
- java.net.Authenticator
-
- uk.ac.starlink.util.PropertyAuthenticator
-
public class PropertyAuthenticator extends java.net.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 methodinstallInstance(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 Summary
Fields Modifier and Type Field Description static java.lang.String
PASSWORD_PROP
System property supplying basic authentication password ("star.basicauth.password").static java.lang.String
USER_PROP
System property supplying basic authentication username ("star.basicauth.user").
-
Constructor Summary
Constructors Constructor Description PropertyAuthenticator()
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.net.PasswordAuthentication
createAuthentication()
Returns a PasswordAuthentication instance suitable for use with PropertyAuthenticator.java.net.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 java.net.Authenticator
getDefault, getRequestingHost, getRequestingPort, getRequestingPrompt, getRequestingProtocol, getRequestingScheme, getRequestingSite, getRequestingURL, getRequestorType, requestPasswordAuthentication, requestPasswordAuthentication, requestPasswordAuthentication, requestPasswordAuthentication, requestPasswordAuthenticationInstance, setDefault
-
-
-
-
Field Detail
-
USER_PROP
public static final java.lang.String USER_PROP
System property supplying basic authentication username ("star.basicauth.user").- See Also:
- Constant Field Values
-
PASSWORD_PROP
public static final java.lang.String PASSWORD_PROP
System property supplying basic authentication password ("star.basicauth.password").- See Also:
- Constant Field Values
-
-
Method Detail
-
getPasswordAuthentication
public java.net.PasswordAuthentication getPasswordAuthentication()
- Overrides:
getPasswordAuthentication
in classjava.net.Authenticator
-
createAuthentication
public static java.net.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 theofferAdvice
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(java.net.Authenticator)
-
-