Class PlainTextAuthProviderBase
- java.lang.Object
-
- com.datastax.oss.driver.api.core.auth.PlainTextAuthProviderBase
-
- All Implemented Interfaces:
AuthProvider,AutoCloseable
- Direct Known Subclasses:
DsePlainTextAuthProviderBase,ProgrammaticPlainTextAuthProvider
@ThreadSafe public abstract class PlainTextAuthProviderBase extends Object implements AuthProvider
Common infrastructure for plain text auth providers.This can be reused to write an implementation that retrieves the credentials from another source than the configuration. The driver offers one built-in implementation:
ProgrammaticPlainTextAuthProvider.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPlainTextAuthProviderBase.Credentialsprotected static classPlainTextAuthProviderBase.PlainTextAuthenticator
-
Constructor Summary
Constructors Modifier Constructor Description protectedPlainTextAuthProviderBase(String logPrefix)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()protected abstract PlainTextAuthProviderBase.CredentialsgetCredentials(EndPoint endPoint, String serverAuthenticator)Retrieves the credentials from the underlying source.AuthenticatornewAuthenticator(EndPoint endPoint, String serverAuthenticator)The authenticator to use when connecting tohost.voidonMissingChallenge(EndPoint endPoint)What to do if the server does not send back an authentication challenge (in other words, lets the client connect without any form of authentication).
-
-
-
Constructor Detail
-
PlainTextAuthProviderBase
protected PlainTextAuthProviderBase(@NonNull String logPrefix)- Parameters:
logPrefix- a string that will get prepended to the logs (this is used for discrimination when you have multiple driver instances executing in the same JVM). Built-in implementations fill this withSession.getName().
-
-
Method Detail
-
getCredentials
@NonNull protected abstract 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.
- Parameters:
endPoint- The endpoint being contacted.serverAuthenticator- The authenticator class sent by the endpoint.
-
newAuthenticator
@NonNull public Authenticator newAuthenticator(@NonNull EndPoint endPoint, @NonNull String serverAuthenticator) throws AuthenticationException
Description copied from interface:AuthProviderThe authenticator to use when connecting tohost.- Specified by:
newAuthenticatorin interfaceAuthProvider- Parameters:
endPoint- the Cassandra host to connect to.serverAuthenticator- the configured authenticator on the host.- Returns:
- the authentication implementation to use.
- Throws:
AuthenticationException
-
onMissingChallenge
public void onMissingChallenge(@NonNull EndPoint endPoint)Description copied from interface:AuthProviderWhat to do if the server does not send back an authentication challenge (in other words, lets the client connect without any form of authentication).This is suspicious because having authentication enabled on the client but not on the server is probably a configuration mistake.
Provider implementations are free to handle this however they want; typical approaches are:
- ignoring;
- logging a warning;
- throwing an
AuthenticationExceptionto abort the connection (but note that it will be retried according to theReconnectionPolicy).
- Specified by:
onMissingChallengein interfaceAuthProvider
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable
-
-