From fa59db441861c921d2509b34495b2791063db4b3 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Thu, 2 Jul 2020 15:51:26 +0800 Subject: [PATCH] =?UTF-8?q?LDAP=20=E6=B5=8B=E8=AF=95=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ldap/controller/LdapController.java | 19 +++- .../metersphere/ldap/dao/PersonRepoImpl.java | 7 +- .../settings/system/LdapSetting.vue | 91 +++++++++++++++++-- 3 files changed, 105 insertions(+), 12 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 32c6ee15ed..e019e426ac 100644 --- a/backend/src/main/java/io/metersphere/ldap/controller/LdapController.java +++ b/backend/src/main/java/io/metersphere/ldap/controller/LdapController.java @@ -1,11 +1,15 @@ package io.metersphere.ldap.controller; import io.metersphere.base.domain.User; +import io.metersphere.commons.constants.ParamConstants; +import io.metersphere.commons.exception.MSException; import io.metersphere.controller.ResultHolder; import io.metersphere.controller.request.LoginRequest; import io.metersphere.ldap.service.LdapService; import io.metersphere.ldap.domain.LdapInfo; +import io.metersphere.service.SystemParameterService; import io.metersphere.service.UserService; +import org.apache.commons.lang3.StringUtils; import org.apache.shiro.SecurityUtils; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -18,9 +22,17 @@ public class LdapController { private UserService userService; @Resource private LdapService ldapService; + @Resource + private SystemParameterService systemParameterService; @PostMapping(value = "/signin") public ResultHolder login(@RequestBody LoginRequest request) { + + String isOpen = systemParameterService.getValue(ParamConstants.LDAP.OPEN.getValue()); + if (StringUtils.isBlank(isOpen) || StringUtils.equals(Boolean.FALSE.toString(), isOpen)) { + MSException.throwException("LDAP 认证未启用!"); + } + ldapService.authenticate(request); SecurityUtils.getSubject().getSession().setAttribute("authenticate", "ldap"); @@ -45,9 +57,14 @@ public class LdapController { return userService.login(request); } - @PostMapping("/connect") + @PostMapping("/test/connect") public void testConnect(@RequestBody LdapInfo ldapInfo) { ldapService.testConnect(ldapInfo); } + @PostMapping("/test/login") + public void testLogin(@RequestBody LoginRequest request) { + ldapService.authenticate(request); + } + } diff --git a/backend/src/main/java/io/metersphere/ldap/dao/PersonRepoImpl.java b/backend/src/main/java/io/metersphere/ldap/dao/PersonRepoImpl.java index 4ae370365b..a743b8f05b 100644 --- a/backend/src/main/java/io/metersphere/ldap/dao/PersonRepoImpl.java +++ b/backend/src/main/java/io/metersphere/ldap/dao/PersonRepoImpl.java @@ -105,9 +105,12 @@ public class PersonRepoImpl implements PersonRepo { String url = service.getValue(ParamConstants.LDAP.URL.getValue()); String dn = service.getValue(ParamConstants.LDAP.DN.getValue()); String ou = service.getValue(ParamConstants.LDAP.OU.getValue()); - String credentials = EncryptUtils.aesDecrypt(service.getValue(ParamConstants.LDAP.PASSWORD.getValue())).toString(); + String password = service.getValue(ParamConstants.LDAP.PASSWORD.getValue()); + + preConnect(url, dn, ou, password); + + String credentials = EncryptUtils.aesDecrypt(password).toString(); - preConnect(url, dn, ou, credentials); LdapContextSource sourceLdapCtx = new LdapContextSource(); sourceLdapCtx.setUrl(url); diff --git a/frontend/src/business/components/settings/system/LdapSetting.vue b/frontend/src/business/components/settings/system/LdapSetting.vue index d4351df83a..4878ce91e8 100644 --- a/frontend/src/business/components/settings/system/LdapSetting.vue +++ b/frontend/src/business/components/settings/system/LdapSetting.vue @@ -27,33 +27,58 @@
测试连接 - 测试登录 + 测试登录 编辑 保存 取消
+ + + + + + + + + + + + + + +