ramu11 commented on code in PR #2094:
URL: 
https://github.com/apache/camel-spring-boot/pull/2094#discussion_r4577158468


##########
components-starter/camel-mcp-server-starter/src/main/java/org/apache/camel/springboot/mcp/server/SpringAiMcpTransportContext.java:
##########
@@ -0,0 +1,294 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.springboot.mcp.server;
+
+import java.lang.reflect.Method;
+import java.security.Principal;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import io.modelcontextprotocol.common.McpTransportContext;
+import io.modelcontextprotocol.server.McpSyncServerExchange;
+import org.apache.camel.component.mcp.server.McpToolCallContext;
+import org.springframework.web.servlet.function.ServerRequest;
+
+/**
+ * Captures the authenticated HTTP caller when Spring AI creates the MCP 
transport context,
+ * and makes that caller available to Camel tool execution.
+ * <p>
+ * The identity is taken from the servlet request principal established by the 
application's
+ * security infrastructure. It is not derived from MCP tool arguments or 
client-supplied
+ * identity headers.
+ * <p>
+ * Spring Security is optional for applications using this starter. Its APIs 
are accessed
+ * reflectively, and reflective accessors are cached per Authentication 
implementation.
+ * <p>
+ * Spring authorities with the ROLE_ prefix are exposed without that prefix. 
SCOPE_ authorities
+ * are mapped to OAuth scopes, and FACTOR_ authorities are not treated as 
application roles.
+ * When the principal is a JwtAuthenticationToken, its subject, scopes and 
claims are also
+ * propagated to the Camel tool exchange.
+ * <p>
+ * Applications that provide their own {@code 
WebMvcStreamableServerTransportProvider}
+ * can preserve caller identity by installing
+ * {@code .contextExtractor(SpringAiMcpTransportContext::extract)} on its 
builder.
+ */
+public final class SpringAiMcpTransportContext {
+
+    static final String CALL_CONTEXT_KEY =
+            SpringAiMcpTransportContext.class.getName() + ".toolCallContext";
+
+    private static final String AUTHENTICATION_CLASS =
+            "org.springframework.security.core.Authentication";
+    private static final String GRANTED_AUTHORITY_CLASS =
+            "org.springframework.security.core.GrantedAuthority";
+    private static final String JWT_AUTHENTICATION_CLASS =

Review Comment:
   Thanks for catching this. Fixed by resolving `getTokenAttributes()` from 
`AbstractOAuth2TokenAuthenticationToken` rather than relying on 
`JwtAuthenticationToken` specifically. This supports both JWT and opaque 
bearer-token authentication.
   
   I also added a regression test using `BearerTokenAuthentication` to verify 
that the OAuth subject, token attributes, roles, and scopes are correctly 
propagated into the Camel tool call context.



-- 
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]

Reply via email to