From e6622291d3c6b120027f9965651333b0b1ebbc49 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Fri, 18 Nov 2022 18:06:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20OA?= =?UTF-8?q?uth2=E7=99=BB=E5=BD=95=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1019845 --user=李玉号 【系统设置】添加QAuth2成功-选择OAuth2登录-登录失败 https://www.tapd.cn/55049933/s/1298624 --- .../main/java/io/metersphere/gateway/service/SSOService.java | 5 +++-- .../io/metersphere/gateway/service/UserLoginService.java | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/framework/gateway/src/main/java/io/metersphere/gateway/service/SSOService.java b/framework/gateway/src/main/java/io/metersphere/gateway/service/SSOService.java index b9f28cb17a..23a492d35a 100644 --- a/framework/gateway/src/main/java/io/metersphere/gateway/service/SSOService.java +++ b/framework/gateway/src/main/java/io/metersphere/gateway/service/SSOService.java @@ -3,6 +3,7 @@ package io.metersphere.gateway.service; import com.fasterxml.jackson.core.type.TypeReference; import io.metersphere.base.domain.AuthSource; import io.metersphere.base.domain.User; +import io.metersphere.commons.constants.UserSource; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.user.SessionUser; import io.metersphere.commons.utils.*; @@ -303,8 +304,8 @@ public class SSOService { user.setSource(authSource.getType()); userLoginService.createOssUser(user); } else { - if (StringUtils.equals(u.getEmail(), email) && !StringUtils.equals(u.getId(), userid)) { - MSException.throwException("email already exists!"); + if (!StringUtils.equals(u.getSource(), UserSource.OAuth2.name())) { + MSException.throwException("user already exist, user source type is " + u.getSource()); } } diff --git a/framework/gateway/src/main/java/io/metersphere/gateway/service/UserLoginService.java b/framework/gateway/src/main/java/io/metersphere/gateway/service/UserLoginService.java index 1dfdd985cc..ed3542ccd5 100644 --- a/framework/gateway/src/main/java/io/metersphere/gateway/service/UserLoginService.java +++ b/framework/gateway/src/main/java/io/metersphere/gateway/service/UserLoginService.java @@ -9,6 +9,7 @@ import io.metersphere.commons.constants.UserStatus; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.user.SessionUser; import io.metersphere.commons.utils.CodingUtil; +import io.metersphere.commons.utils.LogUtil; import io.metersphere.dto.GroupResourceDTO; import io.metersphere.dto.UserDTO; import io.metersphere.dto.UserGroupPermissionDTO; @@ -233,7 +234,9 @@ public class UserLoginService { public UserDTO getLoginUser(String userId, List list) { UserExample example = new UserExample(); example.createCriteria().andIdEqualTo(userId).andSourceIn(list); - if (userMapper.countByExample(example) == 0) { + long count = userMapper.countByExample(example); + if (count == 0) { + LogUtil.error("get login user error, userid is {}, sources is {}", userId, list); return null; } return getUserDTO(userId);