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

This commit is contained in:
liqiang-fit2cloud 2023-04-28 20:49:44 +08:00
parent 166cde0b11
commit 45c733c30e
1 changed files with 15 additions and 8 deletions

View File

@ -5,6 +5,7 @@ import io.metersphere.commons.constants.OperLogConstants;
import io.metersphere.commons.constants.OperLogModule; import io.metersphere.commons.constants.OperLogModule;
import io.metersphere.commons.constants.SessionConstants; import io.metersphere.commons.constants.SessionConstants;
import io.metersphere.commons.user.SessionUser; import io.metersphere.commons.user.SessionUser;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.commons.utils.RsaUtil; import io.metersphere.commons.utils.RsaUtil;
import io.metersphere.controller.handler.ResultHolder; import io.metersphere.controller.handler.ResultHolder;
import io.metersphere.dto.ServiceDTO; import io.metersphere.dto.ServiceDTO;
@ -56,6 +57,7 @@ public class LoginController {
if (StringUtils.isNotBlank(sessionId) && StringUtils.isNotBlank(csrfToken)) { if (StringUtils.isNotBlank(sessionId) && StringUtils.isNotBlank(csrfToken)) {
userLoginService.validateCsrfToken(sessionId, csrfToken); userLoginService.validateCsrfToken(sessionId, csrfToken);
Object userFromSession = redisSessionRepository.getSessionRedisOperations().opsForHash().get("spring:session:sessions:" + sessionId, "sessionAttr:user"); Object userFromSession = redisSessionRepository.getSessionRedisOperations().opsForHash().get("spring:session:sessions:" + sessionId, "sessionAttr:user");
if (userFromSession != null) {
if (userFromSession instanceof User) { if (userFromSession instanceof User) {
// 用户只有工作空间权限 // 用户只有工作空间权限
if (StringUtils.isBlank(((User) userFromSession).getLastProjectId())) { if (StringUtils.isBlank(((User) userFromSession).getLastProjectId())) {
@ -66,6 +68,11 @@ public class LoginController {
SessionUser sessionUser = SessionUser.fromUser(userDTO, sessionId); SessionUser sessionUser = SessionUser.fromUser(userDTO, sessionId);
return Mono.just(ResultHolder.success(sessionUser)); 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())); return Mono.just(ResultHolder.error(RsaUtil.getRsaKey().getPublicKey()));
} }