提交 7c6407d8 编写于 作者: F fengyw

增加用户登录session过期控制

上级 1d1b560c
......@@ -100,7 +100,7 @@ public class EduGlobalFilter implements GlobalFilter, Ordered {
throw new BaseException(ResultEnum.MENU_NO);
}
// 更新时间,使用户菜单不过期
stringRedisTemplate.opsForValue().set(Constants.RedisPre.ADMINI_MENU.concat(userId.toString()), tk, Constants.SESSIONTIME, TimeUnit.MINUTES);
stringRedisTemplate.expire(Constants.RedisPre.ADMINI_MENU.concat(userId.toString()), Constants.SESSIONTIME, TimeUnit.MINUTES);
}
request.mutate().header(Constants.USER_ID, String.valueOf(userId));
return chain.filter(exchange);
......@@ -133,6 +133,10 @@ public class EduGlobalFilter implements GlobalFilter, Ordered {
throw new BaseException("token不存在,请重新登录");
}
if (!stringRedisTemplate.hasKey(token)) {
throw new BaseException(ResultEnum.TOKEN_PAST);
}
// 解析 token
DecodedJWT jwt = null;
try {
......@@ -152,7 +156,7 @@ public class EduGlobalFilter implements GlobalFilter, Ordered {
}
// 更新时间,使token不过期
stringRedisTemplate.opsForValue().set(Constants.RedisPre.USERS_INFO.concat(userId.toString()), token, Constants.SESSIONTIME, TimeUnit.MINUTES);
stringRedisTemplate.expire(token, Constants.SESSIONTIME, TimeUnit.MINUTES);
return userId;
}
......
......@@ -28,7 +28,6 @@ public final class Constants {
public interface RedisPre {
String ADMINI_MENU = "admin::menu::";
String USERS_INFO = "users::info::";
String ADMIN_VERI_CODE = "admin::ver::code::";
String USER_STUDY = "user::study::";
String RESOURCE = "resource::";
......
......@@ -68,7 +68,7 @@ public class AdminLoginBiz {
resp.setToken(JWTUtil.create(sysUser.getId(), JWTUtil.DATE));
// token,放入缓存
cacheRedis.set(Constants.RedisPre.USERS_INFO.concat(sysUser.getId().toString()), resp.getToken(), 1, TimeUnit.DAYS);
cacheRedis.set(resp.getToken(), sysUser.getId(), 1, TimeUnit.DAYS);
// 获取菜单权限,放入缓存
cacheRedis.set(Constants.RedisPre.ADMINI_MENU.concat(sysUser.getId().toString()), extracted(sysUser), 1, TimeUnit.DAYS);
......
......@@ -115,6 +115,9 @@ public class ApiUsersBiz extends BaseBiz {
dto.setMobile(user.getMobile());
dto.setToken(JWTUtil.create(user.getId(), JWTUtil.DATE));
// token,放入缓存
cacheRedis.set(dto.getToken(), user.getId(), 1, TimeUnit.DAYS);
return Result.success(dto);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册