# Class ImpersonatedCredentials.Builder (1.46.0)

1.46.0 (latest) 1.43.0 1.42.1 1.41.0 1.40.0 1.39.1 1.38.0 1.37.1 1.36.0 1.35.0 1.34.0 1.33.1 1.32.1 1.31.0 1.30.1 1.29.1-SNAPSHOT 1.28.0 1.27.0 1.26.0 1.25.0 1.24.1 1.20.0 1.19.0 1.18.0 1.7.0 1.6.1 1.4.0 1.3.0

    public static class ImpersonatedCredentials.Builder extends GoogleCredentials.Builder

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> [OAuth2Credentials.Builder](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials.Builder) \> [GoogleCredentials.Builder](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials.Builder) \> ImpersonatedCredentials.Builder

## Inherited Members

[GoogleCredentials.Builder.build()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials.Builder#com_google_auth_oauth2_GoogleCredentials_Builder_build__) [GoogleCredentials.Builder.getQuotaProjectId()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials.Builder#com_google_auth_oauth2_GoogleCredentials_Builder_getQuotaProjectId__) [GoogleCredentials.Builder.getUniverseDomain()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials.Builder#com_google_auth_oauth2_GoogleCredentials_Builder_getUniverseDomain__) [GoogleCredentials.Builder.setAccessToken(AccessToken)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials.Builder#com_google_auth_oauth2_GoogleCredentials_Builder_setAccessToken_com_google_auth_oauth2_AccessToken_) [GoogleCredentials.Builder.setQuotaProjectId(String)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials.Builder#com_google_auth_oauth2_GoogleCredentials_Builder_setQuotaProjectId_java_lang_String_) [GoogleCredentials.Builder.setUniverseDomain(String)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials.Builder#com_google_auth_oauth2_GoogleCredentials_Builder_setUniverseDomain_java_lang_String_) [OAuth2Credentials.Builder.getAccessToken()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials.Builder#com_google_auth_oauth2_OAuth2Credentials_Builder_getAccessToken__) [OAuth2Credentials.Builder.getExpirationMargin()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials.Builder#com_google_auth_oauth2_OAuth2Credentials_Builder_getExpirationMargin__) [OAuth2Credentials.Builder.getRefreshMargin()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials.Builder#com_google_auth_oauth2_OAuth2Credentials_Builder_getRefreshMargin__) [OAuth2Credentials.Builder.setExpirationMargin(Duration)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials.Builder#com_google_auth_oauth2_OAuth2Credentials_Builder_setExpirationMargin_java_time_Duration_) [OAuth2Credentials.Builder.setRefreshMargin(Duration)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials.Builder#com_google_auth_oauth2_OAuth2Credentials_Builder_setRefreshMargin_java_time_Duration_) [Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Constructors

### Builder()

    protected Builder()

### Builder(GoogleCredentials sourceCredentials, String targetPrincipal) (deprecated)

    protected Builder(GoogleCredentials sourceCredentials, String targetPrincipal)

**Deprecated.** *Use [#Builder(ImpersonatedCredentials)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.ImpersonatedCredentials.Builder#com_google_auth_oauth2_ImpersonatedCredentials_Builder_Builder_com_google_auth_oauth2_ImpersonatedCredentials_) instead. This constructor will be
removed in a future release.*

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `sourceCredentials` | `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials` The source credentials to use for impersonation. |
| `targetPrincipal` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The service account to impersonate. |

### Builder(ImpersonatedCredentials credentials)

    protected Builder(ImpersonatedCredentials credentials)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `credentials` | `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.ImpersonatedCredentials` |

## Methods

### build()

    public ImpersonatedCredentials build()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.ImpersonatedCredentials` |   |

**Overrides** [GoogleCredentials.Builder.build()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials.Builder#com_google_auth_oauth2_GoogleCredentials_Builder_build__)

### getCalendar()

    public Calendar getCalendar()

> [!WARNING]
> **Obsolete**
>
> *This method is obsolete and will be removed in a future release.*
>
> This feature is stable for usage in this major version, but may be deprecated in a future release.

This method is marked obsolete. There is no alternative to getting a custom calendar for the
Credential.

Returns the calendar to be used for parsing the expiration time.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html` | the calendar |

### getDelegates()

    public List<String> getDelegates()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` |   |

### getHttpTransportFactory()

    public HttpTransportFactory getHttpTransportFactory()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.http.HttpTransportFactory` |   |

### getLifetime()

    public int getLifetime()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### getScopes()

    public List<String> getScopes()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` | List of scopes to be applied to the impersonated token. |

### getSourceCredentials()

    public GoogleCredentials getSourceCredentials()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials` |   |

### getTargetPrincipal()

    public String getTargetPrincipal()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### setCalendar(Calendar calendar)

    public ImpersonatedCredentials.Builder setCalendar(Calendar calendar)

> [!WARNING]
> **Obsolete**
>
> *This method is obsolete and will be removed in a future release.*
>
> This feature is stable for usage in this major version, but may be deprecated in a future release.

This method is marked obsolete. There is no alternative to setting a custom calendar for the
Credential.

Sets the calendar to be used for parsing the expiration time.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `calendar` | `https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html` the calendar to use |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.ImpersonatedCredentials.Builder` | the builder |

### setConnectTimeout(int connectTimeout)

    public ImpersonatedCredentials.Builder setConnectTimeout(int connectTimeout)

> [!WARNING]
> **Internal Only**: This feature is not stable for application use.

Warning: Not for public use and can be removed at any time.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `connectTimeout` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.ImpersonatedCredentials.Builder` |   |

### setDelegates(List\<String\> delegates)

    public ImpersonatedCredentials.Builder setDelegates(List<String> delegates)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `delegates` | `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.ImpersonatedCredentials.Builder` |   |

### setHttpTransportFactory(HttpTransportFactory transportFactory)

    public ImpersonatedCredentials.Builder setHttpTransportFactory(HttpTransportFactory transportFactory)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `transportFactory` | `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.http.HttpTransportFactory` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.ImpersonatedCredentials.Builder` |   |

### setIamEndpointOverride(String iamEndpointOverride)

    public ImpersonatedCredentials.Builder setIamEndpointOverride(String iamEndpointOverride)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `iamEndpointOverride` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.ImpersonatedCredentials.Builder` |   |

### setLifetime(int lifetime)

    public ImpersonatedCredentials.Builder setLifetime(int lifetime)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `lifetime` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.ImpersonatedCredentials.Builder` |   |

### setQuotaProjectId(String quotaProjectId)

    public ImpersonatedCredentials.Builder setQuotaProjectId(String quotaProjectId)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `quotaProjectId` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.ImpersonatedCredentials.Builder` |   |

**Overrides** [GoogleCredentials.Builder.setQuotaProjectId(String quotaProjectId)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials.Builder#com_google_auth_oauth2_GoogleCredentials_Builder_setQuotaProjectId_java_lang_String_)

### setReadTimeout(int readTimeout)

    public ImpersonatedCredentials.Builder setReadTimeout(int readTimeout)

> [!WARNING]
> **Internal Only**: This feature is not stable for application use.

Warning: Not for public use and can be removed at any time.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `readTimeout` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.ImpersonatedCredentials.Builder` |   |

### setScopes(List\<String\> scopes)

    public ImpersonatedCredentials.Builder setScopes(List<String> scopes)

Set the scopes to be applied on the impersonated token and not on the source credential. This
user configuration has precedence over the scopes listed in the source credential json file.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `scopes` | `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` List of scopes to apply to the impersonated token |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.ImpersonatedCredentials.Builder` |   |

### setSourceCredentials(GoogleCredentials sourceCredentials)

    public ImpersonatedCredentials.Builder setSourceCredentials(GoogleCredentials sourceCredentials)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `sourceCredentials` | `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.ImpersonatedCredentials.Builder` |   |

### setTargetPrincipal(String targetPrincipal)

    public ImpersonatedCredentials.Builder setTargetPrincipal(String targetPrincipal)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `targetPrincipal` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.ImpersonatedCredentials.Builder` |   |