Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
basic-api-boot
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-api-boot
Commits
55c1a4d9
提交
55c1a4d9
authored
6月 21, 2023
作者:
方治民
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: websocket 连接信息优化记录 token 方便找到用户信息
上级
150f913b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
8 行增加
和
4 行删除
+8
-4
StompPrincipal.java
...main/java/com/yiring/websocket/domain/StompPrincipal.java
+1
-0
ClientInboundChannelInterceptor.java
...ebsocket/interceptor/ClientInboundChannelInterceptor.java
+7
-4
没有找到文件。
basic-websocket/src/main/java/com/yiring/websocket/domain/StompPrincipal.java
浏览文件 @
55c1a4d9
...
@@ -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
;
...
...
basic-websocket/src/main/java/com/yiring/websocket/interceptor/ClientInboundChannelInterceptor.java
浏览文件 @
55c1a4d9
...
@@ -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
.
get
User
()
principal
.
get
Token
()
);
);
}
}
}
}
...
@@ -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
.
get
User
()
principal
.
get
Token
()
);
);
}
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论