@@ -100,10 +100,6 @@ public abstract class ExternalAccountCredentials extends GoogleCredentials
100100
101101 private EnvironmentProvider environmentProvider ;
102102
103- private static final String WORKFORCE_POOL_URL_FORMAT =
104- "https://iamcredentials.googleapis.com/v1/locations/global/workforcePools/%s/allowedLocations" ;
105- private static final String WORKLOAD_POOL_URL_FORMAT =
106- "https://iamcredentials.googleapis.com/v1/projects/%s/locations/global/workloadIdentityPools/%s/allowedLocations" ;
107103
108104 private static final Pattern WORKFORCE_PATTERN =
109105 Pattern .compile (
@@ -633,26 +629,28 @@ public String getServiceAccountEmail() {
633629 return ImpersonatedCredentials .extractTargetPrincipal (serviceAccountImpersonationUrl );
634630 }
635631
636- // todo Add doc comment.
637632 @ Override
638633 public String getTrustBoundaryUrl () throws IOException {
639- if (isWorkforcePoolConfiguration ()) {
640- Matcher matcher = WORKFORCE_PATTERN .matcher (getAudience ());
641- if (!matcher .matches ()) {
642- throw new IOException (
643- "The provided audience is not in the correct format for a workforce pool." );
644- }
645- String poolId = matcher .group ("pool" );
646- return String .format (WORKFORCE_POOL_URL_FORMAT , poolId );
634+ Matcher workforceMatcher = WORKFORCE_PATTERN .matcher (getAudience ());
635+ Matcher workloadMatcher = WORKLOAD_PATTERN .matcher (getAudience ());
636+
637+ if (workforceMatcher .matches ()) {
638+ String poolId = workforceMatcher .group ("pool" );
639+ return String .format (
640+ OAuth2Utils .IAM_CREDENTIALS_ALLOWED_LOCATIONS_URL_FORMAT_WORKFORCE_POOL ,
641+ getUniverseDomain (),
642+ poolId );
643+ } else if (workloadMatcher .matches ()) {
644+ String projectNumber = workloadMatcher .group ("project" );
645+ String poolId = workloadMatcher .group ("pool" );
646+ return String .format (
647+ OAuth2Utils .IAM_CREDENTIALS_ALLOWED_LOCATIONS_URL_FORMAT_WORKLOAD_POOL ,
648+ getUniverseDomain (),
649+ projectNumber ,
650+ poolId );
647651 } else {
648- Matcher matcher = WORKLOAD_PATTERN .matcher (getAudience ());
649- if (!matcher .matches ()) {
650- throw new IOException (
651- "The provided audience is not in the correct format for a workload identity pool." );
652- }
653- String projectNumber = matcher .group ("project" );
654- String poolId = matcher .group ("pool" );
655- return String .format (WORKLOAD_POOL_URL_FORMAT , projectNumber , poolId );
652+ throw new IOException (
653+ "The provided audience is not in a valid format for either a workload identity pool or a workforce pool." );
656654 }
657655 }
658656
0 commit comments