use of com.haier.api.user.domain.ClientVO in project su-sunday-cloud by illeagalName.
the class ResourcePreloadRunner method run.
@Override
public void run(ApplicationArguments args) {
clearCache(CacheConstants.AUTHORIZATION_USER_ROLE + "*");
log.info("加载角色菜单资源开始 {}", LocalDateTime.now());
QueryWrapper<Role> roleWrapper = new QueryWrapper<>();
roleWrapper.eq("status", 0).eq("is_delete", 0);
List<Role> roles = roleMapper.selectList(roleWrapper);
roles.parallelStream().forEach(item -> {
List<Menu> menus = menuMapper.listMenusByRoleId(item.getRoleId());
RoleVO role = new RoleVO();
BeanUtils.copyProperties(item, role);
role.setMenus(menus.stream().map(Menu::getSymbol).filter(Objects::nonNull).collect(Collectors.toList()));
// 缓存起来
redisService.setObject(CacheConstants.AUTHORIZATION_USER_ROLE + role.getRoleId(), role);
});
clearCache(CacheConstants.AUTHORIZATION_USER_MENU + "*");
QueryWrapper<Menu> menuWrapper = new QueryWrapper<>();
menuWrapper.orderByAsc("parent_id", "menu_sort");
List<Menu> menus = menuMapper.selectList(menuWrapper);
menus.forEach(item -> {
MenuVO menu = new MenuVO();
BeanUtils.copyProperties(item, menu);
redisService.setObject(CacheConstants.AUTHORIZATION_USER_MENU + item.getMenuId(), menu);
});
clearCache(CacheConstants.AUTHORIZATION_USER_CLIENT + "*");
log.info("加载client资源开始 {}", LocalDateTime.now());
List<AuthClient> authClients = authClientMapper.listAuthClients();
authClients.stream().map(client -> {
ClientVO clientVO = new ClientVO();
clientVO.setClientId(client.getClientId());
clientVO.setTime(client.getAccessTokenValidity());
clientVO.setRemark(client.getRemark());
return clientVO;
}).forEach(m -> {
redisService.setObject(CacheConstants.AUTHORIZATION_USER_CLIENT + m.getClientId(), m);
});
log.info("加载资源结束 {}", LocalDateTime.now());
}
use of com.haier.api.user.domain.ClientVO in project su-sunday-cloud by illeagalName.
the class AuthService method createToken.
private Map<String, Object> createToken(UserVO user) {
// 获取加密盐
String secret = SecurityUtils.generateSecurityCode();
// 从header中获取clientId
String clientId = ServletUtils.getHeader(DETAILS_CLIENT_ID);
AssertUtils.notEmpty(clientId, "客户端标识不正确");
ClientVO clientMap = redisService.getObject(CacheConstants.AUTHORIZATION_USER_CLIENT + clientId);
AssertUtils.notEmpty(clientMap, "客户端标识不正确");
// 生成token
Date date = new Date(System.currentTimeMillis() + clientMap.getTime() * 1000);
String token = SecurityUtils.createToken(new HashMap<>() {
{
put("uniqueId", user.getUserId() + "");
put("clientId", clientId);
}
}, secret, date);
user.setClientId(clientId);
user.setSecret(secret);
user.setToken(token);
user.setIpaddr(IpUtils.getIpAddr(ServletUtils.getRequest()));
user.setLoginTime(LocalDateTime.now());
user.setExpireTime(DateUtils.toLocalDateTime(date));
// 保存或更新用户token
Map<String, Object> map = new HashMap<>();
map.put("token", token);
redisService.setObject(AUTHORIZATION_USER_TOKEN + clientId + ":" + user.getUserId(), user, clientMap.getTime() - 1, TimeUnit.SECONDS);
return map;
}
Aggregations