@ThreadSafe public class ProgrammaticPlainTextAuthProvider extends PlainTextAuthProviderBase
AuthProvider that 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.
PlainTextAuthProviderBase.Credentials, PlainTextAuthProviderBase.PlainTextAuthenticator| Constructor and 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.
|
| Modifier and Type | Method and Description |
|---|---|
protected PlainTextAuthProviderBase.Credentials |
getCredentials(EndPoint endPoint,
String serverAuthenticator)
Retrieves the credentials from the underlying source.
|
void |
setAuthorizationId(String authorizationId)
Changes the authorization id.
|
void |
setPassword(String password)
Changes the password.
|
void |
setUsername(String username)
Changes the username.
|
close, newAuthenticator, onMissingChallengepublic ProgrammaticPlainTextAuthProvider(@NonNull
String username,
@NonNull
String password)
public ProgrammaticPlainTextAuthProvider(@NonNull
String username,
@NonNull
String password,
@NonNull
String 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.
public void setUsername(@NonNull
String username)
The new credentials will be used for all connections initiated after this method was called.
username - the new name.public void setPassword(@NonNull
String password)
The new credentials will be used for all connections initiated after this method was called.
password - the new password.public void setAuthorizationId(@NonNull
String authorizationId)
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.
authorizationId - the new authorization id.@NonNull protected PlainTextAuthProviderBase.Credentials getCredentials(@NonNull EndPoint endPoint, @NonNull String serverAuthenticator)
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.
getCredentials in class PlainTextAuthProviderBaseendPoint - The endpoint being contacted.serverAuthenticator - The authenticator class sent by the endpoint.Copyright © 2017–2025. All rights reserved.