GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: add impersonation credentials to ADC by liuchaoren · Pull Request #613 · googleapis/google-auth-library-java

This repository was archived by the owner on May 12, 2026. It is now read-only.

Conversation

@liuchaoren

@liuchaoren liuchaoren commented Mar 25, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #614 ☕️

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
liuchaoren added 4 commits March 22, 2021 18:09
@liuchaoren
ADC can load impersonation credentials
887c67d
@liuchaoren
Add tests for new features in ImpersonationCredentials
f98b61c
@liuchaoren
Merge remote-tracking branch 'upstream/master'
9f805fb
@liuchaoren
Add tests for GoogleCredentials
ebeba8b
@liuchaoren
liuchaoren requested a review from a team March 25, 2021 19:42
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Mar 25, 2021
@codecov

codecov Bot commented Mar 25, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

Merging #613 (55a0c61) into master (292e81a) will increase coverage by 0.38%.
The diff coverage is 89.18%.

❗ Current head 55a0c61 differs from pull request most recent head b5340d0. Consider uploading reports for the commit b5340d0 to get more accurate results
Impacted file tree graph

@@             Coverage Diff              @@
##             master     #613      +/-   ##
============================================
+ Coverage     83.59%   83.98%   +0.38%     
- Complexity      606      622      +16     
============================================
  Files            42       42              
  Lines          2712     2778      +66     
  Branches        289      295       +6     
============================================
+ Hits           2267     2333      +66     
+ Misses          303      300       -3     
- Partials        142      145       +3     
Impacted Files Coverage Δ Complexity Δ
...java/com/google/auth/oauth2/GoogleCredentials.java 63.26% <50.00%> (+1.56%) 12.00 <0.00> (+1.00)
...om/google/auth/oauth2/ImpersonatedCredentials.java 90.67% <90.00%> (+4.27%) 33.00 <17.00> (+17.00)
...google/auth/oauth2/ExternalAccountCredentials.java 98.46% <100.00%> (+0.70%) 27.00 <0.00> (-2.00) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3f90c81...b5340d0. Read the comment docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@liuchaoren liuchaoren changed the title Add impersonation credentials to ADC. feat: add impersonation credentials to ADC Mar 25, 2021
liuchaoren added 2 commits March 25, 2021 15:53
@liuchaoren
Fix linter errors
33f6db0
@liuchaoren
Fix linter errors in ImpersonatedCredentialsTest
8b38844
silvolu
silvolu reviewed Mar 30, 2021
View reviewed changes
Comment thread oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

silvolu
silvolu reviewed Mar 31, 2021
View reviewed changes
Comment thread oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread oauth2_http/javatests/com/google/auth/oauth2/GoogleCredentialsTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

elharo
elharo reviewed Mar 31, 2021
View reviewed changes
Comment thread oauth2_http/java/com/google/auth/oauth2/CredentialTypeException.java Outdated
import java.io.IOException;

/** Indicates that the provided credential has a unsupported type. */
public class CredentialTypeException extends IOException {

@elharo elharo Mar 31, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

  1. This doesn't feel like an IOException.
  2. This is untested. This class is simple but it suggests there's a code path elsewhere that should throw this that isn't tested.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren Apr 1, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I removed this customized exception and adopt the same strategy as

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java

Line 172 in a5150b5

throw new IOException(
to avoid introducing one more exception in the throw which will propagate to upper level code.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java Outdated
String serviceAccountImpersonationUrl = (String) json.get("service_account_impersonation_url");
String targetPrincipal = extractTargetPrincipal(serviceAccountImpersonationUrl);

List<String> delegates = (List<String>) json.get("delegates");

@elharo elharo Mar 31, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It looks like they're a lot of potential ClassCastExceptions here that are not being handled. Where does the json object come from?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren Apr 1, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The json object is passed from

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java

Line 149 in a5150b5

public static GoogleCredentials fromStream(
and it reads credential json file from disk. The json file is generated by gcloud which should be well-formatted and user shouldn't manually edit the file. We have done something similar in

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/ExternalAccountCredentials.java

Line 269 in a5150b5

String audience = (String) json.get("audience");

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@elharo elharo Apr 2, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The code should check this input and be prepared to handle a malformed or invalid file. It does not know where the file came from or how it might have been modified since it was generated. Do not assume it has the format you expect. Even if it's right today, the output of gcloud could change in the future.

If other code already makes this mistake, it should be fixed too.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren Apr 2, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

fair enough, thanks for pointing this out! I added the exception handling and added a test to cover it. Please take another look.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
liuchaoren added 3 commits April 1, 2021 13:30
@liuchaoren
Fix issues after receiving comments
3a98164
@liuchaoren
Merge remote-tracking branch 'upstream/master'
ea3d14a
@liuchaoren
Fix lint errors
815e39b
elharo
elharo previously requested changes Apr 2, 2021
View reviewed changes
Comment thread oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java Outdated
String serviceAccountImpersonationUrl = (String) json.get("service_account_impersonation_url");
String targetPrincipal = extractTargetPrincipal(serviceAccountImpersonationUrl);

List<String> delegates = (List<String>) json.get("delegates");

@elharo elharo Apr 2, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The code should check this input and be prepared to handle a malformed or invalid file. It does not know where the file came from or how it might have been modified since it was generated. Do not assume it has the format you expect. Even if it's right today, the output of gcloud could change in the future.

If other code already makes this mistake, it should be fixed too.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
liuchaoren added 3 commits April 2, 2021 14:48
@liuchaoren
Handle ClassCastException in fromJson
0ee39aa
@liuchaoren
Fix lint errors
35b347a
@liuchaoren
minor refactoring
56ed2bb
@liuchaoren
liuchaoren requested a review from elharo April 2, 2021 19:12
elharo
elharo reviewed Apr 2, 2021
View reviewed changes
Comment thread oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java Outdated
static final String QUOTA_PROJECT_ID_HEADER_KEY = "x-goog-user-project";
static final String USER_FILE_TYPE = "authorized_user";
static final String SERVICE_ACCOUNT_FILE_TYPE = "service_account";
static final String IMPERSONATED_SERVICE_ACCOUNT = "impersonated_service_account";

@elharo elharo Apr 2, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This constant does not improve on the literal string. I suggest just using the string.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren Apr 2, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I am debating on these two options. I think even though the constant is not more readable than the string itself. I like the way we define all credential types in one place. So people can see all supported types there. I am not very familiar with Java convention, I trust your judgement on this. Please let me know if you still want me to make this change.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@elharo elharo Apr 7, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

That's something that belongs in documentation. Don't rely on the code for that.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren Apr 23, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java Outdated

/**
* @param sourceCredentials the source credential used as to acquire the impersonated credentials
* @param sourceCredentials the source credential used as to acquire the impersonated credentials.

@elharo elharo Apr 2, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

delete "as",
delete final period since it's not a complete sentence

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren Apr 2, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java Outdated

/**
* @param sourceCredentials the source credential used as to acquire the impersonated credentials
* @param sourceCredentials the source credential used as to acquire the impersonated credentials.

@elharo elharo Apr 2, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

delete "as",
delete final period since it's not a complete sentence

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren Apr 2, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@elharo
elharo dismissed their stale review April 2, 2021 22:00

resolved

liuchaoren added 2 commits April 2, 2021 18:09
@liuchaoren
fix doc strings
a36da60
@liuchaoren
fix lint errors
1b3bcd6
silvolu
silvolu approved these changes Apr 2, 2021
View reviewed changes

@silvolu silvolu left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Please make sure you get approval from @elharo before merging.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
liuchaoren added 2 commits April 2, 2021 23:55
@liuchaoren
delegates can be missing from the json file
685ea43
@liuchaoren
Mark test using @test()
3a20de4
elharo
elharo previously requested changes Apr 7, 2021
View reviewed changes
Comment thread oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java Outdated
static final String QUOTA_PROJECT_ID_HEADER_KEY = "x-goog-user-project";
static final String USER_FILE_TYPE = "authorized_user";
static final String SERVICE_ACCOUNT_FILE_TYPE = "service_account";
static final String IMPERSONATED_SERVICE_ACCOUNT = "impersonated_service_account";

@elharo elharo Apr 7, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

That's something that belongs in documentation. Don't rely on the code for that.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread oauth2_http/javatests/com/google/auth/oauth2/ImpersonatedCredentialsTest.java Outdated
assertEquals(QUOTA_PROJECT_ID, credentials.getQuotaProjectId());
assertEquals(DELEGATES, credentials.getDelegates());
assertEquals(new ArrayList<String>(), credentials.getScopes());
assertEquals(credentials.getLifetime(), 3600);

@elharo elharo Apr 7, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

expected value comes first; swap the arguments

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren Apr 23, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done. I made the change in new commits to my branch https://github.com/liuchaoren/google-auth-library-java which should update the PR automatically. Somehow the new commits do not show up in the PR. There might be some lag. I will keep an eye on it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren Apr 23, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

New commits show up in the PR now.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread oauth2_http/javatests/com/google/auth/oauth2/ImpersonatedCredentialsTest.java Outdated
assertNull(credentials.getQuotaProjectId());
assertEquals(new ArrayList<String>(), credentials.getDelegates());
assertEquals(new ArrayList<String>(), credentials.getScopes());
assertEquals(credentials.getLifetime(), 3600);

@elharo elharo Apr 7, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

expected value comes first; swap the arguments

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren Apr 23, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread oauth2_http/javatests/com/google/auth/oauth2/ImpersonatedCredentialsTest.java Outdated
assertNull(credentials.getQuotaProjectId());
assertEquals(DELEGATES, credentials.getDelegates());
assertEquals(new ArrayList<String>(), credentials.getScopes());
assertEquals(credentials.getLifetime(), 3600);

@elharo elharo Apr 7, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

expected value comes first; swap the arguments

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren Apr 23, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread oauth2_http/javatests/com/google/auth/oauth2/ImpersonatedCredentialsTest.java Outdated
assertEquals(QUOTA_PROJECT_ID, credentials.getQuotaProjectId());
assertEquals(DELEGATES, credentials.getDelegates());
assertEquals(new ArrayList<String>(), credentials.getScopes());
assertEquals(credentials.getLifetime(), 3600);

@elharo elharo Apr 7, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

expected value comes first; swap the arguments

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren Apr 23, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java Outdated
return this;
}

public String getQuotaProjectId() {

@elharo elharo Apr 7, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This method is not tested. Is it needed at all? It can probably be removed at no loss.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren Apr 23, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for pointing it out! It is not used and I removed it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java Outdated
} catch (ClassCastException | NullPointerException e) {
throw new CredentialFormatException("An invalid input stream was provided.", e);
}
String targetPrincipal = extractTargetPrincipal(serviceAccountImpersonationUrl);

@elharo elharo Apr 7, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

need to handle the IllegalArgumentException here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren Apr 23, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks, it is handled.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@liuchaoren
Merge remote-tracking branch 'upstream/master'
3ac3809
@liuchaoren
Fix docstring and move one variable to inner scope.
2febd2a
@liuchaoren
liuchaoren requested a review from elharo May 5, 2021 14:06
@elharo
Merge branch 'master' into master
3402664
elharo
elharo approved these changes May 5, 2021
View reviewed changes
@elharo
Merge branch 'master' into master
eee39af
elharo
elharo reviewed May 10, 2021
View reviewed changes
Comment thread oauth2_http/javatests/com/google/auth/oauth2/ImpersonatedCredentialsTest.java Outdated
USER_ACCOUNT_CLIENT_ID,
USER_ACCOUNT_CLIENT_SECRET,
REFRESH_TOKEN);
MockIAMCredentialsServiceTransportFactory mtransportFactory =

@elharo elharo May 10, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

mockTransportFactory because style does not abbreviate in variable names

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren May 11, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread oauth2_http/javatests/com/google/auth/oauth2/ImpersonatedCredentialsTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread oauth2_http/javatests/com/google/auth/oauth2/ImpersonatedCredentialsTest.java Outdated
USER_ACCOUNT_CLIENT_SECRET,
REFRESH_TOKEN);
json.remove("delegates");
MockIAMCredentialsServiceTransportFactory mtransportFactory =

@elharo elharo May 10, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

mockTransportFactory

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren May 11, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread oauth2_http/javatests/com/google/auth/oauth2/ImpersonatedCredentialsTest.java Outdated
public void fromJson_ServiceAccountAsSource() throws IOException {
GenericJson json =
buildImpersonationCredentialsJson(IMPERSONATION_URL, DELEGATES, QUOTA_PROJECT_ID);
MockIAMCredentialsServiceTransportFactory mtransportFactory =

@elharo elharo May 10, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

mockTransportFactory

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren May 11, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread oauth2_http/javatests/com/google/auth/oauth2/ImpersonatedCredentialsTest.java Outdated
@Test()
public void fromJson_InvalidFormat() throws IOException {
GenericJson json = buildInvalidCredentialsJson();
MockIAMCredentialsServiceTransportFactory mtransportFactory =

@elharo elharo May 10, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

mockTransportFactory

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren May 11, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread oauth2_http/javatests/com/google/auth/oauth2/ImpersonatedCredentialsTest.java Outdated
@Test()
public void createScoped() throws IOException {
GoogleCredentials sourceCredentials = getSourceCredentials();
MockIAMCredentialsServiceTransportFactory mtransportFactory =

@elharo elharo May 10, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

mockTransportFactory

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren May 11, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread oauth2_http/javatests/com/google/auth/oauth2/ImpersonatedCredentialsTest.java Outdated
public void getRequestMetadata_withQuotaProjectId() throws IOException, IllegalStateException {

GoogleCredentials sourceCredentials = getSourceCredentials();
MockIAMCredentialsServiceTransportFactory mtransportFactory =

@elharo elharo May 10, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

mockTransportFactory

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren May 11, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread oauth2_http/javatests/com/google/auth/oauth2/ImpersonatedCredentialsTest.java Outdated
@Test()
public void getRequestMetadata_withQuotaProjectId() throws IOException, IllegalStateException {

GoogleCredentials sourceCredentials = getSourceCredentials();

@elharo elharo May 10, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

You might be able to move these two lines into a fixture. They are repeated a lot.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren May 11, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread oauth2_http/javatests/com/google/auth/oauth2/ImpersonatedCredentialsTest.java Outdated
public void getRequestMetadata_withoutQuotaProjectId() throws IOException, IllegalStateException {

GoogleCredentials sourceCredentials = getSourceCredentials();
MockIAMCredentialsServiceTransportFactory mtransportFactory =

@elharo elharo May 10, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

mockTransportFactory

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren May 11, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread oauth2_http/javatests/com/google/auth/oauth2/ImpersonatedCredentialsTest.java Outdated

private String getDefaultExpireTime() {
public static String getDefaultExpireTime() {
Date currentDate = new Date();

@elharo elharo May 10, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

why set the date? Calendar.getInstance is already the current time.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren May 11, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
liuchaoren added 4 commits May 10, 2021 23:17
@liuchaoren
Merge remote-tracking branch 'upstream/master'
b2751ae
@liuchaoren
Refactor ImpersonatedCredentialsTest
8420528
@liuchaoren
Merge branch 'master' of github.com:liuchaoren/google-auth-library-java
51525ab
@liuchaoren
Reformat the ImpersonatedCredentialsTest
d34dae2
@liuchaoren
liuchaoren requested a review from elharo May 11, 2021 04:45
elharo
elharo reviewed May 11, 2021
View reviewed changes
Comment thread oauth2_http/javatests/com/google/auth/oauth2/GoogleCredentialsTest.java Outdated
GoogleCredentials.fromStream(impersonationCredentialsStream, transportFactoryForSource);
credentials.setTransportFactory(transportFactory);

assertNotNull(credentials);

@elharo elharo May 11, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Line 333 will have already thrown a NullPointerException if credentials is null so you can remove this

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren May 12, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread oauth2_http/javatests/com/google/auth/oauth2/GoogleCredentialsTest.java Outdated
GoogleCredentials.fromStream(impersonationCredentialsStream, transportFactoryForSource);
credentials.setTransportFactory(transportFactory);

assertNotNull(credentials);

@elharo elharo May 11, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Line 298 will have already thrown a NullPointerException if credentials is null so you can remove this assertNotNull

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren May 12, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java
}

@Override
public boolean createScopedRequired() {

@elharo elharo May 11, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This name doesn't quite fit. Create tends t be a factory method. This is more of an is method. Is this new in this PR?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren May 12, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This method is not invented in this PR. It is defined in the base class 'GoogleCredentials' which is overridden by its subclasses. I think it uses "create" in its name because of its relationship with the createScoped method.

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java

Line 218 in 292e81a

* Indicates whether the credentials require scopes to be specified via a call to {@link

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
elharo
elharo reviewed May 11, 2021
View reviewed changes
Comment thread oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java Outdated
return this.quotaProjectId;
}

public List<String> getDelegates() {

@elharo elharo May 11, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This method doesn't seem used. Can it be removed?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren May 12, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This method is used in tests to verify the delegates.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@elharo elharo May 12, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

In that case please annotate it as @VisibleForTesting. Also, make it non-public if possible. (It might not be but worth checking.)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@liuchaoren liuchaoren May 12, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Great, thanks for letting me know the annotation! I added it and removed the "public" to limit the visibility.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@liuchaoren
Remove redundant checks in tests
4ea84e9
@liuchaoren
liuchaoren requested a review from elharo May 12, 2021 19:45
@liuchaoren
Use VisibleForTesting annotation to limit visibility
55a0c61
elharo
elharo approved these changes May 12, 2021
View reviewed changes
@elharo
Merge branch 'master' into master
2884531
elharo
elharo reviewed May 19, 2021
View reviewed changes

@elharo elharo left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Github actions was having trouble yesterday systemwide. Might be fixed now. I pushed the button to rerun.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
elharo added 3 commits May 20, 2021 15:04
@elharo
Merge branch 'master' into master
35206dc
@elharo
Merge branch 'master' into master
6ea5150
@elharo
Merge branch 'master' into master
b5340d0
@liuchaoren
liuchaoren merged commit b9823f7 into googleapis:master May 21, 2021
gcf-merge-on-green Bot pushed a commit that referenced this pull request Jul 14, 2021
@release-please
chore: release 0.27.0 (#678)
90c24b1
🤖 I have created a release \*beep\* \*boop\*
---
## [0.27.0](https://www.github.com/googleapis/google-auth-library-java/compare/v0.26.0...v0.27.0) (2021-07-14)


### Features

* add Id token support for UserCredentials ([#650](https://www.github.com/googleapis/google-auth-library-java/issues/650)) ([5a8f467](https://www.github.com/googleapis/google-auth-library-java/commit/5a8f4676630854c53aa708a9c8b960770067f858))
* add impersonation credentials to ADC  ([#613](https://www.github.com/googleapis/google-auth-library-java/issues/613)) ([b9823f7](https://www.github.com/googleapis/google-auth-library-java/commit/b9823f70d7f3f7461b7de40bee06f5e7ba0e797c))
* Adding functional tests for Service Account  ([#685](https://www.github.com/googleapis/google-auth-library-java/issues/685)) ([dfe118c](https://www.github.com/googleapis/google-auth-library-java/commit/dfe118c261aadf137a3cf47a7acb9892c7a6db4d))
* allow scopes for self signed jwt ([#689](https://www.github.com/googleapis/google-auth-library-java/issues/689)) ([f4980c7](https://www.github.com/googleapis/google-auth-library-java/commit/f4980c77566bbd5ef4c532acb199d7d484dbcd01))
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
lsirac added a commit that referenced this pull request Jul 22, 2021
@lsirac Timur Sadykov
@arithmetic1728 @release-please
test: adds integration tests for downscoping with credential access b…
b26f8a4
…oundaries (#698)

* feat: Adding functional tests for Service Account  (#685)

ServiceAccountCredentials tests for 4110

* feat: allow scopes for self signed jwt (#689)

* feat: self signed jwt support

* update

* address comments

* allow to use uri as audience

* address comments

* chore: release 0.27.0 (#678)

:robot: I have created a release \*beep\* \*boop\*
---
## [0.27.0](https://www.github.com/googleapis/google-auth-library-java/compare/v0.26.0...v0.27.0) (2021-07-14)


### Features

* add Id token support for UserCredentials ([#650](https://www.github.com/googleapis/google-auth-library-java/issues/650)) ([5a8f467](https://www.github.com/googleapis/google-auth-library-java/commit/5a8f4676630854c53aa708a9c8b960770067f858))
* add impersonation credentials to ADC  ([#613](https://www.github.com/googleapis/google-auth-library-java/issues/613)) ([b9823f7](https://www.github.com/googleapis/google-auth-library-java/commit/b9823f70d7f3f7461b7de40bee06f5e7ba0e797c))
* Adding functional tests for Service Account  ([#685](https://www.github.com/googleapis/google-auth-library-java/issues/685)) ([dfe118c](https://www.github.com/googleapis/google-auth-library-java/commit/dfe118c261aadf137a3cf47a7acb9892c7a6db4d))
* allow scopes for self signed jwt ([#689](https://www.github.com/googleapis/google-auth-library-java/issues/689)) ([f4980c7](https://www.github.com/googleapis/google-auth-library-java/commit/f4980c77566bbd5ef4c532acb199d7d484dbcd01))
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).

* test: adds integration tests for downscoping with credential access boundaries

Co-authored-by: Timur Sadykov <[email protected]>
Co-authored-by: arithmetic1728 <[email protected]>
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
lsirac added a commit that referenced this pull request Jul 26, 2021
@lsirac Timur Sadykov
@arithmetic1728 @release-please
fix: use source credential expiration when STS does not return expire…
4b23843
…s_in (#699)

* feat: Adding functional tests for Service Account  (#685)

ServiceAccountCredentials tests for 4110

* feat: allow scopes for self signed jwt (#689)

* feat: self signed jwt support

* update

* address comments

* allow to use uri as audience

* address comments

* chore: release 0.27.0 (#678)

:robot: I have created a release \*beep\* \*boop\*
---
## [0.27.0](https://www.github.com/googleapis/google-auth-library-java/compare/v0.26.0...v0.27.0) (2021-07-14)


### Features

* add Id token support for UserCredentials ([#650](https://www.github.com/googleapis/google-auth-library-java/issues/650)) ([5a8f467](https://www.github.com/googleapis/google-auth-library-java/commit/5a8f4676630854c53aa708a9c8b960770067f858))
* add impersonation credentials to ADC  ([#613](https://www.github.com/googleapis/google-auth-library-java/issues/613)) ([b9823f7](https://www.github.com/googleapis/google-auth-library-java/commit/b9823f70d7f3f7461b7de40bee06f5e7ba0e797c))
* Adding functional tests for Service Account  ([#685](https://www.github.com/googleapis/google-auth-library-java/issues/685)) ([dfe118c](https://www.github.com/googleapis/google-auth-library-java/commit/dfe118c261aadf137a3cf47a7acb9892c7a6db4d))
* allow scopes for self signed jwt ([#689](https://www.github.com/googleapis/google-auth-library-java/issues/689)) ([f4980c7](https://www.github.com/googleapis/google-auth-library-java/commit/f4980c77566bbd5ef4c532acb199d7d484dbcd01))
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).

* test: adds integration tests for downscoping with credential access boundaries

* fix: STS does not always return expires_in, fallback to source credential expiration for DownscopedCredentials

* fix: review

Co-authored-by: Timur Sadykov <[email protected]>
Co-authored-by: arithmetic1728 <[email protected]>
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
@codyoss codyoss mentioned this pull request Sep 3, 2021
impersonated_service_account do not take into account golang/oauth2#515
Closed
@quartzmo quartzmo mentioned this pull request Nov 15, 2021
Add full support for service account impersonation googleapis/google-auth-library-ruby#353
Closed
@release-please release-please Bot mentioned this pull request Jan 4, 2022
chore(main): release google-auth-library-java 1.0.0 #819
Closed
@release-please release-please Bot mentioned this pull request Aug 11, 2022
chore(main): release 1.11.0 #974
Merged
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

2 more reviewers
@elharo elharo elharo approved these changes
@silvolu silvolu silvolu approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

ADC can load a json of impersonated service account credentials generated by gcloud

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@liuchaoren @silvolu @elharo
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.