public class RedisAuthenticationHandler<K,V> extends Object
Constructor and Description |
---|
RedisAuthenticationHandler(StatefulRedisConnectionImpl<K,V> connection,
RedisCredentialsProvider credentialsProvider,
Boolean isPubSubConnection)
Creates a new
RedisAuthenticationHandler . |
Modifier and Type | Method and Description |
---|---|
protected void |
complete() |
static <K,V> RedisAuthenticationHandler<K,V> |
createDefaultAuthenticationHandler()
Creates a new default
RedisAuthenticationHandler . |
static <K,V> RedisAuthenticationHandler<K,V> |
createHandler(StatefulRedisConnectionImpl<K,V> connection,
RedisCredentialsProvider credentialsProvider,
Boolean isPubSubConnection,
ClientOptions options)
Creates a new
RedisAuthenticationHandler if the connection supports re-authentication. |
protected void |
dispatchAuth(RedisCredentials credentials) |
void |
endTransaction()
Marks that the current connection has ended the transaction.
|
protected void |
onError(Throwable e) |
protected void |
onNext(RedisCredentials credentials) |
protected void |
postProcess(Collection<? extends RedisCommand<K,V,?>> dispatched)
Post-processes a collection of dispatched commands after they are sent to the server.
|
protected void |
postProcess(RedisCommand<K,V,?> toSend)
Post-processes the command after it is sent to the server.
|
protected void |
reauthenticate(RedisCredentials credentials)
Performs re-authentication with the provided credentials.
|
void |
setCredentials(RedisCredentials credentials)
Authenticates the current connection using the provided credentials.
|
void |
startTransaction()
Marks that the current connection has started a transaction.
|
void |
subscribe()
This method subscribes to a stream of credentials provided by the `StreamingCredentialsProvider`.
|
void |
unsubscribe()
Unsubscribes from the current credentials stream.
|
public RedisAuthenticationHandler(StatefulRedisConnectionImpl<K,V> connection, RedisCredentialsProvider credentialsProvider, Boolean isPubSubConnection)
RedisAuthenticationHandler
.connection
- the connection to authenticatecredentialsProvider
- the implementation of RedisCredentialsProvider
to useisPubSubConnection
- true
if the connection is a pub/sub connectionpublic static <K,V> RedisAuthenticationHandler<K,V> createHandler(StatefulRedisConnectionImpl<K,V> connection, RedisCredentialsProvider credentialsProvider, Boolean isPubSubConnection, ClientOptions options)
RedisAuthenticationHandler
if the connection supports re-authentication.connection
- the connection to authenticatecredentialsProvider
- the implementation of RedisCredentialsProvider
to useisPubSubConnection
- true
if the connection is a pub/sub connectionoptions
- the ClientOptions
to useRedisAuthenticationHandler
if the connection supports re-authentication, otherwise an
implementation of the RedisAuthenticationHandler
that does nothingRedisCredentialsProvider
public static <K,V> RedisAuthenticationHandler<K,V> createDefaultAuthenticationHandler()
RedisAuthenticationHandler
.
The default RedisAuthenticationHandler
is used when re-authentication is not supported.RedisAuthenticationHandler
RedisCredentialsProvider
public void subscribe()
Each time new credentials are received, the client is re-authenticated. The previous subscription, if any, is disposed of before setting the new subscription.
public void unsubscribe()
protected void complete()
protected void onNext(RedisCredentials credentials)
protected void onError(Throwable e)
protected void reauthenticate(RedisCredentials credentials)
credentials
- the new credentialsprotected void postProcess(RedisCommand<K,V,?> toSend)
If the command type is either RedisCommand.Type#EXEC
or RedisCommand.Type#DISCARD
, the transaction state
is cleared and a check for deferred credentials is initiated.
toSend
- the command to post-processprotected void postProcess(Collection<? extends RedisCommand<K,V,?>> dispatched)
This method checks if any of the dispatched commands indicate the completion of a transaction (via
RedisCommand.Type#EXEC
or RedisCommand.Type#DISCARD
). If the transaction is complete, it clears the
transaction state and initiates a check for deferred credentials.
dispatched
- the collection of dispatched commands to post-processpublic void startTransaction()
During transactions, any re-authentication attempts are deferred until the transaction ends.
public void endTransaction()
After a transaction is completed, any deferred re-authentication attempts are dispatched.
public void setCredentials(RedisCredentials credentials)
Unlike using dispatch of RedisAsyncCommands.auth(java.lang.CharSequence)
, this method defers the AUTH
command if the connection
is within an active transaction. The authentication command will only be dispatched after the enclosing DISCARD
or EXEC
command is executed, ensuring that authentication does not interfere with ongoing transactions.
credentials
- the RedisCredentials
to authenticate the connection. If null
, no action is performed.
Behavior:
null
, the method exits immediately.inTransaction
), the AUTH
command is not dispatched
immediately but deferred until the transaction ends.AUTH
command is dispatched immediately using the provided
credentials.RedisAsyncCommands.auth(java.lang.CharSequence)
protected void dispatchAuth(RedisCredentials credentials)
Copyright © 2025 lettuce.io. All rights reserved.