From 45c733c30e6be3a6f4e109592a61c5e3899ec720 Mon Sep 17 00:00:00 2001 From: liqiang-fit2cloud Date: Fri, 28 Apr 2023 20:49:44 +0800 Subject: [PATCH] =?UTF-8?q?refactor(gateway):=20=E9=87=8D=E5=86=99is-login?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E4=B8=8D=E7=94=A8=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E5=BC=8F=EF=BC=8C=E9=98=B2=E6=AD=A2=E9=98=BB=E5=A1=9Eredisson?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gateway/controller/LoginController.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/framework/gateway/src/main/java/io/metersphere/gateway/controller/LoginController.java b/framework/gateway/src/main/java/io/metersphere/gateway/controller/LoginController.java index cb35c8ff0f..1b50d1c672 100644 --- a/framework/gateway/src/main/java/io/metersphere/gateway/controller/LoginController.java +++ b/framework/gateway/src/main/java/io/metersphere/gateway/controller/LoginController.java @@ -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()));