diff --git a/sync-admin/src/main/java/com/lyr/web/controller/monitor/SysUserOnlineController.java b/sync-admin/src/main/java/com/lyr/web/controller/monitor/SysUserOnlineController.java index d38e1ac..45d0db8 100644 --- a/sync-admin/src/main/java/com/lyr/web/controller/monitor/SysUserOnlineController.java +++ b/sync-admin/src/main/java/com/lyr/web/controller/monitor/SysUserOnlineController.java @@ -40,7 +40,7 @@ public class SysUserOnlineController extends BaseController { Collection keys = redisCache.keys(CacheConstants.LOGIN_TOKEN_KEY + "*"); List userOnlineList = new ArrayList(); for (String key : keys) { - LoginUser user = redisCache.getCacheObject(key); + LoginUser user = redisCache.getCacheObject(key, LoginUser.class); if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) { userOnlineList.add(userOnlineService.selectOnlineByInfo(ipaddr, userName, user)); } else if (StringUtils.isNotEmpty(ipaddr)) { diff --git a/sync-admin/src/main/resources/application.yml b/sync-admin/src/main/resources/application.yml index 9c85247..e539dc3 100644 --- a/sync-admin/src/main/resources/application.yml +++ b/sync-admin/src/main/resources/application.yml @@ -46,7 +46,7 @@ logging: user: password: # 密码最大错误次数 - maxRetryCount: 5 + maxRetryCount: 50 # 密码锁定时间(默认10分钟) lockTime: 10 diff --git a/sync-admin/target/classes/application.yml b/sync-admin/target/classes/application.yml index f5f2170..c133c49 100644 --- a/sync-admin/target/classes/application.yml +++ b/sync-admin/target/classes/application.yml @@ -46,7 +46,7 @@ logging: user: password: # 密码最大错误次数 - maxRetryCount: 5 + maxRetryCount: 50 # 密码锁定时间(默认10分钟) lockTime: 10 diff --git a/sync-admin/target/classes/com/lyr/web/controller/monitor/SysUserOnlineController.class b/sync-admin/target/classes/com/lyr/web/controller/monitor/SysUserOnlineController.class index d1b43f4..7b2b839 100644 Binary files a/sync-admin/target/classes/com/lyr/web/controller/monitor/SysUserOnlineController.class and b/sync-admin/target/classes/com/lyr/web/controller/monitor/SysUserOnlineController.class differ diff --git a/sync-common/src/main/java/com/lyr/common/config/RuoYiConfig.java b/sync-common/src/main/java/com/lyr/common/config/RuoYiConfig.java index fafcf19..e741f30 100644 --- a/sync-common/src/main/java/com/lyr/common/config/RuoYiConfig.java +++ b/sync-common/src/main/java/com/lyr/common/config/RuoYiConfig.java @@ -9,7 +9,7 @@ import org.springframework.stereotype.Component; * @author ruoyi */ @Component -@ConfigurationProperties(prefix = "ruoyi") +@ConfigurationProperties(prefix = "sync") public class RuoYiConfig { /** * 上传路径 diff --git a/sync-common/src/main/java/com/lyr/common/core/redis/RedisCache.java b/sync-common/src/main/java/com/lyr/common/core/redis/RedisCache.java index 430546b..c3a3e75 100644 --- a/sync-common/src/main/java/com/lyr/common/core/redis/RedisCache.java +++ b/sync-common/src/main/java/com/lyr/common/core/redis/RedisCache.java @@ -1,5 +1,6 @@ package com.lyr.common.core.redis; +import com.alibaba.fastjson2.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.BoundSetOperations; import org.springframework.data.redis.core.HashOperations; @@ -97,6 +98,22 @@ public class RedisCache { return operation.get(key); } + /** + * @param key + * @param clazz + * @param + * @return + */ + public T getCacheObject(final String key, Class clazz) { + Object cacheObject = this.getCacheObject(key); + if (cacheObject == null) { + return null; + } + Object object = JSONObject.parseObject(cacheObject.toString(), clazz); + return (T) object; + } + + /** * 删除单个对象 * diff --git a/sync-common/target/classes/com/lyr/common/config/RuoYiConfig.class b/sync-common/target/classes/com/lyr/common/config/RuoYiConfig.class index 1b6365b..5a2bfb5 100644 Binary files a/sync-common/target/classes/com/lyr/common/config/RuoYiConfig.class and b/sync-common/target/classes/com/lyr/common/config/RuoYiConfig.class differ diff --git a/sync-common/target/classes/com/lyr/common/core/redis/RedisCache.class b/sync-common/target/classes/com/lyr/common/core/redis/RedisCache.class index 1b6ff6b..bdc2216 100644 Binary files a/sync-common/target/classes/com/lyr/common/core/redis/RedisCache.class and b/sync-common/target/classes/com/lyr/common/core/redis/RedisCache.class differ diff --git a/sync-framework/src/main/java/com/lyr/framework/config/RedisConfig.java b/sync-framework/src/main/java/com/lyr/framework/config/RedisConfig.java index 7b54510..41e915c 100644 --- a/sync-framework/src/main/java/com/lyr/framework/config/RedisConfig.java +++ b/sync-framework/src/main/java/com/lyr/framework/config/RedisConfig.java @@ -1,5 +1,8 @@ package com.lyr.framework.config; +import com.alibaba.fastjson2.JSONObject; +import com.lyr.common.core.domain.model.LoginUser; +import com.lyr.common.utils.StringUtils; import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; @@ -7,6 +10,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.script.DefaultRedisScript; +import org.springframework.data.redis.serializer.SerializationException; import org.springframework.data.redis.serializer.StringRedisSerializer; /** @@ -49,17 +53,44 @@ public class RedisConfig extends CachingConfigurerSupport { * 限流脚本 */ private String limitScriptText() { - return "local key = KEYS[1]\n" + - "local count = tonumber(ARGV[1])\n" + - "local time = tonumber(ARGV[2])\n" + - "local current = redis.call('get', key);\n" + - "if current and tonumber(current) > count then\n" + - " return tonumber(current);\n" + - "end\n" + - "current = redis.call('incr', key)\n" + - "if tonumber(current) == 1 then\n" + - " redis.call('expire', key, time)\n" + - "end\n" + - "return tonumber(current);"; + return "local key = KEYS[1]\n" + "local count = tonumber(ARGV[1])\n" + "local time = tonumber(ARGV[2])\n" + "local current = redis.call('get', key);\n" + "if current and tonumber(current) > count then\n" + " return tonumber(current);\n" + "end\n" + "current = redis.call('incr', key)\n" + "if tonumber(current) == 1 then\n" + " redis.call('expire', key, time)\n" + "end\n" + "return tonumber(current);"; + } + + + public class StringRedisSerializerEx extends StringRedisSerializer { + + + private String DEFAULT_PREFIX = "sync_data:"; + + @Override + public byte[] serialize(String string) throws SerializationException { + if (string == null) { + return new byte[0]; + } + // 添加前缀 + String realKey = DEFAULT_PREFIX + string; + return super.serialize(realKey); + } + + @Override + public String deserialize(byte[] bytes) throws SerializationException { + String s = bytes == null ? null : new String(bytes); + if (StringUtils.isBlank(s)) { + return s; + } + // 移除前缀 + if (s.startsWith(DEFAULT_PREFIX)) { + return s.substring(DEFAULT_PREFIX.length()); + } + return s; + } + } + + + public static void main(String[] args) { + String string = "{\"@type\":\"com.lyr.common.core.domain.model.LoginUser\",\"browser\":\"Chrome 13\",\"deptId\":103L,\"expireTime\":1730195709559,\"ipaddr\":\"127.0.0.1\",\"loginLocation\":\"内网IP\",\"loginTime\":1730193909559,\"os\":\"Windows 10\",\"permissions\":Set[\"*:*:*\"],\"token\":\"6636edfa-3090-4466-a1c9-965c171f87a3\",\"user\":{\"admin\":true,\"createBy\":\"admin\",\"createTime\":\"2024-10-29 14:37:51\",\"delFlag\":\"0\",\"dept\":{\"ancestors\":\"0,100,101\",\"children\":[],\"deptId\":103L,\"deptName\":\"研发部门\",\"leader\":\"若依\",\"orderNum\":1,\"params\":{\"@type\":\"java.util.HashMap\"},\"parentId\":101L,\"status\":\"0\"},\"deptId\":103L,\"email\":\"ry@163.com\",\"loginDate\":\"2024-10-29 17:23:50\",\"loginIp\":\"127.0.0.1\",\"nickName\":\"若依\",\"params\":{\"@type\":\"java.util.HashMap\"},\"password\":\"$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2\",\"phonenumber\":\"15888888888\",\"remark\":\"管理员\",\"roles\":[{\"admin\":true,\"dataScope\":\"1\",\"deptCheckStrictly\":false,\"flag\":false,\"menuCheckStrictly\":false,\"params\":{\"@type\":\"java.util.HashMap\"},\"roleId\":1L,\"roleKey\":\"admin\",\"roleName\":\"超级管理员\",\"roleSort\":1,\"status\":\"0\"}],\"sex\":\"1\",\"status\":\"0\",\"userId\":1L,\"userName\":\"admin\"},\"userId\":1L,\"username\":\"admin\"}"; + LoginUser jsonObject = JSONObject.parseObject(string, LoginUser.class); + System.out.println(jsonObject.toString()); + } } diff --git a/sync-framework/src/main/java/com/lyr/framework/web/service/TokenService.java b/sync-framework/src/main/java/com/lyr/framework/web/service/TokenService.java index 7b98d4a..b59e6a3 100644 --- a/sync-framework/src/main/java/com/lyr/framework/web/service/TokenService.java +++ b/sync-framework/src/main/java/com/lyr/framework/web/service/TokenService.java @@ -61,7 +61,7 @@ public class TokenService { // 解析对应的权限以及用户信息 String uuid = (String) claims.get(Constants.LOGIN_USER_KEY); String userKey = getTokenKey(uuid); - LoginUser user = redisCache.getCacheObject(userKey); + LoginUser user = redisCache.getCacheObject(userKey, LoginUser.class); return user; } catch (Exception e) { log.error("获取用户信息异常'{}'", e.getMessage()); @@ -154,9 +154,7 @@ public class TokenService { * @return 令牌 */ private String createToken(Map claims) { - String token = Jwts.builder() - .setClaims(claims) - .signWith(SignatureAlgorithm.HS512, secret).compact(); + String token = Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS512, secret).compact(); return token; } @@ -167,10 +165,7 @@ public class TokenService { * @return 数据声明 */ private Claims parseToken(String token) { - return Jwts.parser() - .setSigningKey(secret) - .parseClaimsJws(token) - .getBody(); + return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody(); } /** diff --git a/sync-framework/target/classes/com/lyr/framework/config/RedisConfig.class b/sync-framework/target/classes/com/lyr/framework/config/RedisConfig.class index c89a15c..30c737f 100644 Binary files a/sync-framework/target/classes/com/lyr/framework/config/RedisConfig.class and b/sync-framework/target/classes/com/lyr/framework/config/RedisConfig.class differ diff --git a/sync-framework/target/classes/com/lyr/framework/web/service/TokenService.class b/sync-framework/target/classes/com/lyr/framework/web/service/TokenService.class index d3bc07f..75c1f9e 100644 Binary files a/sync-framework/target/classes/com/lyr/framework/web/service/TokenService.class and b/sync-framework/target/classes/com/lyr/framework/web/service/TokenService.class differ