Skip to content

fix(auth): propagate universeDomain to JwtCredentials from service account credentials - #15189

Open
lqiu96 wants to merge 1 commit into
googleapis:mainfrom
lqiu96:fix/auth-sa-jwt-universe-domain-propagation
Open

lqiu96 wants to merge 1 commit into
googleapis:mainfrom
lqiu96:fix/auth-sa-jwt-universe-domain-propagation

Conversation

@lqiu96

@lqiu96 lqiu96 commented Nov 24, 2026

Copy link
Copy Markdown
Member

Follow-up to #15176 to propagate universeDomain when constructing JwtCredentials from service account credentials:

  • Updates ServiceAccountCredentials.jwtWithClaims() and createSelfSignedJwtCredentials() to pass the credential's universeDomain into the constructed JwtCredentials (wrapping checked IOException from getUniverseDomain() in IllegalStateException).
  • Updates ServiceAccountJwtAccessCredentials to initialize universeDomain before createCache() and pass universeDomain in createCache() and jwtWithClaims().
  • Adds unit tests in ServiceAccountCredentialsTest and ServiceAccountJwtAccessCredentialsTest.

@lqiu96
lqiu96 requested review from a team as code owners November 24, 2026 03:24

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request ensures that the universeDomain is correctly propagated when creating JWT credentials in both ServiceAccountCredentials and ServiceAccountJwtAccessCredentials, and adds corresponding unit tests to verify this behavior. The feedback suggests a minor improvement in ServiceAccountCredentials to use java.io.UncheckedIOException instead of IllegalStateException when wrapping the checked IOException in getUniverseDomainOrThrow(), which is more idiomatic in Java.

Comment on lines +1043 to +1049
private String getUniverseDomainOrThrow() {
try {
return getUniverseDomain();
} catch (IOException e) {
throw new IllegalStateException("Failed to retrieve universe domain.", e);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When wrapping a checked IOException in a runtime exception, it is more idiomatic in Java 8+ to use java.io.UncheckedIOException instead of IllegalStateException. This provides a more specific exception type for I/O-related failures and allows callers to easily catch and handle it specifically. Ensure that the original exception is preserved as the cause to maintain the exception chain.

Suggested change
private String getUniverseDomainOrThrow() {
try {
return getUniverseDomain();
} catch (IOException e) {
throw new IllegalStateException("Failed to retrieve universe domain.", e);
}
}
private String getUniverseDomainOrThrow() {
try {
return getUniverseDomain();
} catch (IOException e) {
throw new java.io.UncheckedIOException("Failed to retrieve universe domain.", e);
}
}
References
  1. When catching an exception and throwing a new exception, preserve the original exception as the cause to maintain the exception chain and aid in debugging.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant