@@ -28,11 +28,20 @@ public ProjectEventsInterceptor(AccessManager accessManager) {
2828 this .accessManager = accessManager ;
2929 }
3030
31+
3132 @ Override
3233 public Message <?> preSend (Message <?> message , MessageChannel channel ) {
3334 StompHeaderAccessor accessor = StompHeaderAccessor .wrap (message );
3435
35- if (SimpMessageType .SUBSCRIBE .equals (accessor .getCommand ().getMessageType ())) {
36+ // Only check authorization for SUBSCRIBE messages
37+ // getMessageType() can be null for heartbeat messages, non-STOMP frames, or internal messages
38+ if (SimpMessageType .SUBSCRIBE .equals (accessor .getMessageType ())) {
39+ String destination = accessor .getDestination ();
40+ if (destination == null || destination .isEmpty ()) {
41+ LOGGER .error ("Missing destination in SUBSCRIBE message" );
42+ throw new AuthorizationServiceException ("Missing destination in SUBSCRIBE message" );
43+ }
44+
3645 List <String > tokenHeaders = accessor .getNativeHeader ("token" );
3746 List <String > userIdHeaders = accessor .getNativeHeader ("userId" );
3847 if (tokenHeaders == null || tokenHeaders .isEmpty ()) {
@@ -41,17 +50,16 @@ public Message<?> preSend(Message<?> message, MessageChannel channel) {
4150 }
4251 if (userIdHeaders == null || userIdHeaders .isEmpty ()) {
4352 LOGGER .error ("Missing userId header" );
44-
4553 throw new AuthorizationServiceException ("Missing userId header" );
4654 }
4755 String token = tokenHeaders .get (0 );
4856 String userId = userIdHeaders .get (0 );
49- String projectId = extractProjectId (accessor . getDestination () );
57+ String projectId = extractProjectId (destination );
5058 LOGGER .info ("Validation subscription. User {} project {}" , userId , projectId );
5159
5260 var hasAccessToProject = accessManager .hasPermission (Subject .forUser (userId )
5361 , ProjectResource .forProject (ProjectId .valueOf (projectId )), BuiltInCapability .VIEW_PROJECT ,
54- new ExecutionContext (UserId .valueOf (userId ), token , UUID .randomUUID ().toString ()));
62+ new ExecutionContext (UserId .valueOf (userId ), token , UUID .randomUUID ().toString ()));
5563
5664 if (!hasAccessToProject ) {
5765 throw new AuthorizationServiceException ("User " + userId + " does not have access to project " + projectId );
0 commit comments