提交 55c1a4d9 作者: 方治民

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

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