Spring Security is very nice framework widely used for Authentication & Authorization.
I have a requirement in which the application to be authenticated using j_spring_security_check, and only authorized users can make request to websocket handler.
I have configured spring security as per http://malalanayake.wordpress.com/2014/06/27/spring-security-on-rest-api/
And I have configured websocket as per http://syntx.io/using-websockets-in-java-using-spring-4/.
I want MyPrincipal principal object to be accessed from handleTextMessage handler as per below:
@Override
protected void handleTextMessage(WebSocketSession session,
TextMessage message) throws Exception {
System.out.println("Protocol: "+session.getAcceptedProtocol());
TextMessage returnMessage = new TextMessage(message.getPayload()
+ " received at server");
System.out.println("myAttrib="
+ session.getAttributes().get("myAttrib"));
MyPrincipal user = (MyPrincipal) ((Authentication) session
.getPrincipal()).getPrincipal();
System.out.println("User: " + user.getUserId());
session.sendMessage(returnMessage);
}
Please replay ASAP.