|
@@ -1,21 +1,17 @@
|
|
package com.ruoyi.framework.web.service;
|
|
package com.ruoyi.framework.web.service;
|
|
|
|
|
|
-import cn.hutool.core.convert.Convert;
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
import cn.hutool.core.util.IdUtil;
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
|
import cn.hutool.http.useragent.UserAgent;
|
|
import cn.hutool.http.useragent.UserAgent;
|
|
import cn.hutool.http.useragent.UserAgentUtil;
|
|
import cn.hutool.http.useragent.UserAgentUtil;
|
|
-import cn.hutool.json.JSONObject;
|
|
|
|
-import cn.hutool.json.JSONUtil;
|
|
|
|
import com.ruoyi.common.constant.Constants;
|
|
import com.ruoyi.common.constant.Constants;
|
|
-import com.ruoyi.common.core.domain.GatewayUser;
|
|
|
|
-import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
|
import com.ruoyi.common.utils.RedisUtils;
|
|
import com.ruoyi.common.utils.RedisUtils;
|
|
import com.ruoyi.common.utils.ServletUtils;
|
|
import com.ruoyi.common.utils.ServletUtils;
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
import com.ruoyi.common.utils.ip.AddressUtils;
|
|
import com.ruoyi.common.utils.ip.AddressUtils;
|
|
import com.ruoyi.framework.config.properties.TokenProperties;
|
|
import com.ruoyi.framework.config.properties.TokenProperties;
|
|
|
|
+import com.ruoyi.system.service.ISysUserService;
|
|
|
|
+import com.ruoyi.zhdd.feign.FeignUserManageService;
|
|
import io.jsonwebtoken.Claims;
|
|
import io.jsonwebtoken.Claims;
|
|
import io.jsonwebtoken.Jwts;
|
|
import io.jsonwebtoken.Jwts;
|
|
import io.jsonwebtoken.SignatureAlgorithm;
|
|
import io.jsonwebtoken.SignatureAlgorithm;
|
|
@@ -25,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
-import java.net.URLDecoder;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -47,6 +42,12 @@ public class TokenService {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private TokenProperties tokenProperties;
|
|
private TokenProperties tokenProperties;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISysUserService userService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private SysPermissionService permissionService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private FeignUserManageService feignUserManageService;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取用户身份信息
|
|
* 获取用户身份信息
|
|
@@ -55,28 +56,48 @@ public class TokenService {
|
|
*/
|
|
*/
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
public LoginUser getLoginUser(HttpServletRequest request) {
|
|
public LoginUser getLoginUser(HttpServletRequest request) {
|
|
- // 获取请求携带的令牌
|
|
|
|
- String token = getToken(request);
|
|
|
|
- if (StringUtils.isNotEmpty(token)) {
|
|
|
|
- try {
|
|
|
|
- Claims claims = parseToken(token);
|
|
|
|
- // 解析对应的权限以及用户信息
|
|
|
|
- String uuid = (String) claims.get(Constants.LOGIN_USER_KEY);
|
|
|
|
- String userKey = getTokenKey(uuid);
|
|
|
|
- LoginUser user = RedisUtils.getCacheObject(userKey);
|
|
|
|
|
|
+ /*String userStr = request.getHeader("user");
|
|
|
|
+ if (StrUtil.isNotBlank(userStr)) {
|
|
|
|
+ userStr = URLDecoder.decode(userStr, "UTF-8");
|
|
|
|
+ JSONObject userJsonObject = JSONUtil.parseObj(userStr);
|
|
|
|
+ JSONObject principalObject = userJsonObject.getJSONObject("principal");
|
|
|
|
+ String id = userJsonObject.getStr("id");
|
|
|
|
+ log.info("userJsonObject:{}", userJsonObject);
|
|
|
|
+ log.info("principalObject:{}", principalObject);
|
|
|
|
+ // 先从缓存中获取
|
|
|
|
+ String userKey = getTokenKey(id);
|
|
|
|
+ LoginUser user = RedisUtils.getCacheObject(userKey);
|
|
|
|
+ if (user != null) {
|
|
|
|
+ return user;
|
|
|
|
+ }
|
|
|
|
+ // 如果缓存中没有的话,则先查询我们的数据库是否存在,如果不存在则查询四维用户是否存在
|
|
|
|
+ SysUser sysUser = userService.selectUserById(id);
|
|
|
|
+ if (sysUser != null) {
|
|
|
|
+ if (StrUtil.isBlank(sysUser.getDeptId())) {
|
|
|
|
+ throw new ServiceException("请联系应急事件处置系统管理员分配组织", 90000);
|
|
|
|
+ }
|
|
|
|
+ // 查询当前用户角色
|
|
|
|
+ SysUser userRole = new SysUser();
|
|
|
|
+ userRole.setUserId(id);
|
|
|
|
+ Set<String> roles = permissionService.getRolePermission(userRole);
|
|
|
|
+ if (roles.isEmpty()) {
|
|
|
|
+ throw new AuthenticationServiceException("请联系应急事件处置系统管理员分配权限");
|
|
|
|
+ }
|
|
|
|
+ user = new LoginUser(sysUser.getUserId(), sysUser.getDeptId(), sysUser, permissionService.getMenuPermission(sysUser));
|
|
|
|
+ user.setUserRole(roles.iterator().next());
|
|
|
|
+ setUserAgent(user);
|
|
|
|
+ user.setSuQian(true);
|
|
|
|
+ RedisUtils.setCacheObject(userKey, user, tokenProperties.getExpireTime(), TimeUnit.MINUTES);
|
|
return user;
|
|
return user;
|
|
- } catch (Exception e) {
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- // 获取网关传过来的用户信息
|
|
|
|
- String userStr = request.getHeader("user");
|
|
|
|
- if (StrUtil.isNotBlank(userStr)) {
|
|
|
|
- userStr = URLDecoder.decode(userStr, "UTF-8");
|
|
|
|
- JSONObject userJsonObject = JSONUtil.parseObj(userStr);
|
|
|
|
- JSONObject principalObject = userJsonObject.getJSONObject("principal");
|
|
|
|
- GatewayUser userDTO = new GatewayUser();
|
|
|
|
- userDTO.setUserId(userJsonObject.getStr("id"));
|
|
|
|
|
|
+ // 查询四维用户
|
|
|
|
+ GatewayUserDetail gatewayUserDetail = feignUserManageService.userDetail(id);
|
|
|
|
+ log.info("四维用户详情:{}", gatewayUserDetail);
|
|
|
|
+ throw new AuthenticationServiceException("请联系应急事件处置系统管理员分配组织及权限");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ *//*GatewayUser userDTO = new GatewayUser();
|
|
|
|
+ userDTO.setUserId(id);
|
|
userDTO.setUserGroupId(userJsonObject.getStr("user_group_id"));
|
|
userDTO.setUserGroupId(userJsonObject.getStr("user_group_id"));
|
|
if (principalObject != null) {
|
|
if (principalObject != null) {
|
|
userDTO.setUsername(principalObject.getStr("userName"));
|
|
userDTO.setUsername(principalObject.getStr("userName"));
|
|
@@ -94,7 +115,20 @@ public class TokenService {
|
|
loginUser.setDeptId(userDTO.getOrgId());
|
|
loginUser.setDeptId(userDTO.getOrgId());
|
|
loginUser.setUser(sysUser);
|
|
loginUser.setUser(sysUser);
|
|
loginUser.setSuQian(true);
|
|
loginUser.setSuQian(true);
|
|
- return loginUser;
|
|
|
|
|
|
+ return loginUser;*//*
|
|
|
|
+ }*/
|
|
|
|
+ // 获取请求携带的令牌
|
|
|
|
+ String token = getToken(request);
|
|
|
|
+ if (StringUtils.isNotEmpty(token)) {
|
|
|
|
+ try {
|
|
|
|
+ Claims claims = parseToken(token);
|
|
|
|
+ // 解析对应的权限以及用户信息
|
|
|
|
+ String uuid = (String) claims.get(Constants.LOGIN_USER_KEY);
|
|
|
|
+ String userKey = getTokenKey(uuid);
|
|
|
|
+ LoginUser user = RedisUtils.getCacheObject(userKey);
|
|
|
|
+ return user;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|