Extract shared ExtendedCacheKey helper to de-duplicate cache-key plumbing#1046
Merged
Conversation
…bing The extended-cache-key storage, memoization, and hash-delegation boilerplate was copy-pasted across four *Parameters classes (ClientCredential, OnBehalfOf, UserFederatedIdentityCredential, AuthorizationCode). Extract it into a shared package-private ExtendedCacheKey helper so each class keeps only its distinct buildCacheKeyComponents() logic. Also removes the unused cacheKeyComponents() getter (dead code, zero callers). Behavior-preserving: the hash algorithm (StringHelper.computeExtCacheKeyHash) and memoization semantics are unchanged. Addresses review feedback on #1039. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors MSAL4J’s “extended cache key” plumbing used by several confidential-client *Parameters types to isolate token-cache entries (e.g., by client_claims and fmi_path) by extracting the shared component storage + lazy hash memoization into a single package-private helper.
Changes:
- Introduced a package-private
ExtendedCacheKeyhelper that holds aSortedMapof cache-key components and memoizes the computed Base64URL(SHA-256) hash. - Updated
ClientCredentialParameters,OnBehalfOfParameters,UserFederatedIdentityCredentialParameters, andAuthorizationCodeParametersto delegatecomputeExtCacheKeyHash()to the helper. - Removed the unused
cacheKeyComponents()getter from the above parameter classes (confirmed no references remain in the repo).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ExtendedCacheKey.java | New helper that centralizes extended cache-key hash memoization logic. |
| msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ClientCredentialParameters.java | Delegates extended cache-key hash computation to ExtendedCacheKey and removes dead getter. |
| msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/OnBehalfOfParameters.java | Delegates extended cache-key hash computation to ExtendedCacheKey and removes dead getter. |
| msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/UserFederatedIdentityCredentialParameters.java | Delegates extended cache-key hash computation to ExtendedCacheKey and removes dead getter. |
| msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AuthorizationCodeParameters.java | Delegates extended cache-key hash computation to ExtendedCacheKey and removes dead getter. |
gladjohn
approved these changes
Jul 16, 2026
Contributor
Author
|
/azp run MSAL Java - Unit Tests |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
neha-bhargava
approved these changes
Jul 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Follow-up cleanup addressing review feedback on #1039. Stacked on
rginsburg/client_claims(the #1039 branch); base auto-retargets todevonce #1039 merges.The extended-cache-key storage/memoization/hash-delegation boilerplate was copy-pasted across four
*Parametersclasses:ClientCredentialParameters,OnBehalfOfParameters,UserFederatedIdentityCredentialParameters, andAuthorizationCodeParameters. This extracts it into one package-privateExtendedCacheKeyhelper (composition, not a base class -- avoids a construction-ordering hazard). Each class keeps only its distinctbuildCacheKeyComponents()logic. Also removes the unusedcacheKeyComponents()getter (dead code, zero callers).Behavior-preserving: the hash algorithm (
StringHelper.computeExtCacheKeyHash) and memoization semantics are unchanged.ClientClaimsTest,FmiTest(golden cross-SDK hash),UserFederatedIdentityCredentialTest, andManagedIdentityTestsall pass with identical counts.