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)Deprecated.Only an empty authorization ID is supported for ordinary authentication.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected PlainTextAuthProviderBase.CredentialsgetCredentials(EndPoint endPoint, String serverAuthenticator)Retrieves the credentials from the underlying source.voidsetAuthorizationId(String authorizationId)Deprecated.Only an empty authorization ID is supported for ordinary authentication.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
@Deprecated public ProgrammaticPlainTextAuthProvider(@NonNull String username, @NonNull String password, @NonNull String authorizationId)
Deprecated.Only an empty authorization ID is supported for ordinary authentication.
-
-
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
@Deprecated public void setAuthorizationId(@NonNull String authorizationId)
Deprecated.Only an empty authorization ID is supported for ordinary authentication.
-
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.
-
-