Skip to content

Commit

Permalink
Merge branch 'fix_builders' into programmatic-auth
Browse files Browse the repository at this point in the history
# Conflicts:
#	oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentials.java
#	oauth2_http/javatests/com/google/auth/oauth2/AwsCredentialsTest.java
#	oauth2_http/javatests/com/google/auth/oauth2/ExternalAccountCredentialsTest.java
  • Loading branch information
aeitzman committed Dec 1, 2023
2 parents 616fb13 + b2552eb commit d32e19c
Show file tree
Hide file tree
Showing 8 changed files with 715 additions and 443 deletions.
97 changes: 97 additions & 0 deletions oauth2_http/java/com/google/auth/oauth2/AwsCredentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.google.api.client.http.HttpResponse;
import com.google.api.client.json.GenericJson;
import com.google.api.client.json.JsonParser;
import com.google.auth.http.HttpTransportFactory;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
Expand Down Expand Up @@ -475,6 +476,102 @@ public Builder setRegionalCredentialVerificationUrlOverride(
return this;
}

@CanIgnoreReturnValue
public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) {
super.setHttpTransportFactory(transportFactory);
return this;
}

@CanIgnoreReturnValue
public Builder setAudience(String audience) {
super.setAudience(audience);
return this;
}

@CanIgnoreReturnValue
public Builder setSubjectTokenType(String subjectTokenType) {
super.setSubjectTokenType(subjectTokenType);
return this;
}

@CanIgnoreReturnValue
public Builder setSubjectTokenType(SubjectTokenTypes subjectTokenType) {
super.setSubjectTokenType(subjectTokenType);
return this;
}

@CanIgnoreReturnValue
public Builder setTokenUrl(String tokenUrl) {
super.setTokenUrl(tokenUrl);
return this;
}

@CanIgnoreReturnValue
public Builder setCredentialSource(AwsCredentialSource credentialSource) {
super.setCredentialSource(credentialSource);
return this;
}

@CanIgnoreReturnValue
public Builder setServiceAccountImpersonationUrl(String serviceAccountImpersonationUrl) {
super.setServiceAccountImpersonationUrl(serviceAccountImpersonationUrl);
return this;
}

@CanIgnoreReturnValue
public Builder setTokenInfoUrl(String tokenInfoUrl) {
super.setTokenInfoUrl(tokenInfoUrl);
return this;
}

@CanIgnoreReturnValue
public Builder setQuotaProjectId(String quotaProjectId) {
super.setQuotaProjectId(quotaProjectId);
return this;
}

@CanIgnoreReturnValue
public Builder setClientId(String clientId) {
super.setClientId(clientId);
return this;
}

@CanIgnoreReturnValue
public Builder setClientSecret(String clientSecret) {
super.setClientSecret(clientSecret);
return this;
}

@CanIgnoreReturnValue
public Builder setScopes(Collection<String> scopes) {
super.setScopes(scopes);
return this;
}

@CanIgnoreReturnValue
public Builder setWorkforcePoolUserProject(String workforcePoolUserProject) {
super.setWorkforcePoolUserProject(workforcePoolUserProject);
return this;
}

@CanIgnoreReturnValue
public Builder setServiceAccountImpersonationOptions(Map<String, Object> optionsMap) {
super.setServiceAccountImpersonationOptions(optionsMap);
return this;
}

@CanIgnoreReturnValue
public Builder setUniverseDomain(String universeDomain) {
super.setUniverseDomain(universeDomain);
return this;
}

@CanIgnoreReturnValue
Builder setEnvironmentProvider(EnvironmentProvider environmentProvider) {
super.setEnvironmentProvider(environmentProvider);
return this;
}

@Override
public AwsCredentials build() {
return new AwsCredentials(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@
*/
public abstract class ExternalAccountCredentials extends GoogleCredentials {

/**
* Enum to specify values for the subjectTokenType field in {@code ExternalAccountCredentials}.
*/
public enum SubjectTokenTypes {
AWS4("urn:ietf:params:aws:token-type:aws4_request"),
JWT("urn:ietf:params:oauth:token-type:jwt"),
SAML2("urn:ietf:params:oauth:token-type:saml2"),
ID_TOKEN("urn:ietf:params:oauth:token-type:id_token");

public final String value;

private SubjectTokenTypes(String value) {
this.value = value;
}
}

private static final long serialVersionUID = 8049126194174465023L;

/** Base credential source class. Dictates the retrieval method of the external credential. */
Expand Down Expand Up @@ -789,6 +805,19 @@ public Builder setSubjectTokenType(String subjectTokenType) {
return this;
}

/**
* Sets the Security Token Service subject token type based on the OAuth 2.0 token exchange
* spec. Indicates the type of the security token in the credential file.
*
* @param subjectTokenType the {@code SubjectTokenType} to set
* @return this {@code Builder} object
*/
@CanIgnoreReturnValue
public Builder setSubjectTokenType(SubjectTokenTypes subjectTokenType) {
this.subjectTokenType = subjectTokenType.value;
return this;
}

/**
* Sets the Security Token Service token exchange endpoint.
*
Expand Down
104 changes: 98 additions & 6 deletions oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.google.api.client.http.HttpResponse;
import com.google.api.client.json.GenericJson;
import com.google.api.client.json.JsonObjectParser;
import com.google.auth.http.HttpTransportFactory;
import com.google.auth.oauth2.IdentityPoolCredentialSource.CredentialFormatType;
import com.google.auth.oauth2.IdentityPoolCredentialSource.IdentityPoolCredentialSourceType;
import com.google.common.io.CharStreams;
Expand All @@ -55,6 +56,7 @@
import java.util.Collection;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import java.util.Map;

/**
* Url-sourced and file-sourced external account credentials.
Expand Down Expand Up @@ -210,12 +212,6 @@ public static class Builder extends ExternalAccountCredentials.Builder {
this.setSubjectTokenSupplier(credentials.subjectTokenSupplier);
}

@CanIgnoreReturnValue
public Builder setWorkforcePoolUserProject(String workforcePoolUserProject) {
super.setWorkforcePoolUserProject(workforcePoolUserProject);
return this;
}

/**
* Sets the subject token supplier. The supplier should return a valid subject token string.
*
Expand All @@ -228,6 +224,102 @@ public Builder setSubjectTokenSupplier(Supplier<String> subjectTokenSupplier) {
return this;
}

@CanIgnoreReturnValue
public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) {
super.setHttpTransportFactory(transportFactory);
return this;
}

@CanIgnoreReturnValue
public Builder setAudience(String audience) {
super.setAudience(audience);
return this;
}

@CanIgnoreReturnValue
public Builder setSubjectTokenType(String subjectTokenType) {
super.setSubjectTokenType(subjectTokenType);
return this;
}

@CanIgnoreReturnValue
public Builder setSubjectTokenType(SubjectTokenTypes subjectTokenType) {
super.setSubjectTokenType(subjectTokenType);
return this;
}

@CanIgnoreReturnValue
public Builder setTokenUrl(String tokenUrl) {
super.setTokenUrl(tokenUrl);
return this;
}

@CanIgnoreReturnValue
public Builder setCredentialSource(IdentityPoolCredentialSource credentialSource) {
super.setCredentialSource(credentialSource);
return this;
}

@CanIgnoreReturnValue
public Builder setServiceAccountImpersonationUrl(String serviceAccountImpersonationUrl) {
super.setServiceAccountImpersonationUrl(serviceAccountImpersonationUrl);
return this;
}

@CanIgnoreReturnValue
public Builder setTokenInfoUrl(String tokenInfoUrl) {
super.setTokenInfoUrl(tokenInfoUrl);
return this;
}

@CanIgnoreReturnValue
public Builder setQuotaProjectId(String quotaProjectId) {
super.setQuotaProjectId(quotaProjectId);
return this;
}

@CanIgnoreReturnValue
public Builder setClientId(String clientId) {
super.setClientId(clientId);
return this;
}

@CanIgnoreReturnValue
public Builder setClientSecret(String clientSecret) {
super.setClientSecret(clientSecret);
return this;
}

@CanIgnoreReturnValue
public Builder setScopes(Collection<String> scopes) {
super.setScopes(scopes);
return this;
}

@CanIgnoreReturnValue
public Builder setWorkforcePoolUserProject(String workforcePoolUserProject) {
super.setWorkforcePoolUserProject(workforcePoolUserProject);
return this;
}

@CanIgnoreReturnValue
public Builder setServiceAccountImpersonationOptions(Map<String, Object> optionsMap) {
super.setServiceAccountImpersonationOptions(optionsMap);
return this;
}

@CanIgnoreReturnValue
public Builder setUniverseDomain(String universeDomain) {
super.setUniverseDomain(universeDomain);
return this;
}

@CanIgnoreReturnValue
Builder setEnvironmentProvider(EnvironmentProvider environmentProvider) {
super.setEnvironmentProvider(environmentProvider);
return this;
}

@Override
public IdentityPoolCredentials build() {
return new IdentityPoolCredentials(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

package com.google.auth.oauth2;

import com.google.auth.http.HttpTransportFactory;
import com.google.auth.oauth2.ExecutableHandler.ExecutableOptions;
import com.google.common.annotations.VisibleForTesting;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
Expand Down Expand Up @@ -222,6 +223,102 @@ public Builder setExecutableHandler(ExecutableHandler handler) {
return this;
}

@CanIgnoreReturnValue
public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) {
super.setHttpTransportFactory(transportFactory);
return this;
}

@CanIgnoreReturnValue
public Builder setAudience(String audience) {
super.setAudience(audience);
return this;
}

@CanIgnoreReturnValue
public Builder setSubjectTokenType(String subjectTokenType) {
super.setSubjectTokenType(subjectTokenType);
return this;
}

@CanIgnoreReturnValue
public Builder setSubjectTokenType(SubjectTokenTypes subjectTokenType) {
super.setSubjectTokenType(subjectTokenType);
return this;
}

@CanIgnoreReturnValue
public Builder setTokenUrl(String tokenUrl) {
super.setTokenUrl(tokenUrl);
return this;
}

@CanIgnoreReturnValue
public Builder setCredentialSource(PluggableAuthCredentialSource credentialSource) {
super.setCredentialSource(credentialSource);
return this;
}

@CanIgnoreReturnValue
public Builder setServiceAccountImpersonationUrl(String serviceAccountImpersonationUrl) {
super.setServiceAccountImpersonationUrl(serviceAccountImpersonationUrl);
return this;
}

@CanIgnoreReturnValue
public Builder setTokenInfoUrl(String tokenInfoUrl) {
super.setTokenInfoUrl(tokenInfoUrl);
return this;
}

@CanIgnoreReturnValue
public Builder setQuotaProjectId(String quotaProjectId) {
super.setQuotaProjectId(quotaProjectId);
return this;
}

@CanIgnoreReturnValue
public Builder setClientId(String clientId) {
super.setClientId(clientId);
return this;
}

@CanIgnoreReturnValue
public Builder setClientSecret(String clientSecret) {
super.setClientSecret(clientSecret);
return this;
}

@CanIgnoreReturnValue
public Builder setScopes(Collection<String> scopes) {
super.setScopes(scopes);
return this;
}

@CanIgnoreReturnValue
public Builder setWorkforcePoolUserProject(String workforcePoolUserProject) {
super.setWorkforcePoolUserProject(workforcePoolUserProject);
return this;
}

@CanIgnoreReturnValue
public Builder setServiceAccountImpersonationOptions(Map<String, Object> optionsMap) {
super.setServiceAccountImpersonationOptions(optionsMap);
return this;
}

@CanIgnoreReturnValue
public Builder setUniverseDomain(String universeDomain) {
super.setUniverseDomain(universeDomain);
return this;
}

@CanIgnoreReturnValue
Builder setEnvironmentProvider(EnvironmentProvider environmentProvider) {
super.setEnvironmentProvider(environmentProvider);
return this;
}

@Override
public PluggableAuthCredentials build() {
return new PluggableAuthCredentials(this);
Expand Down
Loading

0 comments on commit d32e19c

Please sign in to comment.