0

I have Spring Stomp setup on a project, everything is working fine but I keep getting this as errors in the server logs.

2021-02-17 05:02:26.875 ERROR 23773 --- [oundChannel-914] o.s.w.s.m.StompSubProtocolHandler        : Error publishing SessionConnectedEvent[GenericMessage [payload=byte[0], headers={simpMessageType=CONNECT_ACK, simpConnectMessage=GenericMessage [payload=byte[0], headers={simpMessageType=CONNECT, stompCommand=CONNECT, nativeHeaders={x_from_wss=[true], accept-version=[1.1,1.0], heart-beat=[0,0]}, simpSessionAttributes={}, simpHeartbeat=[J@1dbcdf26, simpUser=org.springframework.security.authentication.UsernamePasswordAuthenticationToken@cda212a8: Principal: me.xxxx.xxx.user.security.UserLoginDetails@325d7812; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null; Not granted any authorities, simpSessionId=ml2gvecs}], simpUser=org.springframework.security.authentication.UsernamePasswordAuthenticationToken@cda212a8: Principal: me.xxxx.xxx.user.security.UserLoginDetails@325d7812; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null; Not granted any authorities, simpSessionId=ml2gvecs}]]

I tried setting up Event handlers for the websocket as well but still it continues to show up in the logs. I understand its an acknowledgement message on the connect from the client but it should not fail. Any advise will be much appreciated.

Shuja Ahmed
  • 752
  • 5
  • 17

1 Answers1

0

The error says:

Not granted any authorities

If you are using something like Spring Security, make sure to pass a collection of Granted Authorities, once authenticated.

You could do something like this

 UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken= new UsernamePasswordAuthenticationToken(
                "AuthenticatedUserName", "Credentials",  Collections.singleton((GrantedAuthority) () -> "USER")
        );

In case you are not using Spring Security, you could set up a Authenticated User Token via Channel Interceptor.

Follow thelink below, to see how you can setup Channel Interceptor for you WebSocket Connection

Websocket Authentication and Authorization in Spring

Bernerd
  • 68
  • 5