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: