提交 55c1a4d9 作者: 方治民

feat: websocket 连接信息优化记录 token 方便找到用户信息

上级 150f913b
......@@ -32,6 +32,7 @@ public class StompPrincipal implements Principal, Serializable {
Type type;
String user;
String token;
String session;
JSONObject options;
......
......@@ -55,6 +55,7 @@ public class ClientInboundChannelInterceptor implements ChannelInterceptor {
if (tokens instanceof Collection<?>) {
String token = Convert.toList(String.class, tokens).get(0);
User user = auths.getUserByToken(token);
principal.setToken(token);
principal.setUser(user.getRealName());
principal.setType(StompPrincipal.Type.LOGIN_USER);
} else {
......@@ -66,10 +67,11 @@ public class ClientInboundChannelInterceptor implements ChannelInterceptor {
synchronized (lock) {
redis.hset(RedisKey.STOMP_ONLINE_USERS, principal.getSession(), principal);
log.info(
"STOMP Online Users: {} (incr: +1, session: {}, user: `{}`)",
"STOMP Online Users: {} (incr: +1, user: {}, session: {}, token: {})",
redis.hsize(RedisKey.STOMP_ONLINE_USERS),
principal.getUser(),
principal.getSession(),
principal.getUser()
principal.getToken()
);
}
}
......@@ -79,10 +81,11 @@ public class ClientInboundChannelInterceptor implements ChannelInterceptor {
synchronized (lock) {
redis.hdel(RedisKey.STOMP_ONLINE_USERS, principal.getSession());
log.info(
"STOMP Online Users: {} (incr: -1, session: {}, user: `{}`)",
"STOMP Online Users: {} (incr: -1, user: {}, session: {}, token: {})",
redis.hsize(RedisKey.STOMP_ONLINE_USERS),
principal.getUser(),
principal.getSession(),
principal.getUser()
principal.getToken()
);
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论