From c62fdc92764dc0c7ffa15b77860ba20efc1c3171 Mon Sep 17 00:00:00 2001 From: click33 <2393584716@qq.com> Date: Tue, 10 Dec 2024 18:19:12 +0800 Subject: [PATCH] =?UTF-8?q?fix(core):=20=E4=BF=AE=E5=A4=8D=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=9C=BA=E6=99=AF=E4=B8=8B=E7=99=BB=E5=BD=95=E5=90=8E?= =?UTF-8?q?=E5=B7=B2=E5=AD=98=E5=9C=A8=E7=9A=84=20token-session=20?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E8=A2=AB=E7=BB=AD=E6=9C=9F=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8Cfixes=20#IA8U1O?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/cn/dev33/satoken/stp/StpLogic.java | 12 +++++++++--- .../src/main/java/com/pj/test/Test2Controller.java | 13 +++++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/sa-token-core/src/main/java/cn/dev33/satoken/stp/StpLogic.java b/sa-token-core/src/main/java/cn/dev33/satoken/stp/StpLogic.java index 57cfc2c3..0ea61b51 100644 --- a/sa-token-core/src/main/java/cn/dev33/satoken/stp/StpLogic.java +++ b/sa-token-core/src/main/java/cn/dev33/satoken/stp/StpLogic.java @@ -486,15 +486,21 @@ public class StpLogic { setLastActiveToNow(tokenValue, loginModel.getActiveTimeout(), loginModel.getTimeoutOrGlobalConfig()); } - // 8、$$ 发布全局事件:账号 xxx 登录成功 + // 8、如果该 token 对应的 Token-Session 已经存在,则需要给其续期 + SaSession tokenSession = getTokenSessionByToken(tokenValue, false); + if(tokenSession != null) { + tokenSession.updateMinTimeout(loginModel.getTimeout()); + } + + // 9、$$ 发布全局事件:账号 xxx 登录成功 SaTokenEventCenter.doLogin(loginType, id, tokenValue, loginModel); - // 9、检查此账号会话数量是否超出最大值,如果超过,则按照登录时间顺序,把最开始登录的给注销掉 + // 10、检查此账号会话数量是否超出最大值,如果超过,则按照登录时间顺序,把最开始登录的给注销掉 if(config.getMaxLoginCount() != -1) { logoutByMaxLoginCount(id, session, null, config.getMaxLoginCount()); } - // 10、一切处理完毕,返回会话凭证 token + // 11、一切处理完毕,返回会话凭证 token return tokenValue; } diff --git a/sa-token-demo/sa-token-demo-test/src/main/java/com/pj/test/Test2Controller.java b/sa-token-demo/sa-token-demo-test/src/main/java/com/pj/test/Test2Controller.java index 7b418278..397617ac 100644 --- a/sa-token-demo/sa-token-demo-test/src/main/java/com/pj/test/Test2Controller.java +++ b/sa-token-demo/sa-token-demo-test/src/main/java/com/pj/test/Test2Controller.java @@ -1,5 +1,6 @@ package com.pj.test; +import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.util.SaResult; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -12,11 +13,15 @@ import org.springframework.web.bind.annotation.RestController; @RestController public class Test2Controller { - // 测试登录 ---- http://localhost:8081/.test - @RequestMapping("/.test") + // 测试登录 ---- http://localhost:8081/test + @RequestMapping("/test") public SaResult test2() { - System.out.println("--- 进来了"); - return SaResult.ok("登录成功"); + + StpUtil.login(30003); + System.out.println(StpUtil.getSession().getTimeout()); + System.out.println(StpUtil.getStpLogic().getTokenSession(false)); + + return SaResult.ok(); } }