Class CredentialBuilderBase<T extends CredentialBuilderBase<T>>

java.lang.Object
com.azure.identity.CredentialBuilderBase<T>
Type Parameters:
T - the type of the credential builder
All Implemented Interfaces:
com.azure.core.client.traits.HttpTrait<T>
Direct Known Subclasses:
AadCredentialBuilderBase, AzureCliCredentialBuilder, AzureDeveloperCliCredentialBuilder, AzurePowerShellCredentialBuilder, DefaultAzureCredentialBuilder, EnvironmentCredentialBuilder, IntelliJCredentialBuilder, ManagedIdentityCredentialBuilder, VisualStudioCodeCredentialBuilder

public abstract class CredentialBuilderBase<T extends CredentialBuilderBase<T>> extends Object implements com.azure.core.client.traits.HttpTrait<T>
The base class for all the credential builders.
  • Method Summary

    Modifier and Type
    Method
    Description
    addPolicy(com.azure.core.http.policy.HttpPipelinePolicy policy)
    Adds a pipeline policy to apply on each request sent.
    clientOptions(com.azure.core.util.ClientOptions clientOptions)
    Allows for setting common properties such as application ID, headers, proxy configuration, etc.
    configuration(com.azure.core.util.Configuration configuration)
    Sets the configuration store that is used during construction of the credential.
    Enables account identifiers to be logged on client side for debugging/monitoring purposes.
    httpClient(com.azure.core.http.HttpClient client)
    Sets the HTTP client to use for sending and receiving requests to and from the service.
    httpLogOptions(com.azure.core.http.policy.HttpLogOptions logOptions)
    Sets the logging configuration to use when sending and receiving requests to and from the service.
    httpPipeline(com.azure.core.http.HttpPipeline httpPipeline)
    Deprecated.
    This method is deprecated.
    maxRetry(int maxRetry)
    Specifies the max number of retries when an authentication request fails.
    pipeline(com.azure.core.http.HttpPipeline pipeline)
    Sets the HttpPipeline to use for the service client.
    proxyOptions(com.azure.core.http.ProxyOptions proxyOptions)
    Deprecated.
    Configure the proxy options on the HttpClient instead and then set that client on the credential using httpClient(HttpClient).
    retryOptions(com.azure.core.http.policy.RetryOptions retryOptions)
    Sets the RetryOptions for all the requests made through the client.
    retryPolicy(com.azure.core.http.policy.RetryPolicy retryPolicy)
    Sets the RetryPolicy that is used when each request is sent.
    Specifies a Function to calculate seconds of timeout on every retried request.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • maxRetry

      public T maxRetry(int maxRetry)
      Specifies the max number of retries when an authentication request fails.
      Parameters:
      maxRetry - the number of retries
      Returns:
      An updated instance of this builder with the max retry set as specified.
    • retryTimeout

      public T retryTimeout(Function<Duration,Duration> retryTimeout)
      Specifies a Function to calculate seconds of timeout on every retried request.
      Parameters:
      retryTimeout - the Function that returns a timeout in seconds given the number of retry
      Returns:
      An updated instance of this builder with the retry timeout set as specified.
    • proxyOptions

      @Deprecated public T proxyOptions(com.azure.core.http.ProxyOptions proxyOptions)
      Deprecated.
      Configure the proxy options on the HttpClient instead and then set that client on the credential using httpClient(HttpClient).
      Specifies the options for proxy configuration.
      Parameters:
      proxyOptions - the options for proxy configuration
      Returns:
      An updated instance of this builder with the proxy options set as specified.
    • httpPipeline

      @Deprecated public T httpPipeline(com.azure.core.http.HttpPipeline httpPipeline)
      Deprecated.
      This method is deprecated.

      Use pipeline(HttpPipeline) instead

      Specifies the HttpPipeline to send all requests. This setting overrides the others.
      Parameters:
      httpPipeline - the HttpPipeline to send all requests
      Returns:
      An updated instance of this builder with the http pipeline set as specified.
    • httpClient

      public T httpClient(com.azure.core.http.HttpClient client)
      Sets the HTTP client to use for sending and receiving requests to and from the service.
      Specified by:
      httpClient in interface com.azure.core.client.traits.HttpTrait<T extends CredentialBuilderBase<T>>
      Parameters:
      client - The HTTP client to use for requests.
      Returns:
      An updated instance of this builder with the http client set as specified.
      Throws:
      NullPointerException - If client is null.
    • configuration

      public T configuration(com.azure.core.util.Configuration configuration)
      Sets the configuration store that is used during construction of the credential. The default configuration store is a clone of the global configuration store.
      Parameters:
      configuration - The configuration store used to load Env variables and/or properties from.
      Returns:
      An updated instance of this builder with the configuration store set as specified.
    • clientOptions

      public T clientOptions(com.azure.core.util.ClientOptions clientOptions)
      Allows for setting common properties such as application ID, headers, proxy configuration, etc. Note that it is recommended that this method be called with an instance of the HttpClientOptions class (a subclass of the ClientOptions base class). The HttpClientOptions subclass provides more configuration options suitable for HTTP clients, which is applicable for any class that implements this HttpTrait interface.

      Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.

      Specified by:
      clientOptions in interface com.azure.core.client.traits.HttpTrait<T extends CredentialBuilderBase<T>>
      Parameters:
      clientOptions - A configured instance of HttpClientOptions.
      Returns:
      An updated instance of this builder with the client options configured.
      See Also:
      • HttpClientOptions
    • httpLogOptions

      public T httpLogOptions(com.azure.core.http.policy.HttpLogOptions logOptions)
      Sets the logging configuration to use when sending and receiving requests to and from the service. If a logLevel is not provided, default value of HttpLogDetailLevel.NONE is set.

      Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.

      Specified by:
      httpLogOptions in interface com.azure.core.client.traits.HttpTrait<T extends CredentialBuilderBase<T>>
      Parameters:
      logOptions - The logging configuration to use when sending and receiving requests to and from the service.
      Returns:
      An updated instance of this builder with the Http log options configured.
    • retryPolicy

      public T retryPolicy(com.azure.core.http.policy.RetryPolicy retryPolicy)
      Sets the RetryPolicy that is used when each request is sent. Setting this is mutually exclusive with using retryOptions(RetryOptions). The default retry policy will be used in the pipeline, if not provided.
      Parameters:
      retryPolicy - user's retry policy applied to each request.
      Returns:
      An updated instance of this builder with the retry policy configured.
    • retryOptions

      public T retryOptions(com.azure.core.http.policy.RetryOptions retryOptions)
      Sets the RetryOptions for all the requests made through the client.

      Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.

      Setting this is mutually exclusive with using retryPolicy(RetryPolicy).

      Specified by:
      retryOptions in interface com.azure.core.client.traits.HttpTrait<T extends CredentialBuilderBase<T>>
      Parameters:
      retryOptions - The RetryOptions to use for all the requests made through the client.
      Returns:
      An updated instance of this builder with the retry options configured.
    • addPolicy

      public T addPolicy(com.azure.core.http.policy.HttpPipelinePolicy policy)
      Adds a pipeline policy to apply on each request sent.

      Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.

      Specified by:
      addPolicy in interface com.azure.core.client.traits.HttpTrait<T extends CredentialBuilderBase<T>>
      Parameters:
      policy - A pipeline policy.
      Returns:
      An updated instance of this builder with the policy configured.
      Throws:
      NullPointerException - If policy is null.
    • pipeline

      public T pipeline(com.azure.core.http.HttpPipeline pipeline)
      Sets the HttpPipeline to use for the service client.

      Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.

      Specified by:
      pipeline in interface com.azure.core.client.traits.HttpTrait<T extends CredentialBuilderBase<T>>
      Parameters:
      pipeline - HttpPipeline to use for sending service requests and receiving responses.
      Returns:
      An updated instance of this builder with the http pipeline set as specified.
    • enableAccountIdentifierLogging

      public T enableAccountIdentifierLogging()
      Enables account identifiers to be logged on client side for debugging/monitoring purposes. By default, it is disabled.

      The Account Identifier logs can contain sensitive information and should be enabled on protected machines only. Enabling this logs Application ID, Object ID, Tenant ID and User Principal Name at INFO level when an access token is successfully retrieved. Ensure that INFO level logs are enabled to see the account identifier logs.

      Returns:
      An updated instance of this builder.