v1.0.0 可用版本

dev
1iyc 1 week ago
parent b12a0aa9bc
commit 2c844c6df5

@ -40,7 +40,7 @@ public class SysUserOnlineController extends BaseController {
Collection<String> keys = redisCache.keys(CacheConstants.LOGIN_TOKEN_KEY + "*");
List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>();
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)) {

@ -46,7 +46,7 @@ logging:
user:
password:
# 密码最大错误次数
maxRetryCount: 5
maxRetryCount: 50
# 密码锁定时间默认10分钟
lockTime: 10

@ -46,7 +46,7 @@ logging:
user:
password:
# 密码最大错误次数
maxRetryCount: 5
maxRetryCount: 50
# 密码锁定时间默认10分钟
lockTime: 10

@ -9,7 +9,7 @@ import org.springframework.stereotype.Component;
* @author ruoyi
*/
@Component
@ConfigurationProperties(prefix = "ruoyi")
@ConfigurationProperties(prefix = "sync")
public class RuoYiConfig {
/**
*

@ -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 <T>
* @return
*/
public <T> 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;
}
/**
*
*

@ -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());
}
}

@ -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<String, Object> 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();
}
/**

Loading…
Cancel
Save