Skip to content

Extract shared ExtendedCacheKey helper to de-duplicate cache-key plumbing#1046

Merged
Robbie-Microsoft merged 1 commit into
devfrom
rginsburg/ext-cache-key-dedup
Jul 16, 2026
Merged

Extract shared ExtendedCacheKey helper to de-duplicate cache-key plumbing#1046
Robbie-Microsoft merged 1 commit into
devfrom
rginsburg/ext-cache-key-dedup

Conversation

@Robbie-Microsoft

Copy link
Copy Markdown
Contributor

Follow-up cleanup addressing review feedback on #1039. Stacked on rginsburg/client_claims (the #1039 branch); base auto-retargets to dev once #1039 merges.

The extended-cache-key storage/memoization/hash-delegation boilerplate was copy-pasted across four *Parameters classes: ClientCredentialParameters, OnBehalfOfParameters, UserFederatedIdentityCredentialParameters, and AuthorizationCodeParameters. This extracts it into one package-private ExtendedCacheKey helper (composition, not a base class -- avoids a construction-ordering hazard). 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. ClientClaimsTest, FmiTest (golden cross-SDK hash), UserFederatedIdentityCredentialTest, and ManagedIdentityTests all pass with identical counts.

…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>
@Robbie-Microsoft
Robbie-Microsoft requested a review from a team as a code owner July 16, 2026 19:34
@Robbie-Microsoft
Robbie-Microsoft changed the base branch from rginsburg/client_claims to dev July 16, 2026 19:53
@Robbie-Microsoft
Robbie-Microsoft requested a review from Copilot July 16, 2026 19:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ExtendedCacheKey helper that holds a SortedMap of cache-key components and memoizes the computed Base64URL(SHA-256) hash.
  • Updated ClientCredentialParameters, OnBehalfOfParameters, UserFederatedIdentityCredentialParameters, and AuthorizationCodeParameters to delegate computeExtCacheKeyHash() 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.

@Robbie-Microsoft

Copy link
Copy Markdown
Contributor Author

/azp run MSAL Java - Unit Tests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@Robbie-Microsoft
Robbie-Microsoft merged commit c2382ad into dev Jul 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants