java.io.Closeable, java.lang.AutoCloseablepublic final class AuthenticationContext extends java.lang.Object implements java.io.Closeable
Authentication callbacks which exist for a
potentially long time like the duration of a repository system session, an authentication context has a supposedly
short lifetime and should be closed as soon as the corresponding network operation has finished:
AuthenticationContext context = AuthenticationContext.forRepository( session, repository );
try {
// get credentials
char[] password = context.get( AuthenticationContext.PASSWORD, char[].class );
// perform network operation using retrieved credentials
...
} finally {
// erase confidential authentication data from heap memory
AuthenticationContext.close( context );
}
The same authentication data can often be presented using different data types, e.g. a password can be presented
using a character array or (less securely) using a string. For ease of use, an authentication context treats the
following groups of data types as equivalent and converts values automatically during retrieval:
String, char[]String, File| Modifier and Type | Field | Description |
|---|---|---|
static java.lang.String |
HOST_KEY_ACCEPTANCE |
The key used to store the acceptance policy for unknown host keys.
|
static java.lang.String |
HOST_KEY_LOCAL |
The key used to store the fingerprint of the public key expected from remote host as recorded in a known hosts
database.
|
static java.lang.String |
HOST_KEY_REMOTE |
The key used to store the fingerprint of the public key advertised by remote host.
|
static java.lang.String |
NTLM_DOMAIN |
The key used to store the NTLM domain.
|
static java.lang.String |
NTLM_WORKSTATION |
The key used to store the NTML workstation.
|
static java.lang.String |
PASSWORD |
The key used to store the password.
|
static java.lang.String |
PRIVATE_KEY_PASSPHRASE |
The key used to store the passphrase protecting the private key.
|
static java.lang.String |
PRIVATE_KEY_PATH |
The key used to store the pathname to a private key file.
|
static java.lang.String |
SSL_CONTEXT |
The key used to store the SSL context.
|
static java.lang.String |
SSL_HOSTNAME_VERIFIER |
The key used to store the SSL hostname verifier.
|
static java.lang.String |
USERNAME |
The key used to store the username.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
Closes this authentication context and erases sensitive authentication data from heap memory.
|
static void |
close(AuthenticationContext context) |
Closes the specified authentication context.
|
static AuthenticationContext |
forProxy(RepositorySystemSession session,
RemoteRepository repository) |
Gets an authentication context for the proxy of the specified repository.
|
static AuthenticationContext |
forRepository(RepositorySystemSession session,
RemoteRepository repository) |
Gets an authentication context for the specified repository.
|
java.lang.String |
get(java.lang.String key) |
Gets the authentication data for the specified key.
|
<T> T |
get(java.lang.String key,
java.lang.Class<T> type) |
Gets the authentication data for the specified key.
|
<T> T |
get(java.lang.String key,
java.util.Map<java.lang.String,java.lang.String> data,
java.lang.Class<T> type) |
Gets the authentication data for the specified key.
|
Proxy |
getProxy() |
Gets the proxy (if any) to be authenticated with.
|
RemoteRepository |
getRepository() |
Gets the repository requiring authentication.
|
RepositorySystemSession |
getSession() |
Gets the repository system session during which the authentication happens.
|
void |
put(java.lang.String key,
java.lang.Object value) |
Puts the specified authentication data into this context.
|
public static final java.lang.String USERNAME
String.public static final java.lang.String PASSWORD
char[] or
String.public static final java.lang.String NTLM_DOMAIN
String.public static final java.lang.String NTLM_WORKSTATION
String.public static final java.lang.String PRIVATE_KEY_PATH
String or File.public static final java.lang.String PRIVATE_KEY_PASSPHRASE
char[] or String.public static final java.lang.String HOST_KEY_ACCEPTANCE
Boolean. When querying this authentication data, the extra data should provide
HOST_KEY_REMOTE and HOST_KEY_LOCAL, e.g. to enable a well-founded decision of the user during
an interactive prompt.public static final java.lang.String HOST_KEY_REMOTE
get(String, Map, Class) when getting HOST_KEY_ACCEPTANCE, not
the authentication data in a context.public static final java.lang.String HOST_KEY_LOCAL
get(String, Map, Class) when
getting HOST_KEY_ACCEPTANCE, not the authentication data in a context.public static final java.lang.String SSL_CONTEXT
SSLContext.public static final java.lang.String SSL_HOSTNAME_VERIFIER
HostnameVerifier.public static AuthenticationContext forRepository(RepositorySystemSession session, RemoteRepository repository)
session - The repository system session during which the repository is accessed, must not be null.repository - The repository for which to create an authentication context, must not be null.null if no authentication is configured for it.public static AuthenticationContext forProxy(RepositorySystemSession session, RemoteRepository repository)
session - The repository system session during which the repository is accessed, must not be null.repository - The repository for whose proxy to create an authentication context, must not be null.null if no proxy is set or no authentication is
configured for it.public RepositorySystemSession getSession()
null.public RemoteRepository getRepository()
getProxy() is not null, the data gathered by
this authentication context does not apply to the repository's host but rather the proxy.null.public Proxy getProxy()
null if authenticating directly with the repository's host.public java.lang.String get(java.lang.String key)
key - The key whose authentication data should be retrieved, must not be null.null if none.public <T> T get(java.lang.String key, java.lang.Class<T> type)
T - The data type of the authentication data.key - The key whose authentication data should be retrieved, must not be null.type - The expected type of the authentication data, must not be null.null if none or if the data doesn't match the expected type.public <T> T get(java.lang.String key, java.util.Map<java.lang.String,java.lang.String> data, java.lang.Class<T> type)
T - The data type of the authentication data.key - The key whose authentication data should be retrieved, must not be null.data - Any (read-only) extra data in form of key value pairs that might be useful when getting the
authentication data, may be null.type - The expected type of the authentication data, must not be null.null if none or if the data doesn't match the expected type.public void put(java.lang.String key, java.lang.Object value)
Authentication.fill(AuthenticationContext, String, Map). Passed in character arrays are not cloned and
become owned by this context, i.e. get erased when the context gets closed.key - The key to associate the authentication data with, must not be null.value - The (cleartext) authentication data to store, may be null.public void close()
close in interface java.lang.AutoCloseableclose in interface java.io.Closeablepublic static void close(AuthenticationContext context)
null check before
calling close() on the given context.context - The authentication context to close, may be null.