Class ProgrammaticPlainTextAuthProvider
- java.lang.Object
-
- com.datastax.oss.driver.api.core.auth.PlainTextAuthProviderBase
-
- com.datastax.oss.driver.api.core.auth.ProgrammaticPlainTextAuthProvider
-
- All Implemented Interfaces:
AuthProvider,AutoCloseable
@ThreadSafe public class ProgrammaticPlainTextAuthProvider extends PlainTextAuthProviderBase
A simple plaintextAuthProviderthat receives the credentials programmatically instead of pulling them from the configuration.To use this class, create an instance with the appropriate credentials to use and pass it to your session builder:
AuthProvider authProvider = new ProgrammaticPlainTextAuthProvider("...", "..."); CqlSession session = CqlSession.builder() .addContactEndPoints(...) .withAuthProvider(authProvider) .build();It also offers the possibility of changing the credentials at runtime. The new credentials will be used for all connections initiated after the change.
Implementation Note: this implementation is not particularly suited for highly-sensitive applications: it stores the credentials to use as private fields, and even if the fields are char arrays rather than strings to make it difficult to dump their contents, they are never cleared until the provider itself is garbage-collected, which typically only happens when the session is closed.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.datastax.oss.driver.api.core.auth.PlainTextAuthProviderBase
PlainTextAuthProviderBase.Credentials, PlainTextAuthProviderBase.PlainTextAuthenticator
-
-
Constructor Summary
Constructors Constructor Description ProgrammaticPlainTextAuthProvider(String username, String password)Builds an instance for simple username/password authentication.ProgrammaticPlainTextAuthProvider(String username, String password, String authorizationId)Builds an instance for username/password authentication, and proxy authentication with the given authorizationId.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected PlainTextAuthProviderBase.CredentialsgetCredentials(EndPoint endPoint, String serverAuthenticator)Retrieves the credentials from the underlying source.voidsetAuthorizationId(String authorizationId)Changes the authorization id.voidsetPassword(String password)Changes the password.voidsetUsername(String username)Changes the username.-
Methods inherited from class com.datastax.oss.driver.api.core.auth.PlainTextAuthProviderBase
close, newAuthenticator, onMissingChallenge
-
-
-
-
Constructor Detail
-
ProgrammaticPlainTextAuthProvider
public ProgrammaticPlainTextAuthProvider(@NonNull String username, @NonNull String password)Builds an instance for simple username/password authentication.
-
ProgrammaticPlainTextAuthProvider
public ProgrammaticPlainTextAuthProvider(@NonNull String username, @NonNull String password, @NonNull String authorizationId)Builds an instance for username/password authentication, and proxy authentication with the given authorizationId.This feature is only available with DataStax Enterprise. If the target server is Apache Cassandra, use
ProgrammaticPlainTextAuthProvider(String, String)instead, or set the authorizationId to an empty string.
-
-
Method Detail
-
setUsername
public void setUsername(@NonNull String username)Changes the username.The new credentials will be used for all connections initiated after this method was called.
- Parameters:
username- the new name.
-
setPassword
public void setPassword(@NonNull String password)Changes the password.The new credentials will be used for all connections initiated after this method was called.
- Parameters:
password- the new password.
-
setAuthorizationId
public void setAuthorizationId(@NonNull String authorizationId)Changes the authorization id.The new credentials will be used for all connections initiated after this method was called.
This feature is only available with DataStax Enterprise. If the target server is Apache Cassandra, this method should not be used.
- Parameters:
authorizationId- the new authorization id.
-
getCredentials
@NonNull protected PlainTextAuthProviderBase.Credentials getCredentials(@NonNull EndPoint endPoint, @NonNull String serverAuthenticator)
Retrieves the credentials from the underlying source.This is invoked every time the driver opens a new connection.
This implementation disregards the endpoint being connected to as well as the authenticator class sent by the server, and always returns the same credentials.
- Specified by:
getCredentialsin classPlainTextAuthProviderBase- Parameters:
endPoint- The endpoint being contacted.serverAuthenticator- The authenticator class sent by the endpoint.
-
-