From 613555101ea8aac84f4607ea4b665f3c3c4189eb Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Thu, 18 Mar 2021 16:55:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(LDAP):=20=E4=BF=AE=E5=A4=8DLDAP=E7=99=BB?= =?UTF-8?q?=E9=99=86=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/metersphere/ldap/controller/LdapController.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/io/metersphere/ldap/controller/LdapController.java b/backend/src/main/java/io/metersphere/ldap/controller/LdapController.java index 6771d3a87e..4d14f667d9 100644 --- a/backend/src/main/java/io/metersphere/ldap/controller/LdapController.java +++ b/backend/src/main/java/io/metersphere/ldap/controller/LdapController.java @@ -4,6 +4,9 @@ import io.metersphere.base.domain.User; import io.metersphere.commons.constants.ParamConstants; import io.metersphere.commons.constants.UserSource; import io.metersphere.commons.exception.MSException; +import io.metersphere.commons.utils.CommonBeanFactory; +import io.metersphere.commons.utils.RsaKey; +import io.metersphere.commons.utils.RsaUtil; import io.metersphere.controller.ResultHolder; import io.metersphere.controller.request.LoginRequest; import io.metersphere.i18n.Translator; @@ -16,6 +19,7 @@ import org.springframework.ldap.core.DirContextOperations; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.security.NoSuchAlgorithmException; @RestController @RequestMapping("/ldap") @@ -29,7 +33,7 @@ public class LdapController { private SystemParameterService systemParameterService; @PostMapping(value = "/signin") - public ResultHolder login(@RequestBody LoginRequest request) { + public ResultHolder login(@RequestBody LoginRequest request) throws NoSuchAlgorithmException { String isOpen = systemParameterService.getValue(ParamConstants.LDAP.OPEN.getValue()); if (StringUtils.isBlank(isOpen) || StringUtils.equals(Boolean.FALSE.toString(), isOpen)) { @@ -71,7 +75,8 @@ public class LdapController { // 执行 ShiroDBRealm 中 LDAP 登录逻辑 LoginRequest loginRequest = new LoginRequest(); - loginRequest.setUsername(userId); + RsaKey rsaKey = CommonBeanFactory.getBean(RsaKey.class); + loginRequest.setUsername(RsaUtil.publicEncrypt(userId,rsaKey.getPublicKey())); return userService.login(loginRequest); }