| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.ruoyi.common.constant.CacheConstants; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | |
| | | } |
| | | for (String key : keys) |
| | | { |
| | | LoginUser loginUser = redisCache.getCacheObject(key); |
| | | Object cachedValue = redisCache.getCacheObject(key); |
| | | LoginUser loginUser = toLoginUser(cachedValue, key); |
| | | if (loginUser == null || loginUser.getUser() == null || loginUser.getUser().isAdmin()) |
| | | { |
| | | // 管理员拥有所有权限,跳过 |
| | |
| | | log.info("角色[{}]权限变更,已刷新在线用户[{}]的权限缓存", roleId, loginUser.getUsername()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 兼容 Redis 中由旧序列化配置读取为 JSONObject 的登录缓存。 |
| | | */ |
| | | private LoginUser toLoginUser(Object cachedValue, String key) |
| | | { |
| | | if (cachedValue == null) |
| | | { |
| | | return null; |
| | | } |
| | | if (cachedValue instanceof LoginUser) |
| | | { |
| | | return (LoginUser) cachedValue; |
| | | } |
| | | try |
| | | { |
| | | return JSON.to(LoginUser.class, cachedValue); |
| | | } |
| | | catch (RuntimeException e) |
| | | { |
| | | log.warn("忽略无法转换的登录缓存[{}],实际类型为[{}]", key, |
| | | cachedValue.getClass().getName(), e); |
| | | return null; |
| | | } |
| | | } |
| | | } |