|
@@ -3,11 +3,16 @@ package com.qmth.themis.backend.api;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.qmth.themis.backend.util.ServletUtil;
|
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
|
+import com.qmth.themis.business.dto.AuthDto;
|
|
|
+import com.qmth.themis.business.entity.TBSession;
|
|
|
import com.qmth.themis.business.entity.TBUser;
|
|
|
import com.qmth.themis.business.service.EhcacheService;
|
|
|
+import com.qmth.themis.business.service.TBSessionService;
|
|
|
import com.qmth.themis.business.service.TBUserService;
|
|
|
import com.qmth.themis.business.util.EhcacheUtil;
|
|
|
import com.qmth.themis.business.util.JwtUtil;
|
|
|
+import com.qmth.themis.business.util.RedisUtil;
|
|
|
+import com.qmth.themis.business.util.SessionUtil;
|
|
|
import com.qmth.themis.common.contanst.Constants;
|
|
|
import com.qmth.themis.common.enums.ExceptionResultEnum;
|
|
|
import com.qmth.themis.common.enums.Platform;
|
|
@@ -49,10 +54,10 @@ public class TBUserController {
|
|
|
TBUserService tbUserService;
|
|
|
|
|
|
@Resource
|
|
|
- EhcacheService ehcacheService;
|
|
|
+ TBSessionService tbSessionService;
|
|
|
|
|
|
-// private String privateKey = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAK445Iw+OvQt7nGjcFSe5kLIQu/UXPEddsB9oRhncui532JXfcmJFFSGjZ+f8l134tloLh4rORNVzJ4PbikuH8U7FvSDgmgyiFTE5n0Y2E//uj95nf7ZvOeemMewtoWyCrq98Zq9HFL/+tw9E7mYa28GY+n68rSmg4zhFgGsW0ldAgMBAAECgYEAiP83yIfOt9++ViGc3Q2uJuluqUQmaXsvvCGNobEHDLXMUHpX8TgXgnfjuZd+b70r5qUjTpnSYb/gDJI5n6wjUhkbpPchMozLN359ppPB3d0bA1ZZGoFIIO5fJxIkenhUsHfZqQlNngGByK2x6SYLWwE0Y4lBx6qzMiU2E8lD3YECQQDjijWQ68G7IxqtKTYPg9LgQNCNnQgHHt/D+meZua0zAXh9ooriO2Q1xVynFTSzxOxE6K7SqofCcv/ubpILEfJxAkEAxAN2ChMPboO3ckr82nQf0Rde62K2VN1OjOAZcbVHjDluOL9dagqdRB1if47BBWoHsh1ZjQSpQdavEDM/vuUjrQJBALSKVTZH2c/Casg6isqEri2BP/kdP+FmfeXiKZGv4d02rYQCFHCs7zY7AukPymFZPp7ugMhmxpFi7e8hjH98HgECQG+BkIrWoPa7k4Y/Rmx3lwn5g5PgSd0pMGBPs+nNuG/608sQgfGrLB/tn3T1HrUXxlz6+VCRkD/WAyzyGpdb/tkCQEEEYBWuw7kVEIhgOqqrmZbVA0RFtuqpRKigJrv5YfHWZPirW9h6/mogYHr0hRFcluM/A5MM8ApwBJU2r/+Lo2k=";
|
|
|
-// private String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCuOOSMPjr0Le5xo3BUnuZCyELv1FzxHXbAfaEYZ3Loud9iV33JiRRUho2fn/Jdd+LZaC4eKzkTVcyeD24pLh/FOxb0g4JoMohUxOZ9GNhP/7o/eZ3+2bznnpjHsLaFsgq6vfGavRxS//rcPRO5mGtvBmPp+vK0poOM4RYBrFtJXQIDAQAB";
|
|
|
+ @Resource
|
|
|
+ EhcacheService ehcacheService;
|
|
|
|
|
|
@ApiOperation(value = "用户登录接口")
|
|
|
@RequestMapping(value = "/login/account", method = RequestMethod.POST)
|
|
@@ -89,28 +94,19 @@ public class TBUserController {
|
|
|
String deviceId = ServletUtil.getRequestDeviceId(request);
|
|
|
//生成token
|
|
|
String token = JwtUtil.sign(user.getId(), platform, deviceId);
|
|
|
- //生成sessionId
|
|
|
-// String token = AccessToken.build(String.valueOf(user.getId()), Platform.PC, "1");
|
|
|
-// log.info("token start");
|
|
|
-// long start = System.currentTimeMillis();
|
|
|
-// RSAPrivateKey rsaPrivateKey = RSAUtils.buildPrivateKey(privateKey);
|
|
|
-// for (int i = 0; i < 1000000; i++) {
|
|
|
-// String token = VerifyToken.encode(String.valueOf(i), Platform.PC, "1", rsaPrivateKey);
|
|
|
-// }
|
|
|
-//// String token = VerifyToken.encode(String.valueOf(user.getId()), Platform.PC, "1", rsaPrivateKey);
|
|
|
-// long end = System.currentTimeMillis();
|
|
|
-// log.info("token end,耗时:{}s", (end - start) / 1000);
|
|
|
-// RSAPublicKey rsaPublicKey = RSAUtils.buildPublicKey(publicKey);
|
|
|
-// VerifyToken result = VerifyToken.decode(token, rsaPublicKey);
|
|
|
-// log.info("result:{}", JSONObject.toJSONString(result));
|
|
|
- //生成sessionId
|
|
|
+ //添加用户鉴权缓存
|
|
|
+ AuthDto authDto = ehcacheService.addAccountCache(user);
|
|
|
+ EhcacheUtil.get(SystemConstant.AUTH_CACHE, user.getId());
|
|
|
//添加用户缓存
|
|
|
- if (Objects.isNull(EhcacheUtil.get(SystemConstant.AUTH_CACHE, user.getId()))) {
|
|
|
- ehcacheService.addAccountCache(user);
|
|
|
- }
|
|
|
+ RedisUtil.setUser(user.getId(), platform, user);
|
|
|
+ //添加用户会话缓存
|
|
|
+ String sessionId = SessionUtil.digest(user.getId(), authDto.getRoleEnum().name(), platform.getSource());
|
|
|
+ TBSession tbSession = tbSessionService.saveSessionInfo(sessionId, user.getId(), authDto.getRoleEnum().name(), platform.name(), platform.getSource(), deviceId, token, request.getLocalAddr());
|
|
|
+ RedisUtil.setUserSession(sessionId, platform, tbSession);
|
|
|
+
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put(SystemConstant.TOKEN, token);
|
|
|
- map.put(SystemConstant.ACCOUNT, user);
|
|
|
+ map.put(SystemConstant.USER, user);
|
|
|
return ResultUtil.ok(map);
|
|
|
}
|
|
|
|