Package org.eclipse.aether.repository
Class AuthenticationContext
java.lang.Object
org.eclipse.aether.repository.AuthenticationContext
- All Implemented Interfaces:
- Closeable,- AutoCloseable
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. Unlike 
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
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringThe key used to store the acceptance policy for unknown host keys.static final StringThe key used to store the fingerprint of the public key expected from remote host as recorded in a known hosts database.static final StringThe key used to store the fingerprint of the public key advertised by remote host.static final StringThe key used to store the NTLM domain.static final StringThe key used to store the NTML workstation.static final StringThe key used to store the password.static final StringThe key used to store the passphrase protecting the private key.static final StringThe key used to store the pathname to a private key file.static final StringThe key used to store the SSL context.static final StringThe key used to store the SSL hostname verifier.static final StringThe key used to store the username.
- 
Method SummaryModifier and TypeMethodDescriptionvoidclose()Closes this authentication context and erases sensitive authentication data from heap memory.static voidclose(AuthenticationContext context) Closes the specified authentication context.static AuthenticationContextforProxy(RepositorySystemSession session, RemoteRepository repository) Gets an authentication context for the proxy of the specified repository.static AuthenticationContextforRepository(RepositorySystemSession session, RemoteRepository repository) Gets an authentication context for the specified repository.Gets the authentication data for the specified key.<T> TGets the authentication data for the specified key.<T> TGets the authentication data for the specified key.getProxy()Gets the proxy (if any) to be authenticated with.Gets the repository requiring authentication.Gets the repository system session during which the authentication happens (if within session).voidPuts the specified authentication data into this context.
- 
Field Details- 
USERNAMEThe key used to store the username. The corresponding authentication data should be of typeString.- See Also:
 
- 
PASSWORDThe key used to store the password. The corresponding authentication data should be of typechar[]orString.- See Also:
 
- 
NTLM_DOMAINThe key used to store the NTLM domain. The corresponding authentication data should be of typeString.- See Also:
 
- 
NTLM_WORKSTATIONThe key used to store the NTML workstation. The corresponding authentication data should be of typeString.- See Also:
 
- 
PRIVATE_KEY_PATHThe key used to store the pathname to a private key file. The corresponding authentication data should be of typeStringorFile.- See Also:
 
- 
PRIVATE_KEY_PASSPHRASEThe key used to store the passphrase protecting the private key. The corresponding authentication data should be of typechar[]orString.- See Also:
 
- 
HOST_KEY_ACCEPTANCEThe 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_REMOTEandHOST_KEY_LOCAL, e.g. to enable a well-founded decision of the user during an interactive prompt.- See Also:
 
- 
HOST_KEY_REMOTEThe 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:
 
- 
HOST_KEY_LOCALThe 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:
 
- 
SSL_CONTEXTThe key used to store the SSL context. The corresponding authentication data should be of typeSSLContext.- See Also:
 
- 
SSL_HOSTNAME_VERIFIERThe key used to store the SSL hostname verifier. The corresponding authentication data should be of typeHostnameVerifier.- See Also:
 
 
- 
- 
Method Details- 
forRepositorypublic 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, may be- null.
- repository- The repository for which to create an authentication context, must not be- null.
- Returns:
- An authentication context for the repository or nullif no authentication is configured for it.
 
- 
forProxypublic 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, may be- null.
- repository- The repository for whose proxy to create an authentication context, must not be- null.
- Returns:
- An authentication context for the proxy or nullif no proxy is set or no authentication is configured for it.
 
- 
getSessionGets the repository system session during which the authentication happens (if within session).- Returns:
- The repository system session, may be nullif context is created outside of session.
 
- 
getRepositoryGets 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.
 
- 
getProxyGets the proxy (if any) to be authenticated with.- Returns:
- The proxy or nullif authenticating directly with the repository's host.
 
- 
getGets the authentication data for the specified key.- Parameters:
- key- The key whose authentication data should be retrieved, must not be- null.
- Returns:
- The requested authentication data or nullif none.
 
- 
getGets 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 be- null.
- type- The expected type of the authentication data, must not be- null.
- Returns:
- The requested authentication data or nullif none or if the data doesn't match the expected type.
 
- 
getGets 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 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.
- Returns:
- The requested authentication data or nullif none or if the data doesn't match the expected type.
 
- 
putPuts 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 be- null.
- value- The (cleartext) authentication data to store, may be- null.
 
- 
closeCloses this authentication context and erases sensitive authentication data from heap memory. Closing an already closed context has no effect.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
 
- 
closeCloses the specified authentication context. This is a convenience method doing anullcheck before callingclose()on the given context.- Parameters:
- context- The authentication context to close, may be- null.
 
 
-