T
- the type of token (usually specified by the subclass)public abstract class RefreshProtectedCredentialsProvider<T> extends Object implements CredentialsProvider
CredentialsProvider
that does not let token refresh happen concurrently.
A token is usually long-lived (several minutes or more), can be re-used inside the same application,
and refreshing it is a costly operation. This base class lets a first call to refresh()
pass and block concurrent calls until the first call is over. Concurrent calls are then unblocked and
can benefit from the refresh. This avoids unnecessary refresh operations to happen if a token
is already being renewed.
Subclasses need to provide the actual token retrieval (whether is a first retrieval or a renewal is a implementation detail) and how to extract information (username, password, time before expiration) from the retrieved token.
Constructor and Description |
---|
RefreshProtectedCredentialsProvider() |
Modifier and Type | Method and Description |
---|---|
String |
getPassword()
Password/secret/token to use for authentication
|
Duration |
getTimeBeforeExpiration()
The time before the credentials expire, if they do expire.
|
String |
getUsername()
Username to use for authentication
|
protected abstract String |
passwordFromToken(T token) |
void |
refresh()
Instructs the provider to refresh or renew credentials.
|
protected abstract T |
retrieveToken() |
protected abstract Duration |
timeBeforeExpiration(T token) |
protected abstract String |
usernameFromToken(T token) |
public String getUsername()
CredentialsProvider
getUsername
in interface CredentialsProvider
public String getPassword()
CredentialsProvider
getPassword
in interface CredentialsProvider
public Duration getTimeBeforeExpiration()
CredentialsProvider
If credentials do not expire, must return null. Default behavior is to return null, assuming credentials never expire.
getTimeBeforeExpiration
in interface CredentialsProvider
public void refresh()
CredentialsProvider
Default behavior is no-op.
refresh
in interface CredentialsProvider
protected abstract T retrieveToken()
Copyright © 2022 VMware, Inc. or its affiliates.. All rights reserved.