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 Object implements CredentialsProvider
An abstract 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 Details

    • RefreshProtectedCredentialsProvider

      public RefreshProtectedCredentialsProvider()
  • Method Details

    • getUsername

      public String getUsername()
      Description copied from interface: CredentialsProvider
      Username to use for authentication
      Specified by:
      getUsername in interface CredentialsProvider
      Returns:
      username
    • getPassword

      public String getPassword()
      Description copied from interface: CredentialsProvider
      Password/secret/token to use for authentication
      Specified by:
      getPassword in interface CredentialsProvider
      Returns:
      password/secret/token
    • getTimeBeforeExpiration

      public Duration getTimeBeforeExpiration()
      Description copied from interface: CredentialsProvider
      The 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:
      getTimeBeforeExpiration in interface CredentialsProvider
      Returns:
      time before expiration
    • refresh

      public void refresh()
      Description copied from interface: CredentialsProvider
      Instructs the provider to refresh or renew credentials.

      Default behavior is no-op.

      Specified by:
      refresh in interface CredentialsProvider
    • retrieveToken

      protected abstract T retrieveToken()
    • usernameFromToken

      protected abstract String usernameFromToken(T token)
    • passwordFromToken

      protected abstract String passwordFromToken(T token)
    • timeBeforeExpiration

      protected abstract Duration timeBeforeExpiration(T token)