0

I'd like to store the clients UserName and SessionId when a client subscribes to a particular channel. When i override canHandshake() i can get the user credentials using the following:

userName = (String) authentication.get("userName");
sessionId = (String) authentication.get("sessionId");

Just wondering how i can store these credentials and later retrieve them? I've had a look at the authentication documentation here and it just mentions linking the authentication data to the session. Is this the Bayeux Server side session??

Thanks

user676567
  • 1,119
  • 9
  • 20
  • 39

1 Answers1

0

The "linking" can be done in several ways.

You can link this information in an external map via:

@Override
public boolean canHandshake(BayeuxServer server, ServerSession session, ServerMessage message)
{
    ...
    Map<String, Object> authentication = ...;
    map.put((String)authentication.get("userName"), session);
    ...
}

where the map can be a java.util.ConcurrentHashMap<String, ServerSession> field in the security policy itself, or in another object such as a user service.

For simpler use cases, the userName can be linked directly to the session in this way:

session.setAttribute("userName", authentication.get("userName"));

Or you can use both techniques.

This is the updated link for the authentication how-to, and you can find the latest comprehensive CometD documentation at http://docs.cometd.org.

sbordet
  • 16,856
  • 1
  • 50
  • 45