Make Access token cache public#49712
Conversation
Move AccessTokenCache from com.azure.core.implementation to the public com.azure.core.credential package, alongside SimpleTokenCache. The class is now part of the public API surface of azure-core. Changes: - Move AccessTokenCache.java to com.azure.core.credential package - Add comprehensive public JavaDoc - Update import in BearerTokenAuthenticationPolicy - Move AccessTokenCacheTests to com.azure.core.credential test package - Update import in TokenCacheTests
There was a problem hiding this comment.
Pull request overview
This PR promotes AccessTokenCache from the internal com.azure.core.implementation namespace into the public com.azure.core.credential API surface, and updates in-repo usages and tests accordingly.
Changes:
- Moved
AccessTokenCachetocom.azure.core.credentialand expanded its public JavaDoc. - Updated
BearerTokenAuthenticationPolicyand test code to reference the new public package. - Added a CHANGELOG entry documenting the newly-public API.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| sdk/core/azure-core/src/test/java/com/azure/core/credential/TokenCacheTests.java | Updates AccessTokenCache import to the new public package. |
| sdk/core/azure-core/src/test/java/com/azure/core/credential/AccessTokenCacheTests.java | Moves the test into the com.azure.core.credential package. |
| sdk/core/azure-core/src/main/java/com/azure/core/http/policy/BearerTokenAuthenticationPolicy.java | Updates the policy to import AccessTokenCache from the public credential package. |
| sdk/core/azure-core/src/main/java/com/azure/core/credential/AccessTokenCache.java | Promotes AccessTokenCache to a public package and adds extensive JavaDoc + sample. |
| sdk/core/azure-core/CHANGELOG.md | Documents the promotion of AccessTokenCache as a feature addition. |
Comments suppressed due to low confidence (2)
sdk/core/azure-core/src/test/java/com/azure/core/credential/AccessTokenCacheTests.java:8
- These imports are from the same package as the test (
com.azure.core.credential) and will be flagged by Checkstyle'sRedundantImportrule (seeeng/lintingconfigs/checkstyle/track2/checkstyle.xml:64-73). Remove the redundant imports.
sdk/core/azure-core/src/main/java/com/azure/core/credential/AccessTokenCache.java:53 - The embedded Javadoc sample contains very long lines (due to HTML entities) that are likely to exceed the repo's 120-character
LineLengthCheckstyle rule (seeeng/lintingconfigs/checkstyle/track2/checkstyle.xml:53-59). Please wrap the sample statements similarly to other credential samples to avoid Checkstyle failures.
…ix imports - Rename 'checkToForceFetchToken' to 'refreshOnContextChange' in public methods of AccessTokenCache, and propagate the rename to BearerTokenAuthenticationPolicy and PopTokenAuthenticationPolicy private helpers - Fix getTokenSync @return Javadoc (was incorrectly saying 'Publisher') - Add @throws IllegalArgumentException to both public getToken methods - Add thread-safety guarantee and single-context limitation to class Javadoc - Clarify refreshOnContextChange semantics and CAE use-case in class/param Javadoc - Fix constructor null-check error message to follow SDK convention - Fix internal null-check error messages to follow SDK convention - Add AccessTokenCacheJavadocCodeSnippets.java for the src_embed marker - Remove redundant same-package imports from AccessTokenCacheTests - Fix stale constructor Javadoc and broken import in PopTokenAuthenticationPolicy
…enAuthenticationPolicy PopTokenAuthenticationPolicy uses com.azure.core.credential.AccessTokenCache which is new in azure-core 1.59.0-beta.1. The azure-identity CI was building against the published azure-core 1.58.1 (which doesn't have the public class), causing a compile error. - Add azure-core to AdditionalModules in sdk/identity/ci.yml so the identity CI builds it from source before compiling azure-identity-broker - Add azure-core 1.59.0-beta.1 as a direct test dependency in azure-identity-broker pom so Maven resolves the locally built version over the transitive published one
- Use LOGGER.logThrowableAsError() instead of bare throw in retrieveTokenSync (ThrowFromClientLoggerCheck violation) - Remove unused java.time.OffsetDateTime import from AccessTokenCacheJavadocCodeSnippets (UnusedImportsCheck violation)
…retrieveTokenSync logThrowableAsError returns Throwable which cannot be thrown from a Supplier lambda. Supplier.get() only throws RuntimeException, so narrowing the catch is correct. Use logExceptionAsError which returns RuntimeException and compiles cleanly.
…e rethrowing Error subclasses (OutOfMemoryError etc.) should also be caught. Since the Supplier lambda can only propagate RuntimeException, non-RuntimeException Throwables are wrapped in RuntimeException before being thrown through LOGGER.logExceptionAsError.
vcolin7
left a comment
There was a problem hiding this comment.
Last time we spoke about making this class public you said you'd go back and revisit the design. It seems we're trying to make the class public as is. What other design choices did you explore and why did we go with simply exposing this class?
Making this class public is the first choice. |
Makes AccessTokenCache Public