oscerd opened a new pull request, #27767: URL: https://github.com/apache/camel/pull/27767
## Motivation Follow-up to CAMEL-24831 (MCP identity propagation, 4.23.0). Over the MCP server the authenticated caller reaches the tool route only as the **raw** transport principal — the `CamelMcpSecurityPrincipal` exchange property, which for the Vert.x streamable HTTP server is an `io.vertx.ext.auth.User`. Camel's shipped identity policies (Keycloak, Spring Security, Shiro) and most route guards cannot read that runtime-specific object, so an identity-based policy cannot authorize an MCP tool call out of the box. ## Change Expose a **runtime-neutral view** of the caller alongside the raw principal, derived by the engine from the transport user: - `CamelMcpSecurityPrincipalName` (`String`) — for the Vert.x server, the user subject (or the `username`/`sub` claim); - `CamelMcpSecurityPrincipalRoles` (`Collection<String>`) — read from the principal's `roles`, Keycloak `realm_access.roles`, or `groups` claim. A tool route or its `AuthorizationPolicy` can now authorize on a stable name and roles regardless of the MCP server runtime. Each property is stamped **only when the server could determine it**, so a policy should treat a missing name/roles as unauthorized. A custom policy can still read the raw `CamelMcpSecurityPrincipal` when it knows the runtime type. ### API `McpToolCallContext` gains `principalName` and `principalRoles` record components. The existing single-argument constructor is kept, so the 4.23 API stays backward compatible; the roles are defensively copied into an immutable collection. ### Scope This exposes the neutral view (for route authors and custom policies). Wiring the shipped policies (Keycloak, Spring Security, Shiro) to consume it automatically is intentionally left as a follow-up. ## Testing - `VertxMcpPrincipalTest` — unit tests for name/roles extraction: `username`/`sub` precedence, the `roles` / `realm_access.roles` / `groups` claims and their precedence, blank/non-string filtering, and null/empty → `null`. - `McpServerMainAuthenticationTest` — new end-to-end assertion that a tool route invoked over MCP sees `CamelMcpSecurityPrincipalName` for the basic-auth caller (`name=camel`). - `camel-mcp-server` + `camel-mcp-server-api` module build green (56 tests, 0 failures). Docs updated in `ai-tool-component.adoc` (+ catalog mirror). Targets 4.24.0. _Claude Code on behalf of oscerd_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
