Wednesday, 15 February 2012

Grails Spring Websocket Plugin and spring security -



Grails Spring Websocket Plugin and spring security -

implementation here ( http://grails.org/plugin/spring-websocket ) working, spring security plugin doesn't recognize authenticated user. can imagine why doesn't work, did managed create springsecurityservice in controller recognize authenticated user ?

my controller looks :

class="snippet-code-html lang-html prettyprint-override">@secured('hasrole("role_user")') class websocketchatcontroller { springsecurityservice springsecurityservice def index() {} @messagemapping("/hello") @sendto("/topic/hello") protected string hello(string world) { homecoming "hello controller! ( character: " + springsecurityservice.currentuser + ")" } }

but springsecurityservice.currentuser null ...

try this:

@secured('hasrole("role_user")') class websocketchatcontroller { def index() {} @messagemapping("/hello") @sendto("/topic/hello") protected string hello(string world, principal principal) { homecoming "hello controller! ( character: " + principal.name + ")" } } }

as stated in docs, section 21.4.4 annotation message handling (http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html)

java.security.principal method arguments reflecting user logged in @ time of websocket http handshake.

principal contains currentuser, know springsecurity

grails spring-security websocket

No comments:

Post a Comment