diff --git a/oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java b/oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java index 2878d5d86..91e917a06 100644 --- a/oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java @@ -121,8 +121,8 @@ public class ImpersonatedCredentials extends GoogleCredentials * value should be at most 3600. However, you can follow these * instructions to set up the service account and extend the maximum lifetime to 43200 (12 - * hours). If the given lifetime is 0, default value 3600 will be used instead when creating the - * credentials. + * hours). If the given lifetime is 0, default value 3600 will be used instead when creating + * the credentials. * @param transportFactory HTTP transport factory that creates the transport used to get access * tokens * @return new credentials @@ -234,9 +234,6 @@ private ImpersonatedCredentials(Builder builder) { if (this.lifetime > TWELVE_HOURS_IN_SECONDS) { throw new IllegalStateException("lifetime must be less than or equal to 43200"); } - if (this.lifetime == 0) { - this.lifetime = DEFAULT_LIFETIME_IN_SECONDS; - } } @Override @@ -366,7 +363,7 @@ public static class Builder extends GoogleCredentials.Builder { private String targetPrincipal; private List delegates; private List scopes; - private int lifetime; + private int lifetime = DEFAULT_LIFETIME_IN_SECONDS; private HttpTransportFactory transportFactory; protected Builder() {} @@ -413,7 +410,7 @@ public List getScopes() { } public Builder setLifetime(int lifetime) { - this.lifetime = lifetime; + this.lifetime = lifetime == 0 ? DEFAULT_LIFETIME_IN_SECONDS : lifetime; return this; }