refactor(gateway): 重写is-login方法,不用响应式,防止阻塞redisson线程

This commit is contained in:
liqiang-fit2cloud 2023-04-28 20:49:44 +08:00
parent 166cde0b11
commit 45c733c30e

View File

@ -5,6 +5,7 @@ import io.metersphere.commons.constants.OperLogConstants;
import io.metersphere.commons.constants.OperLogModule;
import io.metersphere.commons.constants.SessionConstants;
import io.metersphere.commons.user.SessionUser;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.commons.utils.RsaUtil;
import io.metersphere.controller.handler.ResultHolder;
import io.metersphere.dto.ServiceDTO;
@ -56,15 +57,21 @@ public class LoginController {
if (StringUtils.isNotBlank(sessionId) && StringUtils.isNotBlank(csrfToken)) {
userLoginService.validateCsrfToken(sessionId, csrfToken);
Object userFromSession = redisSessionRepository.getSessionRedisOperations().opsForHash().get("spring:session:sessions:" + sessionId, "sessionAttr:user");
if (userFromSession instanceof User) {
// 用户只有工作空间权限
if (StringUtils.isBlank(((User) userFromSession).getLastProjectId())) {
((User) userFromSession).setLastProjectId("no_such_project");
if (userFromSession != null) {
if (userFromSession instanceof User) {
// 用户只有工作空间权限
if (StringUtils.isBlank(((User) userFromSession).getLastProjectId())) {
((User) userFromSession).setLastProjectId("no_such_project");
}
// 使用数据库里的最新用户权限不同的tab sessionId 不变
UserDTO userDTO = userLoginService.getUserDTO(((User) userFromSession).getId());
SessionUser sessionUser = SessionUser.fromUser(userDTO, sessionId);
return Mono.just(ResultHolder.success(sessionUser));
}
// 使用数据库里的最新用户权限不同的tab sessionId 不变
UserDTO userDTO = userLoginService.getUserDTO(((User) userFromSession).getId());
SessionUser sessionUser = SessionUser.fromUser(userDTO, sessionId);
return Mono.just(ResultHolder.success(sessionUser));
LogUtil.info("userFromSession.class: " + userFromSession.getClass().getName());
return Mono.just(ResultHolder.success(userFromSession));
} else {
LogUtil.info("userFromSession is null");
}
}
return Mono.just(ResultHolder.error(RsaUtil.getRsaKey().getPublicKey()));