Package org.eclipse.aether.repository
Class AuthenticationContext
- java.lang.Object
-
- org.eclipse.aether.repository.AuthenticationContext
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public final class AuthenticationContext extends java.lang.Object implements java.io.Closeable
A glorified map of key value pairs holding (cleartext) authentication data. Authentication contexts are used internally when network operations need to access secured repositories or proxies. Each authentication context manages the credentials required to access a single host. UnlikeAuthentication
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 beclosed
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
-
-
Field Summary
Fields Modifier and Type Field Description private Authentication
auth
private java.util.Map<java.lang.String,java.lang.Object>
authData
private boolean
fillingAuthData
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.private Proxy
proxy
private RemoteRepository
repository
private RepositorySystemSession
session
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.
-
Constructor Summary
Constructors Modifier Constructor Description private
AuthenticationContext(RepositorySystemSession session, RemoteRepository repository, Proxy proxy, Authentication auth)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods 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.private <T> T
convert(java.lang.Object value, java.lang.Class<T> type)
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.private static AuthenticationContext
newInstance(RepositorySystemSession session, RemoteRepository repository, Proxy proxy, Authentication auth)
void
put(java.lang.String key, java.lang.Object value)
Puts the specified authentication data into this context.
-
-
-
Field Detail
-
USERNAME
public static final java.lang.String USERNAME
The key used to store the username. The corresponding authentication data should be of typeString
.- See Also:
- Constant Field Values
-
PASSWORD
public static final java.lang.String PASSWORD
The key used to store the password. The corresponding authentication data should be of typechar[]
orString
.- See Also:
- Constant Field Values
-
NTLM_DOMAIN
public static final java.lang.String NTLM_DOMAIN
The key used to store the NTLM domain. The corresponding authentication data should be of typeString
.- See Also:
- Constant Field Values
-
NTLM_WORKSTATION
public static final java.lang.String NTLM_WORKSTATION
The key used to store the NTML workstation. The corresponding authentication data should be of typeString
.- See Also:
- Constant Field Values
-
PRIVATE_KEY_PATH
public static final java.lang.String PRIVATE_KEY_PATH
The key used to store the pathname to a private key file. The corresponding authentication data should be of typeString
orFile
.- See Also:
- Constant Field Values
-
PRIVATE_KEY_PASSPHRASE
public static final java.lang.String PRIVATE_KEY_PASSPHRASE
The key used to store the passphrase protecting the private key. The corresponding authentication data should be of typechar[]
orString
.- See Also:
- Constant Field Values
-
HOST_KEY_ACCEPTANCE
public static final java.lang.String HOST_KEY_ACCEPTANCE
The key used to store the acceptance policy for unknown host keys. The corresponding authentication data should be of typeBoolean
. When querying this authentication data, the extra data should provideHOST_KEY_REMOTE
andHOST_KEY_LOCAL
, e.g. to enable a well-founded decision of the user during an interactive prompt.- See Also:
- Constant Field Values
-
HOST_KEY_REMOTE
public static final java.lang.String HOST_KEY_REMOTE
The key used to store the fingerprint of the public key advertised by remote host. Note that this key is used to query the extra data passed toget(String, Map, Class)
when gettingHOST_KEY_ACCEPTANCE
, not the authentication data in a context.- See Also:
- Constant Field Values
-
HOST_KEY_LOCAL
public static final 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. Note that this key is used to query the extra data passed toget(String, Map, Class)
when gettingHOST_KEY_ACCEPTANCE
, not the authentication data in a context.- See Also:
- Constant Field Values
-
SSL_CONTEXT
public static final java.lang.String SSL_CONTEXT
The key used to store the SSL context. The corresponding authentication data should be of typeSSLContext
.- See Also:
- Constant Field Values
-
SSL_HOSTNAME_VERIFIER
public static final java.lang.String SSL_HOSTNAME_VERIFIER
The key used to store the SSL hostname verifier. The corresponding authentication data should be of typeHostnameVerifier
.- See Also:
- Constant Field Values
-
session
private final RepositorySystemSession session
-
repository
private final RemoteRepository repository
-
proxy
private final Proxy proxy
-
auth
private final Authentication auth
-
authData
private final java.util.Map<java.lang.String,java.lang.Object> authData
-
fillingAuthData
private boolean fillingAuthData
-
-
Constructor Detail
-
AuthenticationContext
private AuthenticationContext(RepositorySystemSession session, RemoteRepository repository, Proxy proxy, Authentication auth)
-
-
Method Detail
-
forRepository
public static AuthenticationContext forRepository(RepositorySystemSession session, RemoteRepository repository)
Gets an authentication context for the specified repository.- Parameters:
session
- The repository system session during which the repository is accessed, must not benull
.repository
- The repository for which to create an authentication context, must not benull
.- Returns:
- An authentication context for the repository or
null
if no authentication is configured for it.
-
forProxy
public static AuthenticationContext forProxy(RepositorySystemSession session, RemoteRepository repository)
Gets an authentication context for the proxy of the specified repository.- Parameters:
session
- The repository system session during which the repository is accessed, must not benull
.repository
- The repository for whose proxy to create an authentication context, must not benull
.- Returns:
- An authentication context for the proxy or
null
if no proxy is set or no authentication is configured for it.
-
newInstance
private static AuthenticationContext newInstance(RepositorySystemSession session, RemoteRepository repository, Proxy proxy, Authentication auth)
-
getSession
public RepositorySystemSession getSession()
Gets the repository system session during which the authentication happens.- Returns:
- The repository system session, never
null
.
-
getRepository
public RemoteRepository getRepository()
Gets the repository requiring authentication. IfgetProxy()
is notnull
, the data gathered by this authentication context does not apply to the repository's host but rather the proxy.- Returns:
- The repository to be contacted, never
null
.
-
getProxy
public Proxy getProxy()
Gets the proxy (if any) to be authenticated with.- Returns:
- The proxy or
null
if authenticating directly with the repository's host.
-
get
public java.lang.String get(java.lang.String key)
Gets the authentication data for the specified key.- Parameters:
key
- The key whose authentication data should be retrieved, must not benull
.- Returns:
- The requested authentication data or
null
if none.
-
get
public <T> T get(java.lang.String key, java.lang.Class<T> type)
Gets the authentication data for the specified key.- Type Parameters:
T
- The data type of the authentication data.- Parameters:
key
- The key whose authentication data should be retrieved, must not benull
.type
- The expected type of the authentication data, must not benull
.- Returns:
- The requested authentication data or
null
if none or if the data doesn't match the expected type.
-
get
public <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.- Type Parameters:
T
- The data type of the authentication data.- Parameters:
key
- The key whose authentication data should be retrieved, must not benull
.data
- Any (read-only) extra data in form of key value pairs that might be useful when getting the authentication data, may benull
.type
- The expected type of the authentication data, must not benull
.- Returns:
- The requested authentication data or
null
if none or if the data doesn't match the expected type.
-
convert
private <T> T convert(java.lang.Object value, java.lang.Class<T> type)
-
put
public void put(java.lang.String key, java.lang.Object value)
Puts the specified authentication data into this context. This method should only be called from implementors ofAuthentication.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.- Parameters:
key
- The key to associate the authentication data with, must not benull
.value
- The (cleartext) authentication data to store, may benull
.
-
close
public void close()
Closes this authentication context and erases sensitive authentication data from heap memory. Closing an already closed context has no effect.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
close
public static void close(AuthenticationContext context)
Closes the specified authentication context. This is a convenience method doing anull
check before callingclose()
on the given context.- Parameters:
context
- The authentication context to close, may benull
.
-
-