Skip to content

Commit f502c38

Browse files
committed
Formatting changes
1 parent e6491ec commit f502c38

File tree

4 files changed

+60
-42
lines changed

4 files changed

+60
-42
lines changed

oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ public String getAccount() {
708708

709709
@Override
710710
Boolean supportsTrustBoundary() {
711-
return true;
711+
return true;
712712
}
713713

714714
String getTrustBoundaryUrl() throws IOException {

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

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.google.api.client.json.JsonFactory;
3636
import com.google.api.client.json.JsonObjectParser;
3737
import com.google.api.client.util.Preconditions;
38+
import com.google.api.core.InternalApi;
3839
import com.google.api.core.ObsoleteApi;
3940
import com.google.auth.Credentials;
4041
import com.google.auth.http.HttpTransportFactory;
@@ -111,9 +112,6 @@ String getFileType() {
111112

112113
protected final String quotaProjectId;
113114

114-
private static final LoggerProvider LOGGER_PROVIDER =
115-
LoggerProvider.forClazz(GoogleCredentials.class);
116-
117115
private static final DefaultCredentialsProvider defaultCredentialsProvider =
118116
new DefaultCredentialsProvider();
119117

@@ -337,50 +335,71 @@ public GoogleCredentials createWithQuotaProject(String quotaProject) {
337335
}
338336

339337
@VisibleForTesting
340-
public TrustBoundary getTrustBoundary() {
338+
TrustBoundary getTrustBoundary() {
341339
return trustBoundary;
342340
}
343341

342+
/**
343+
* Returns whether the credentials support trust boundary.
344+
*
345+
* @return {@code true} if the credentials support trust boundary, {@code false} otherwise.
346+
*/
344347
Boolean supportsTrustBoundary() {
345348
return false;
346349
}
347350

348-
void refreshTrustBoundary(AccessToken newAccessToken, String trustBoundaryUrl, HttpTransportFactory transportFactory)
351+
/**
352+
* Refreshes the trust boundary by making a call to the trust boundary URL.
353+
*
354+
* <p>This method is for internal use only and should not be called by users directly. It is used
355+
* to enforce security policies by ensuring that the credentials used to access Google Cloud APIs
356+
* are not used outside a trusted environment.
357+
*
358+
* @param newAccessToken The new access token to be used for the refresh.
359+
* @param trustBoundaryUrl The URL of the trust boundary service.
360+
* @param transportFactory The HTTP transport factory to be used for the refresh.
361+
* @throws IOException If the refresh fails and no cached value is available.
362+
*/
363+
@InternalApi
364+
void refreshTrustBoundary(
365+
AccessToken newAccessToken, String trustBoundaryUrl, HttpTransportFactory transportFactory)
349366
throws IOException {
350367

351-
if (!supportsTrustBoundary() || !TrustBoundary.isTrustBoundaryEnabled() || !isDefaultUniverseDomain()) {
352-
return;
353-
}
354-
355-
TrustBoundary cachedTrustBoundary;
368+
if (!supportsTrustBoundary()
369+
|| !TrustBoundary.isTrustBoundaryEnabled()
370+
|| !isDefaultUniverseDomain()) {
371+
return;
372+
}
356373

357-
synchronized (lock) {
358-
// Do not refresh if the cached value is already NO_OP.
359-
if (trustBoundary != null && trustBoundary.isNoOp()) {
360-
return;
361-
}
362-
cachedTrustBoundary = trustBoundary;
363-
}
374+
TrustBoundary cachedTrustBoundary;
364375

365-
TrustBoundary newTrustBoundary;
366-
try {
367-
newTrustBoundary =
368-
TrustBoundary.refresh(
369-
transportFactory, trustBoundaryUrl, newAccessToken, cachedTrustBoundary);
370-
} catch (IOException e) {
371-
// If refresh fails, check for a cached value.
372-
if (cachedTrustBoundary == null) {
373-
// No cached value, so fail hard.
374-
throw new IOException(
375-
"Failed to refresh trust boundary and no cached value is available.", e);
376-
}
376+
synchronized (lock) {
377+
// Do not refresh if the cached value is already NO_OP.
378+
if (trustBoundary != null && trustBoundary.isNoOp()) {
377379
return;
378380
}
381+
cachedTrustBoundary = trustBoundary;
382+
}
379383

380-
// A lock is required to safely update the shared field.
381-
synchronized (lock) {
382-
trustBoundary = newTrustBoundary;
384+
TrustBoundary newTrustBoundary;
385+
try {
386+
newTrustBoundary =
387+
TrustBoundary.refresh(
388+
transportFactory, trustBoundaryUrl, newAccessToken, cachedTrustBoundary);
389+
} catch (IOException e) {
390+
// If refresh fails, check for a cached value.
391+
if (cachedTrustBoundary == null) {
392+
// No cached value, so fail hard.
393+
throw new IOException(
394+
"Failed to refresh trust boundary and no cached value is available.", e);
383395
}
396+
return;
397+
}
398+
399+
// A lock is required to safely update the shared field.
400+
synchronized (lock) {
401+
trustBoundary = newTrustBoundary;
402+
}
384403
}
385404

386405
/**

oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,10 @@ public GoogleCredentials getSourceCredentials() {
325325
return sourceCredentials;
326326
}
327327

328-
@Override
329-
Boolean supportsTrustBoundary() {
330-
return true;
331-
}
328+
@Override
329+
Boolean supportsTrustBoundary() {
330+
return true;
331+
}
332332

333333
String getTrustBoundaryUrl() throws IOException {
334334
return String.format(
@@ -341,7 +341,6 @@ int getLifetime() {
341341
return this.lifetime;
342342
}
343343

344-
345344
public void setTransportFactory(HttpTransportFactory httpTransportFactory) {
346345
this.transportFactory = httpTransportFactory;
347346
}

oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -823,10 +823,10 @@ public boolean getUseJwtAccessWithScope() {
823823
return useJwtAccessWithScope;
824824
}
825825

826-
@Override
827-
Boolean supportsTrustBoundary() {
828-
return true;
829-
}
826+
@Override
827+
Boolean supportsTrustBoundary() {
828+
return true;
829+
}
830830

831831
String getTrustBoundaryUrl() throws IOException {
832832
return String.format(

0 commit comments

Comments
 (0)