public class CustomAuthenticator extends Authenticator
Authenticator
that can be installed into the running JVM by calling Authenticator.setDefault(Authenticator)
.Modifier and Type | Class and Description |
---|---|
static class |
CustomAuthenticator.CacheMode
Whether user names, user names and passwords, or none of both are remembered while the JVM is running.
|
static class |
CustomAuthenticator.CredentialsSpec
A pattern that is intended to be matched against the properties of an
Authenticator . |
static class |
CustomAuthenticator.StoreMode
Whether user names, user names and passwords, or none of both are persistently stored.
|
Authenticator.RequestorType
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_DIALOG_LABEL
The dialog label to take effect iff no custom label is configured through
setDialogLabel(String) . |
Constructor and Description |
---|
CustomAuthenticator(CustomAuthenticator.CacheMode cacheMode,
CustomAuthenticator.StoreMode storeMode) |
Modifier and Type | Method and Description |
---|---|
void |
addCredentials(Collection<CustomAuthenticator.CredentialsSpec> credentials)
Adds a set of
CustomAuthenticator.CredentialsSpec s to this CustomAuthenticator . |
protected PasswordAuthentication |
getPasswordAuthentication() |
void |
setDialogLabel(String message)
The text of the label in the authentication dialog, in
MessageFormat format. |
getRequestingHost, getRequestingPort, getRequestingPrompt, getRequestingProtocol, getRequestingScheme, getRequestingSite, getRequestingURL, getRequestorType, requestPasswordAuthentication, requestPasswordAuthentication, requestPasswordAuthentication, setDefault
public static final String DEFAULT_DIALOG_LABEL
setDialogLabel(String)
.public CustomAuthenticator(CustomAuthenticator.CacheMode cacheMode, CustomAuthenticator.StoreMode storeMode)
cacheMode
- Whether user names, user names and passwords, or none of both are remembered while the JVM
is runningstoreMode
- Whether user names, user names and passwords, or none of both are persistently storedpublic void setDialogLabel(String message)
MessageFormat
format.
The following arguments are replaced within the message:
/
requesting-protocol/
requesting-host/
requesting-port/
requesting-scheme/
Example value: "PROXY/http/proxy.company.com/8080/Negotiate"
Authenticator.getRequestingHost()
Authenticator.getRequestingSite()
Authenticator.getRequestingPort()
Authenticator.getRequestingProtocol()
Authenticator.getRequestingPrompt()
Authenticator.getRequestingScheme()
Authenticator.getRequestingURL()
Authenticator.getRequestorType()
* Where the above list presents two placeholders, they expand as follows:
null
or ""
or -1
, the two placeholders expand to "0"
and ""
.
"1"
and the value.
The default value is
<html> <table> {1, choice, 0#|1#'<tr><td>Host: </td><td>'{2}'</td></tr>'} {3, choice, 0#|1#'<tr><td>Site: </td><td>'{4}'</td></tr>'} {5, choice, 0#|1#'<tr><td>Port: </td><td>'{6}'</td></tr>'} {7, choice, 0#|1#'<tr><td>Protocol:</td><td>'{8}'</td></tr>'} {9, choice, 0#|1#'<tr><td>Prompt: </td><td>'{10}'</td></tr>'} {11, choice, 0#|1#'<tr><td>Scheme: </td><td>'{12}'</td></tr>'} {13, choice, 0#|1#'<tr><td>URL: </td><td>'{14}'</td></tr>'} {15, choice, 0#|1#'<tr><td>Type: </td><td>'{16}'</td></tr>'} </table> </html>
public void addCredentials(Collection<CustomAuthenticator.CredentialsSpec> credentials)
CustomAuthenticator.CredentialsSpec
s to this CustomAuthenticator
. Earlier specs take precedence over
later specs.
Specs that equal any previously added spec are ignored, because they are irrelevant.
If no specs are added, then the CustomAuthenticator
will prompt the user for user name and/or
password, and optionally cache the entered data (transiently and/or persistently, depending on the
configured cache mode and store mode).
@Nullable protected PasswordAuthentication getPasswordAuthentication()
getPasswordAuthentication
in class Authenticator
Copyright © 2018 Arno Unkrig. All rights reserved.