From 155ff74c57fd9cb93d9a6ffb18f59e8331eb15a1 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 11 Jun 2020 14:27:17 +0800 Subject: [PATCH] =?UTF-8?q?=E9=82=AE=E7=AE=B1=E7=99=BB=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/metersphere/security/ShiroDBRealm.java | 11 ++++++++--- .../main/java/io/metersphere/service/UserService.java | 10 ++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/io/metersphere/security/ShiroDBRealm.java b/backend/src/main/java/io/metersphere/security/ShiroDBRealm.java index 675eb99f03..1c485d4410 100644 --- a/backend/src/main/java/io/metersphere/security/ShiroDBRealm.java +++ b/backend/src/main/java/io/metersphere/security/ShiroDBRealm.java @@ -68,10 +68,15 @@ public class ShiroDBRealm extends AuthorizingRealm { UserDTO user = userService.getUserDTO(userId); String msg; if (user == null) { - msg = "The user does not exist: " + userId; - logger.warn(msg); - throw new UnknownAccountException(Translator.get("user_not_exist") + userId); + user = userService.getUserDTOByEmail(userId); + if (user == null) { + msg = "The user does not exist: " + userId; + logger.warn(msg); + throw new UnknownAccountException(Translator.get("user_not_exist") + userId); + } + userId = user.getId(); } + // local test if (StringUtils.equals("local", runMode)) { SessionUser sessionUser = SessionUser.fromUser(user); diff --git a/backend/src/main/java/io/metersphere/service/UserService.java b/backend/src/main/java/io/metersphere/service/UserService.java index 0d07677969..79cacbfb34 100644 --- a/backend/src/main/java/io/metersphere/service/UserService.java +++ b/backend/src/main/java/io/metersphere/service/UserService.java @@ -147,6 +147,16 @@ public class UserService { return userDTO; } + public UserDTO getUserDTOByEmail(String email) { + UserExample example = new UserExample(); + example.createCriteria().andEmailEqualTo(email); + List users = userMapper.selectByExample(example); + if (users == null || users.size() <= 0) { + return null; + } + return getUserDTO(users.get(0).getId()); + } + public UserRoleDTO getUserRole(String userId) { UserRoleDTO userRoleDTO = new UserRoleDTO(); //