From cdc790e90d8b4d7d3931243cc9d19347ae902aac Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Wed, 29 Jul 2020 18:32:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(LDAP):=20LDAP=E8=AE=BE=E7=BD=AE=E4=B8=AD?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=B9phone=E5=AD=97=E6=AE=B5=E7=9A=84?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E6=98=A0=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/ldap/controller/LdapController.java | 6 ++++++ .../io/metersphere/ldap/service/LdapService.java | 12 ++++++++++++ 2 files changed, 18 insertions(+) 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 0a4f0ded72..6771d3a87e 100644 --- a/backend/src/main/java/io/metersphere/ldap/controller/LdapController.java +++ b/backend/src/main/java/io/metersphere/ldap/controller/LdapController.java @@ -54,11 +54,17 @@ public class LdapController { // 新建用户 获取LDAP映射属性 String name = ldapService.getMappingAttr("name", dirContext); + String phone = ldapService.getNotRequiredMappingAttr("phone", dirContext); User user = new User(); user.setId(userId); user.setName(name); user.setEmail(email); + + if (StringUtils.isNotBlank(phone)) { + user.setPhone(phone); + } + user.setSource(UserSource.LDAP.name()); userService.addLdapUser(user); } diff --git a/backend/src/main/java/io/metersphere/ldap/service/LdapService.java b/backend/src/main/java/io/metersphere/ldap/service/LdapService.java index 7ac413725e..7aa9b08e9b 100644 --- a/backend/src/main/java/io/metersphere/ldap/service/LdapService.java +++ b/backend/src/main/java/io/metersphere/ldap/service/LdapService.java @@ -213,6 +213,18 @@ public class LdapService { return result; } + public String getNotRequiredMappingAttr(String attr, DirContextOperations dirContext) { + String mapping = getLdapMapping(); + JSONObject jsonObject = JSONObject.parseObject(mapping); + + String mapAttr = jsonObject.getString(attr); + + if (StringUtils.isNotBlank(mapAttr)) { + return dirContext.getStringAttribute(mapAttr); + } + return mapAttr; + } + public boolean isOpen() { String open = service.getValue(ParamConstants.LDAP.OPEN.getValue()); if (StringUtils.isBlank(open)) {