From b37b9f3b03a96681cb6839adeaa343f317eeaeba Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Mon, 16 Dec 2024 16:14:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=85=8D=E7=BD=AE=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E9=A1=B5=E9=9D=A2=E7=99=BB=E5=BD=95=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/genersoft/iot/vmp/conf/UserSetting.java | 5 +++++ .../com/genersoft/iot/vmp/conf/security/JwtUtils.java | 10 +++++++++- src/main/resources/配置详情.yml | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java b/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java index 604c8c56..c64b4ba8 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java @@ -170,4 +170,9 @@ public class UserSetting { */ private int gbDeviceOnline = 1; + /** + * 登录超时时间(分钟), + */ + private long loginTimeout = 30; + } diff --git a/src/main/java/com/genersoft/iot/vmp/conf/security/JwtUtils.java b/src/main/java/com/genersoft/iot/vmp/conf/security/JwtUtils.java index c2457dc4..61e019c6 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/security/JwtUtils.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/security/JwtUtils.java @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp.conf.security; +import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.conf.security.dto.JwtUser; import com.genersoft.iot.vmp.service.IUserApiKeyService; import com.genersoft.iot.vmp.service.IUserService; @@ -53,6 +54,8 @@ public class JwtUtils implements InitializingBean { private static IUserService userService; private static IUserApiKeyService userApiKeyService; + + private static UserSetting userSetting; public static String getApiKeyHeader() { return API_KEY_HEADER; @@ -68,6 +71,11 @@ public class JwtUtils implements InitializingBean { JwtUtils.userApiKeyService = userApiKeyService; } + @Resource + public void setUserSetting(UserSetting userSetting) { + JwtUtils.userSetting = userSetting; + } + @Override public void afterPropertiesSet() { try { @@ -153,7 +161,7 @@ public class JwtUtils implements InitializingBean { } public static String createToken(String username) { - return createToken(username, EXPIRATION_TIME); + return createToken(username, userSetting.getLoginTimeout()); } public static String getHeader() { diff --git a/src/main/resources/配置详情.yml b/src/main/resources/配置详情.yml index cef72151..e35f9771 100644 --- a/src/main/resources/配置详情.yml +++ b/src/main/resources/配置详情.yml @@ -251,6 +251,8 @@ user-settings: # 0: 国标标准实现,设备离线后不回复心跳,直到设备重新注册上线, # 1(默认): 对于离线设备,收到心跳就把设备设置为上线,并更新注册时间为上次这次心跳的时间。防止过期时间判断异常 gb-device-online: 0 + # 登录超时时间(分钟), + login-timeout: 30 # 关闭在线文档(生产环境建议关闭) springdoc: