1717import jakarta .ws .rs .core .Context ;
1818import jakarta .ws .rs .core .MediaType ;
1919import jakarta .ws .rs .core .Response ;
20+ import jakarta .ws .rs .core .SecurityContext ;
2021import jakarta .ws .rs .ext .ExceptionMapper ;
2122import jakarta .ws .rs .ext .Provider ;
2223import jakarta .ws .rs .sse .Sse ;
@@ -91,9 +92,11 @@ public class A2AServerResource {
9192 @ POST
9293 @ Consumes (MediaType .APPLICATION_JSON )
9394 @ Produces (MediaType .APPLICATION_JSON )
94- public JSONRPCResponse <?> handleNonStreamingRequests (NonStreamingJSONRPCRequest <?> request ,
95- @ Context HttpServletRequest httpRequest ) {
96- ServerCallContext context = createCallContext (httpRequest );
95+ public JSONRPCResponse <?> handleNonStreamingRequests (
96+ NonStreamingJSONRPCRequest <?> request , @ Context HttpServletRequest httpRequest ,
97+ @ Context SecurityContext securityContext ) {
98+
99+ ServerCallContext context = createCallContext (httpRequest , securityContext );
97100 LOGGER .debug ("Handling non-streaming request" );
98101 try {
99102 return processNonStreamingRequest (request , context );
@@ -109,9 +112,11 @@ public JSONRPCResponse<?> handleNonStreamingRequests(NonStreamingJSONRPCRequest<
109112 @ POST
110113 @ Consumes (MediaType .APPLICATION_JSON )
111114 @ Produces (MediaType .SERVER_SENT_EVENTS )
112- public void handleStreamingRequests (StreamingJSONRPCRequest <?> request , @ Context SseEventSink sseEventSink ,
113- @ Context Sse sse , @ Context HttpServletRequest httpRequest ) {
114- ServerCallContext context = createCallContext (httpRequest );
115+ public void handleStreamingRequests (
116+ StreamingJSONRPCRequest <?> request , @ Context SseEventSink sseEventSink ,
117+ @ Context Sse sse , @ Context HttpServletRequest httpRequest ,
118+ @ Context SecurityContext securityContext ) {
119+ ServerCallContext context = createCallContext (httpRequest , securityContext );
115120 LOGGER .debug ("Handling streaming request" );
116121 executor .execute (() -> processStreamingRequest (request , sseEventSink , sse , context ));
117122 LOGGER .debug ("Submitted streaming request for async processing" );
@@ -235,29 +240,30 @@ public static void setStreamingIsSubscribedRunnable(Runnable streamingIsSubscrib
235240 A2AServerResource .streamingIsSubscribedRunnable = streamingIsSubscribedRunnable ;
236241 }
237242
238- private ServerCallContext createCallContext (HttpServletRequest request ) {
243+ private ServerCallContext createCallContext (HttpServletRequest request , SecurityContext securityContext ) {
239244
240245 if (callContextFactory .isUnsatisfied ()) {
241246 User user ;
242- if (request .getRemoteUser () == null ) {
247+
248+ if (securityContext .getUserPrincipal () == null ) {
243249 user = UnauthenticatedUser .INSTANCE ;
244250 } else {
245251 user = new User () {
246252 @ Override
247253 public boolean isAuthenticated () {
248- return false ;
254+ return true ;
249255 }
250256
251257 @ Override
252258 public String getUsername () {
253- return request . getRemoteUser ();
259+ return securityContext . getUserPrincipal (). getName ();
254260 }
255261 };
256262 }
257263 Map <String , Object > state = new HashMap <>();
258264 // TODO Python's impl has
259265 // state['auth'] = request.auth
260- // in jsonrpc_app.py. Figure out what this maps to in what Vert.X gives us
266+ // in jsonrpc_app.py. Figure out what this maps to in what we have here
261267
262268 Map <String , String > headers = new HashMap <>();
263269 for (Enumeration <String > headerNames = request .getHeaderNames (); headerNames .hasMoreElements () ; ) {
0 commit comments