Update AuthToken rotation to support more auth types #1481
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This update extends the
AuthToken
rotation beyond supporting just the expiring (bearer) tokens to a more flexible solution that allows supporting various auth types.An important part of the
AuthToken
rotation support is retryability, which is either managed automatically by the driver via the Managed Transaction API (Session.executeRead(TransactionCallback)
,Session.executeWrite(TransactionCallback)
, etc.) or explicitly by the user. The rotation support relies on the existing retry approach used for the other retryable conditions. If a given unit of work fails due to credentials rejection by the server and theAuthTokenManager
is able to supply valid credentials, the failure must be marked as retryable to indicate that the given unit of work is worth retrying. The driver provides theRetryableException
marker interface for that.However, the credentials rejection server security error depends on auth type used. Therefore, it was decided that the
AuthTokenManager
implementations should have access to the security error details and should make a decision on whether such error should be considered as retryable or not. To achieve this, theAuthTokenManager.onExpired(AuthToken)
method is replaced with a newAuthTokenManager.handleSecurityException(AuthToken authToken, SecurityException exception)
method that returns aboolean
value to determine if the error is retryable.By default, the
SecurityException
and its subclasses are not retryable. If an error is determined to be retryable by theAuthTokenManager
, then the driver wraps the current error into a newSecurityRetryableException
. The latter is a subclass of theSecurityException
and is also aRetryableException
. It contains the original exception as a cause and transparently proxies calls of both theSecurityRetryableException.code()
andSecurityRetryableException.getMessage()
methods to the original exception. TheSecurityRetryableException
has been introduced to allow markingSecurityException
and its subclasses as retryable and is not currently meant to fork a separate class hierarchy as a single class is sufficient for this purpose at this point. Following these updates, theTokenExpiredRetryableException
has been deleted as no longer needed.The
AuthTokenManagers.expirationBased(Supplier<AuthTokenAndExpiration>)
andAuthTokenManagers.expirationBasedAsync(Supplier<CompletionStage<AuthTokenAndExpiration>>)
methods have been replaced withAuthTokenManagers.bearer(Supplier<AuthTokenAndExpiration>)
andAuthTokenManagers.bearerAsync(Supplier<CompletionStage<AuthTokenAndExpiration>>)
methods respectively. The new medhods are tailored for the bearer token auth support specifically. In addition, 2 new methods have been introduced for the basic (type)AuthToken
rotation support:AuthTokenManagers.basic(Supplier<AuthToken>)
andAuthTokenManagers.basicAsync(Supplier<CompletionStage<AuthToken>>)
.The code inspection profile has been updated to enable the
SerializableHasSerialVersionUIDField
warning.