Class RefreshProtectedCredentialsProvider<T>
- java.lang.Object
-
- com.rabbitmq.client.impl.RefreshProtectedCredentialsProvider<T>
-
- Type Parameters:
T- the type of token (usually specified by the subclass)
- All Implemented Interfaces:
CredentialsProvider
- Direct Known Subclasses:
OAuth2ClientCredentialsGrantCredentialsProvider
public abstract class RefreshProtectedCredentialsProvider<T> extends java.lang.Object implements CredentialsProvider
An abstractCredentialsProviderthat 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.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicReference<java.util.concurrent.CountDownLatch>latchprivate static org.slf4j.LoggerLOGGERprivate java.util.concurrent.atomic.AtomicBooleanrefreshInProcessprivate java.util.concurrent.locks.LockrefreshLockprivate java.util.concurrent.atomic.AtomicReference<T>token
-
Constructor Summary
Constructors Constructor Description RefreshProtectedCredentialsProvider()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetPassword()Password/secret/token to use for authenticationjava.time.DurationgetTimeBeforeExpiration()The time before the credentials expire, if they do expire.java.lang.StringgetUsername()Username to use for authenticationprotected abstract java.lang.StringpasswordFromToken(T token)voidrefresh()Instructs the provider to refresh or renew credentials.protected abstract TretrieveToken()protected abstract java.time.DurationtimeBeforeExpiration(T token)protected abstract java.lang.StringusernameFromToken(T token)
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
token
private final java.util.concurrent.atomic.AtomicReference<T> token
-
refreshLock
private final java.util.concurrent.locks.Lock refreshLock
-
latch
private final java.util.concurrent.atomic.AtomicReference<java.util.concurrent.CountDownLatch> latch
-
refreshInProcess
private java.util.concurrent.atomic.AtomicBoolean refreshInProcess
-
-
Method Detail
-
getUsername
public java.lang.String getUsername()
Description copied from interface:CredentialsProviderUsername to use for authentication- Specified by:
getUsernamein interfaceCredentialsProvider- Returns:
- username
-
getPassword
public java.lang.String getPassword()
Description copied from interface:CredentialsProviderPassword/secret/token to use for authentication- Specified by:
getPasswordin interfaceCredentialsProvider- Returns:
- password/secret/token
-
getTimeBeforeExpiration
public java.time.Duration getTimeBeforeExpiration()
Description copied from interface:CredentialsProviderThe time before the credentials expire, if they do expire.If credentials do not expire, must return null. Default behavior is to return null, assuming credentials never expire.
- Specified by:
getTimeBeforeExpirationin interfaceCredentialsProvider- Returns:
- time before expiration
-
refresh
public void refresh()
Description copied from interface:CredentialsProviderInstructs the provider to refresh or renew credentials.Default behavior is no-op.
- Specified by:
refreshin interfaceCredentialsProvider
-
retrieveToken
protected abstract T retrieveToken()
-
usernameFromToken
protected abstract java.lang.String usernameFromToken(T token)
-
passwordFromToken
protected abstract java.lang.String passwordFromToken(T token)
-
timeBeforeExpiration
protected abstract java.time.Duration timeBeforeExpiration(T token)
-
-