Repository navigation
[2.0] fix(mcp): mcp claims mapping parser - #36213
Conversation
(cherry picked from commit e9d0281)
| } | ||
| } | ||
| return mapping; | ||
| return buildPrincipalClaimsMapping(authConfig.getJwtPrincipalClaimsMapping()); |
There was a problem hiding this comment.
buildPrincipalClaimsMapping is not colon-safe on 2.0. It still uses split(":") and drops entries with more than two parts. Both mappings in the new test therefore disappear, so the username becomes jdoe instead of employee42 and the test fails. Backport the shared parser change to split only at the first colon.
| @SuppressWarnings("unchecked") | ||
| private static Map<String, String> invokeGetClaimsMapping(McpCallbackServlet servlet) | ||
| throws Exception { | ||
| Method m = McpCallbackServlet.class.getDeclaredMethod("getClaimsMapping"); |
There was a problem hiding this comment.
Helper variable breaks naming rule
The new reflection helper names its method variable m. The repository guide forbids single-letter variables outside short lambdas and loop indices. Rename it to claimsMappingMethod before merging to meet that requirement.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| AuthenticationConfiguration authConfig = | ||
| new AuthenticationConfiguration() | ||
| .withJwtPrincipalClaimsMapping(List.of("username:custom:login", "email:custom:mail")); | ||
| Map<String, Object> claims = |
There was a problem hiding this comment.
New declarations omit required
final
The new test and helper omit final from variables and parameters that never change. The repository guide requires final in these cases. Apply it to the new declarations, including authConfig, claims, and the helper parameter, before merging.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Automated backport of #36171 to
2.0.e9d0281149a7cd22276d5783596d69549f9c9891Resolution notes
Backport notes: PR #36171 →
2.0Summary
Backports the colon-safe JWT principal claims mapping parser fix from
McpCallbackServlet.getClaimsMapping()(usesSecurityUtil.buildPrincipalClaimsMappinginstead of a naive
String.split(":"), which previously silently dropped anyclaim pair whose source claim name itself contains a colon, e.g.
username:custom:login).Conflicts and resolution
McpCallbackServlet.java— applied cleanly via cherry-pick, no conflict.SecurityUtil.buildPrincipalClaimsMappingalready exists on2.0.McpCallbackServletTest.java— conflicted. The2.0test file issignificantly smaller than the version on
main, which already containedseveral unrelated tests (
doGet_idpErrorCallback_*,bufferedResponseSendRedirect_records302Status, and their supportingfixtures
samplePendingRequest(),makeServletWithCapturedHandler(),mockCallbackRequest()) added by other PRs never backported to2.0. Thosetests reference types/helpers not present on
2.0(
OAuthRecords.McpPendingAuthRequest,Mockito.never(),ArgumentMatchers.any()/eq(),Assertions.assertEquals, agetStatusCode()helper) and are out of scope for this backport.
Resolution: kept only what PR fix(mcp): mcp claims mapping parser #36171 actually added — the single test
getClaimsMapping_keepsClaimNamesThatContainAColon()and its reflectionhelper
invokeGetClaimsMapping()(the latter merged cleanly withoutconflict) — and pruned the unrelated main-only tests/fixtures from the
conflict hunk. Trimmed imports to match: kept
mockStatic,findEmailFromClaims,findUserNameFromClaims,MockedStatic,AuthenticationConfiguration,SecurityConfigurationManager,List,Map; droppednever,OAuthRecords.McpPendingAuthRequest,any,eq,assertEqualssince nothing remaining in the2.0file needs them.What to check by hand
doGet_idpErrorCallback_*tests separately — if one is in flight, re-verify there's no duplicate test
name collision.
mvn test -pl openmetadata-mcp -Dtest=McpCallbackServletTestonce staged.Opened from openmetadata-collate, which holds the credentials needed to open a PR here. It merges itself once this branch's required checks pass — no review needed. If a check fails it stays open and the author of #36171 is asked to look.
resolver run
Do not merge until the shared parser fix is included and the new test code meets the repository requirements.
Findings
Summary
Routes MCP claim mapping through
SecurityUtil.buildPrincipalClaimsMappingand adds a regression test for claim names containing colons.Reviews (1) · Last reviewed commit: "fix(mcp): mcp claims mapping parser (#36..." · Reviewed by Greptile