|
35 | 35 | import com.google.api.client.json.JsonFactory; |
36 | 36 | import com.google.api.client.json.JsonObjectParser; |
37 | 37 | import com.google.api.client.util.Preconditions; |
| 38 | +import com.google.api.core.InternalApi; |
38 | 39 | import com.google.api.core.ObsoleteApi; |
39 | 40 | import com.google.auth.Credentials; |
40 | 41 | import com.google.auth.http.HttpTransportFactory; |
@@ -111,9 +112,6 @@ String getFileType() { |
111 | 112 |
|
112 | 113 | protected final String quotaProjectId; |
113 | 114 |
|
114 | | - private static final LoggerProvider LOGGER_PROVIDER = |
115 | | - LoggerProvider.forClazz(GoogleCredentials.class); |
116 | | - |
117 | 115 | private static final DefaultCredentialsProvider defaultCredentialsProvider = |
118 | 116 | new DefaultCredentialsProvider(); |
119 | 117 |
|
@@ -337,50 +335,71 @@ public GoogleCredentials createWithQuotaProject(String quotaProject) { |
337 | 335 | } |
338 | 336 |
|
339 | 337 | @VisibleForTesting |
340 | | - public TrustBoundary getTrustBoundary() { |
| 338 | + TrustBoundary getTrustBoundary() { |
341 | 339 | return trustBoundary; |
342 | 340 | } |
343 | 341 |
|
| 342 | + /** |
| 343 | + * Returns whether the credentials support trust boundary. |
| 344 | + * |
| 345 | + * @return {@code true} if the credentials support trust boundary, {@code false} otherwise. |
| 346 | + */ |
344 | 347 | Boolean supportsTrustBoundary() { |
345 | 348 | return false; |
346 | 349 | } |
347 | 350 |
|
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) |
349 | 366 | throws IOException { |
350 | 367 |
|
351 | | - if (!supportsTrustBoundary() || !TrustBoundary.isTrustBoundaryEnabled() || !isDefaultUniverseDomain()) { |
352 | | - return; |
353 | | - } |
354 | | - |
355 | | - TrustBoundary cachedTrustBoundary; |
| 368 | + if (!supportsTrustBoundary() |
| 369 | + || !TrustBoundary.isTrustBoundaryEnabled() |
| 370 | + || !isDefaultUniverseDomain()) { |
| 371 | + return; |
| 372 | + } |
356 | 373 |
|
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; |
364 | 375 |
|
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()) { |
377 | 379 | return; |
378 | 380 | } |
| 381 | + cachedTrustBoundary = trustBoundary; |
| 382 | + } |
379 | 383 |
|
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); |
383 | 395 | } |
| 396 | + return; |
| 397 | + } |
| 398 | + |
| 399 | + // A lock is required to safely update the shared field. |
| 400 | + synchronized (lock) { |
| 401 | + trustBoundary = newTrustBoundary; |
| 402 | + } |
384 | 403 | } |
385 | 404 |
|
386 | 405 | /** |
|
0 commit comments