public class ImpersonatedCredentials extends GoogleCredentials
String credPath = "/path/to/svc_account.json";
ServiceAccountCredentials sourceCredentials = ServiceAccountCredentials
.fromStream(new FileInputStream(credPath));
sourceCredentials = (ServiceAccountCredentials) sourceCredentials
.createScoped(Arrays.asList("https://www.googleapis.com/auth/iam"));
ImpersonatedCredentials targetCredentials = ImpersonatedCredentials.create(sourceCredentials,
"impersonated-account@project.iam.gserviceaccount.com", null,
Arrays.asList("https://www.googleapis.com/auth/devstorage.read_only"), 300);
Storage storage_service = StorageOptions.newBuilder().setProjectId("project-id")
.setCredentials(targetCredentials).build().getService();
for (Bucket b : storage_service.list().iterateAll())
System.out.println(b);
| Modifier and Type | Class and Description |
|---|---|
static class |
ImpersonatedCredentials.Builder |
OAuth2Credentials.CredentialsChangedListener| Modifier and Type | Method and Description |
|---|---|
static ImpersonatedCredentials |
create(GoogleCredentials sourceCredentials,
String targetPrincipal,
List<String> delegates,
List<String> scopes,
int lifetime) |
static ImpersonatedCredentials |
create(GoogleCredentials sourceCredentials,
String targetPrincipal,
List<String> delegates,
List<String> scopes,
int lifetime,
HttpTransportFactory transportFactory) |
boolean |
equals(Object obj) |
int |
hashCode() |
static ImpersonatedCredentials.Builder |
newBuilder() |
AccessToken |
refreshAccessToken()
Method to refresh the access token according to the specific type of credentials.
|
ImpersonatedCredentials.Builder |
toBuilder() |
String |
toString() |
create, createDelegated, createScoped, createScoped, createScopedRequired, fromStream, fromStream, getApplicationDefault, getApplicationDefaultaddChangeListener, getAccessToken, getAuthenticationType, getFromServiceLoader, getRequestMetadata, getRequestMetadata, getRequestMetadataInternal, hasRequestMetadata, hasRequestMetadataOnly, newInstance, refresh, refreshIfExpired, removeChangeListenerblockingGetToCallback, getRequestMetadatapublic static ImpersonatedCredentials create(GoogleCredentials sourceCredentials, String targetPrincipal, List<String> delegates, List<String> scopes, int lifetime, HttpTransportFactory transportFactory)
sourceCredentials - The source credential used as to acquire the impersonated credentialstargetPrincipal - The service account to impersonate.delegates - The chained list of delegates required to grant the final access_token. If
set, the sequence of identities must have "Service Account Token Creator" capability granted to
the preceding identity. For example, if set to [serviceAccountB, serviceAccountC], the
sourceCredential must have the Token Creator role on serviceAccountB. serviceAccountB must have
the Token Creator on serviceAccountC. Finally, C must have Token Creator on target_principal.
If left unset, sourceCredential must have that role on targetPrincipal.scopes - Scopes to request during the authorization grant.lifetime - Number of seconds the delegated credential should be valid for (up to 3600).transportFactory - HTTP transport factory, creates the transport used to get access
tokens.public static ImpersonatedCredentials create(GoogleCredentials sourceCredentials, String targetPrincipal, List<String> delegates, List<String> scopes, int lifetime)
sourceCredentials - The source credential used as to acquire the impersonated credentialstargetPrincipal - The service account to impersonate.delegates - The chained list of delegates required to grant the final access_token. If
set, the sequence of identities must have "Service Account Token Creator" capability granted to
the preceding identity. For example, if set to [serviceAccountB, serviceAccountC], the
sourceCredential must have the Token Creator role on serviceAccountB. serviceAccountB must have
the Token Creator on serviceAccountC. Finally, C must have Token Creator on target_principal.
If left unset, sourceCredential must have that role on targetPrincipal.scopes - Scopes to request during the authorization grant.lifetime - Number of seconds the delegated credential should be valid for (up to 3600).public AccessToken refreshAccessToken() throws IOException
OAuth2CredentialsrefreshAccessToken in class OAuth2CredentialsIOException - from derived implementationspublic int hashCode()
hashCode in class OAuth2Credentialspublic String toString()
toString in class OAuth2Credentialspublic boolean equals(Object obj)
equals in class OAuth2Credentialspublic ImpersonatedCredentials.Builder toBuilder()
toBuilder in class GoogleCredentialspublic static ImpersonatedCredentials.Builder newBuilder()
Copyright © 2019 Google. All rights reserved.