RefreshingOAuth2CredentialsInterceptor (Cloud Bigtable HBase Client for Java 0.9.3-SNAPSHOT API)

com.google.cloud.bigtable.grpc.io

Class RefreshingOAuth2CredentialsInterceptor

  • java.lang.Object
    • com.google.cloud.bigtable.grpc.io.RefreshingOAuth2CredentialsInterceptor
  • All Implemented Interfaces:
    HeaderInterceptor


    public class RefreshingOAuth2CredentialsInterceptor
    extends Object
    implements HeaderInterceptor
    Client interceptor that authenticates all calls by binding header data provided by a credential. Typically this will populate the Authorization header but other headers may also be filled out.

    Uses the new and simplified Google auth library: https://github.com/google/google-auth-library-java

    TODO: COPIED FROM io.grpc.auth.ClientAuthInterceptor. The logic added here for initialization and locking could be moved back to gRPC. This implementation takes advantage of the fact that all of the Bigtable endpoints are OAuth2 based. It uses the OAuth AccessToken to get the token value and next refresh time. The refresh is scheduled asynchronously.

    Version:
    $Id: $Id
    Author:
    sduskis
    • Constructor Detail

      • RefreshingOAuth2CredentialsInterceptor

        public RefreshingOAuth2CredentialsInterceptor(ExecutorService scheduler,
                                                      com.google.auth.oauth2.OAuth2Credentials credentials,
                                                      RetryOptions retryOptions)

        Constructor for RefreshingOAuth2CredentialsInterceptor.

        Parameters:
        scheduler - a ExecutorService object.
        credentials - a OAuth2Credentials object.
        retryOptions - a RetryOptions object.
    • Method Detail

      • updateHeaders

        public void updateHeaders(io.grpc.Metadata headers)
                           throws Exception
        Modify the headers before an RPC call is made.
        Specified by:
        updateHeaders in interface HeaderInterceptor
        Parameters:
        headers - a Metadata object.
        Throws:
        Exception - if any.
      • asyncRefresh

        public void asyncRefresh()

        asyncRefresh.

      • refreshCredentialsWithRetry

        protected com.google.cloud.bigtable.grpc.io.RefreshingOAuth2CredentialsInterceptor.HeaderCacheElement refreshCredentialsWithRetry()

        Calls OAuth2Credentials.refreshAccessToken(). In case of an IOException, retry the call as per the BackOff policy defined by RetryOptions.createBackoff().

        This method retries until one of the following conditions occurs:

        1. An OAuth request was completed. If the value is null, return an exception.
        2. A non-IOException Exception is thrown - return an error status
        3. All retries have been exhausted, i.e. when the Backoff.nextBackOffMillis() returns BackOff.STOP
        4. An interrupt occurs.
        Returns:
        HeaderCacheElement containing either a valid AccessToken or an exception.
      • getRetryState

        protected com.google.cloud.bigtable.grpc.io.RefreshingOAuth2CredentialsInterceptor.RetryState getRetryState(com.google.api.client.util.BackOff backoff)
                                                                                                             throws IOException
        Sleep and/or determine if the backoff has timed out.
        Parameters:
        backoff - a BackOff object.
        Returns:
        RetryState indicating the current state of the retry logic.
        Throws:
        IOException - in some cases from BackOff.nextBackOffMillis()


Send feedback about...

Cloud Bigtable Documentation