登录
注册
开源
企业版
高校版
搜索
帮助中心
使用条款
关于我们
开源
企业版
高校版
私有云
模力方舟
AI 队友
登录
注册
代码拉取完成,页面将自动刷新
开源项目
>
程序开发
>
权限管理
&&
捐赠
捐赠前请先登录
取消
前往登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
Watch
不关注
关注所有动态
仅关注版本发行动态
关注但不提醒动态
422
Star
2.5K
Fork
1.1K
lunar landing
/
Pear Admin Boot
代码
Issues
39
Pull Requests
0
Wiki
统计
流水线
服务
JavaDoc
质量分析
Jenkins for Gitee
腾讯云托管
腾讯云 Serverless
悬镜安全
阿里云 SAE
Codeblitz
SBOM
我知道了,不再自动展开
更新失败,请稍后重试!
移除标识
内容风险标识
本任务被
标识为内容中包含有代码安全 Bug 、隐私泄露等敏感信息,仓库外成员不可访问
在线踢人BUG
待办的
#I60JED
ymm
创建于
2022-11-10 16:58
确定要踢出该用户 sessionRegistry.getAllSessions(userDetails, false)); 中 list<SessionInformation > size 数量为零 for (SessionInformation sessionInformation : sessionRegistry.getAllSessions(userDetails, false)){} 中 sessionRegistry.getAllSessions(userDetails, false); 返回list<SessionInformation> 但是数量为0 sessionRegistry.getAllSessions 的由子类 SessionRegistryImpl实现的方法如下 public List<SessionInformation> getAllSessions(Object principal, boolean includeExpiredSessions) { Set<String> sessionsUsedByPrincipal = (Set)this.principals.get(principal);//返回NULL if (sessionsUsedByPrincipal == null) { return Collections.emptyList(); } else {...} 中 (Set)this.principals.get(principal) 返回 Set<String> sessionsUsedByPrincipal 等于 null 暂时解决办法 * Describe: 用户领域模型 SysUser 类 重写 hashCode() ,equals()方法 // @Override public int hashCode() {return this.username.hashCode();} SessionListener 类 添加spring 管理 @Component注解 @WebListener public class SessionListener implements HttpSessionListener {} HttpSessionContext map 删除key value HttpSession invalidate方法删除 -------------------------------------------------- 类 ``` public class SysOnlineController /** * Describe: 踢出用户(下线) * Param: onlineId * Return: ModelAndView */ @ResponseBody @DeleteMapping("/remove/{onlineId}") public Result remove(@PathVariable String onlineId) { // 从sessionRegistry中获取所有的用户信息 List<Object> principals = sessionRegistry.getAllPrincipals(); for (Object principal : principals) { SysUser userDetails = (SysUser) principal; String userId = userDetails.getUserId(); if (onlineId.equals(userId)) { // 不允许操作admin用户下线 if ("admin".equals(userDetails.getUsername())) { return failure("不允许操作超级管理员[admin]下线"); } for (SessionInformation sessionInformation : sessionRegistry.getAllSessions(userDetails, false)) { // -- foreach 未能进入 size 为零 , SysUser hashcode()方法需要重写 // @Override public int hashCode() {return this.username.hashCode();} // sessionInformation.expireNow(); // 从sessionRegistry中清除session信息 sessionRegistry.removeSessionInformation(sessionInformation.getSessionId()); HttpSessionContext sessionContext = HttpSessionContextHolder.currentSessionContext(); // 销毁session sessionContext.getSession(sessionInformation.getSessionId()).invalidate(); } return success(String.format("用户[%s]已下线", userDetails.getRealName())); } } return failure(); } ```
确定要踢出该用户 sessionRegistry.getAllSessions(userDetails, false)); 中 list<SessionInformation > size 数量为零 for (SessionInformation sessionInformation : sessionRegistry.getAllSessions(userDetails, false)){} 中 sessionRegistry.getAllSessions(userDetails, false); 返回list<SessionInformation> 但是数量为0 sessionRegistry.getAllSessions 的由子类 SessionRegistryImpl实现的方法如下 public List<SessionInformation> getAllSessions(Object principal, boolean includeExpiredSessions) { Set<String> sessionsUsedByPrincipal = (Set)this.principals.get(principal);//返回NULL if (sessionsUsedByPrincipal == null) { return Collections.emptyList(); } else {...} 中 (Set)this.principals.get(principal) 返回 Set<String> sessionsUsedByPrincipal 等于 null 暂时解决办法 * Describe: 用户领域模型 SysUser 类 重写 hashCode() ,equals()方法 // @Override public int hashCode() {return this.username.hashCode();} SessionListener 类 添加spring 管理 @Component注解 @WebListener public class SessionListener implements HttpSessionListener {} HttpSessionContext map 删除key value HttpSession invalidate方法删除 -------------------------------------------------- 类 ``` public class SysOnlineController /** * Describe: 踢出用户(下线) * Param: onlineId * Return: ModelAndView */ @ResponseBody @DeleteMapping("/remove/{onlineId}") public Result remove(@PathVariable String onlineId) { // 从sessionRegistry中获取所有的用户信息 List<Object> principals = sessionRegistry.getAllPrincipals(); for (Object principal : principals) { SysUser userDetails = (SysUser) principal; String userId = userDetails.getUserId(); if (onlineId.equals(userId)) { // 不允许操作admin用户下线 if ("admin".equals(userDetails.getUsername())) { return failure("不允许操作超级管理员[admin]下线"); } for (SessionInformation sessionInformation : sessionRegistry.getAllSessions(userDetails, false)) { // -- foreach 未能进入 size 为零 , SysUser hashcode()方法需要重写 // @Override public int hashCode() {return this.username.hashCode();} // sessionInformation.expireNow(); // 从sessionRegistry中清除session信息 sessionRegistry.removeSessionInformation(sessionInformation.getSessionId()); HttpSessionContext sessionContext = HttpSessionContextHolder.currentSessionContext(); // 销毁session sessionContext.getSession(sessionInformation.getSessionId()).invalidate(); } return success(String.format("用户[%s]已下线", userDetails.getRealName())); } } return failure(); } ```
评论 (
0
)
登录
后才可以发表评论
状态
待办的
待办的
进行中
已完成
已关闭
负责人
未设置
标签
未设置
标签管理
里程碑
未关联里程碑
未关联里程碑
Pull Requests
未关联
未关联
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
未关联
分支 (2)
标签 (47)
next
master
2.0.2
2.0.1
2.0.0
1.5.5
1.5.4
1.5.3
1.5.2
1.5.1
1.5.0
1.4.9
1.4.8.Release
1.4.7.Release
1.4.6.Release
1.4.5.Release
1.4.4.RELEASE
1.4.3.RELEASE
1.4.2.RELEASE
1.4.1.RELEASE
1.4.0.RELEASE
1.3.9.RELEASE
1.3.8.RELEASE
1.3.7.RELEASE
1.3.6.RELEASE
1.3.5.RELEASE
1.3.4.RELEASE
1.3.3.RELEASE
1.3.2.RELEASE
1.3.1.RELEASE
1.3.0.RELEASE
1.2.9.RELEASE
1.2.8.RELEASE
1.2.7.RELEASE
1.2.6.RELEASE
1.2.5.RELEASE
1.2.2.RELEASE
1.2.1.RELEASE
1.2.0.RELEASE
1.1.1.RELEASE
1.1.0.RELEASE
1.0.8.RELEASE
1.0.7.RELEASE
1.0.6.RELEASE
1.0.5.RELEASE
1.0.4.RELEASE
1.0.3.RELEASE
1.0.1.RELEASE
1.0.0.RELEASE
开始日期   -   截止日期
-
置顶选项
不置顶
置顶等级:高
置顶等级:中
置顶等级:低
优先级
不指定
严重
主要
次要
不重要
参与者(1)
Java
1
https://gitee.com/lunarlanding/pear-admin-boot.git
git@gitee.com:lunarlanding/pear-admin-boot.git
lunarlanding
pear-admin-boot
Pear Admin Boot
点此查找更多帮助
搜索帮助
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册