Atmosphere: How to get logged in user from webSocket connection in Grails?
Asked Answered
S

1

9

I am working on bringing WebSockets functionality to my Grails application. I use Atmosphere Meteor plugin 0.7.1 for this purpose. The workflow is simple:

  • User logs in the system.
  • User open page with WebSockets functionality
  • User clicks a Connect button to establish the connection... and the server doesn't recognize him.

I would like to know which user connected my webSocket.

Usually it's quite easy to detect current user by calling springSecurityService.getPrincipal() in any controller. I managed to inject springSecurityService to my MeteorHandler, however it says that the principal is null. It feels strange for me, as the handler has access to JSESSIONID cookie, so I expect it to retrieve the correct session data.

Also, request.session command returns different HttpSession object, compared to the same command performed in regular controller action.

So is there any way to retrieve current logged in user on webSockets connection?

Thanks in advance.

Sora answered 7/2, 2014 at 16:48 Comment(0)
S
3

The Principal object could be easily retrieved from request.userPrincipal.principal

It is exactly the same object as in springSecurityService.getPrincipal()

Find more here: https://github.com/kensiprell/grails-atmosphere-meteor/issues/28#issuecomment-34629462

Sora answered 10/2, 2014 at 13:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.