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

4

1 回答 1

0

“链接”可以通过多种方式完成。

您可以通过以下方式在外部地图中链接此信息:

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

其中map可以是java.util.ConcurrentHashMap<String, ServerSession>安全策略本身的字段,也可以是其他对象(例如用户服务)中的字段。

对于更简单的用例,userName可以通过这种方式直接链接到会话:

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

或者您可以同时使用这两种技术。

这是认证方法的更新链接,您可以在http://docs.cometd.org找到最新的综合 CometD 文档。

于 2013-05-10T19:46:47.763 回答