From 89aaf0396b0d9180dc64f029ac5f4eed18c9c677 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Wed, 1 Jul 2020 14:57:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E5=8F=82=E6=95=B0LDAP?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commons/constants/ParamConstants.java | 22 ++ .../controller/SystemParameterController.java | 12 +- .../io/metersphere/ldap/domain/LdapInfo.java | 16 ++ .../service/SystemParameterService.java | 46 +++- .../settings/system/EmailSetting.vue | 225 ++++++++++++++++++ .../settings/system/LdapSetting.vue | 120 ++++++++++ .../system/SystemParameterSetting.vue | 224 ++--------------- 7 files changed, 453 insertions(+), 212 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/ldap/domain/LdapInfo.java create mode 100644 frontend/src/business/components/settings/system/EmailSetting.vue create mode 100644 frontend/src/business/components/settings/system/LdapSetting.vue diff --git a/backend/src/main/java/io/metersphere/commons/constants/ParamConstants.java b/backend/src/main/java/io/metersphere/commons/constants/ParamConstants.java index 482192246c..abec46c57d 100644 --- a/backend/src/main/java/io/metersphere/commons/constants/ParamConstants.java +++ b/backend/src/main/java/io/metersphere/commons/constants/ParamConstants.java @@ -29,6 +29,7 @@ public interface ParamConstants { enum Classify implements ParamConstants { MAIL("smtp"), + LDAP("ldap"), REGISTRY("registry"); private String value; @@ -112,4 +113,25 @@ public interface ParamConstants { return this.value; } } + + enum LDAP implements ParamConstants { + URL("ldap.url"), + DN("ldap.dn"), + PASSWORD("ldap.password"), + OU("ldap.ou"), + FILTER("ldap.filter"), + MAPPING("ldap.mapping"), + OPEN("ldap.open"); + + private String value; + + LDAP(String value) { + this.value = value; + } + + @Override + public String getValue() { + return value; + } + } } diff --git a/backend/src/main/java/io/metersphere/controller/SystemParameterController.java b/backend/src/main/java/io/metersphere/controller/SystemParameterController.java index 475321346e..b0480b4e7a 100644 --- a/backend/src/main/java/io/metersphere/controller/SystemParameterController.java +++ b/backend/src/main/java/io/metersphere/controller/SystemParameterController.java @@ -2,9 +2,9 @@ package io.metersphere.controller; import io.metersphere.base.domain.SystemParameter; import io.metersphere.commons.constants.ParamConstants; +import io.metersphere.ldap.domain.LdapInfo; import io.metersphere.service.SystemParameterService; import org.springframework.web.bind.annotation.*; - import javax.annotation.Resource; import java.util.HashMap; import java.util.List; @@ -35,4 +35,14 @@ public class SystemParameterController { return SystemParameterService.mailInfo(ParamConstants.Classify.MAIL.getValue()); } + @PostMapping("/save/ldap") + public void saveLdap(@RequestBody List systemParameter) { + SystemParameterService.saveLdap(systemParameter); + } + + @GetMapping("/ldap/info") + public LdapInfo getLdapInfo() { + return SystemParameterService.getLdapInfo(ParamConstants.Classify.LDAP.getValue()); + } + } diff --git a/backend/src/main/java/io/metersphere/ldap/domain/LdapInfo.java b/backend/src/main/java/io/metersphere/ldap/domain/LdapInfo.java new file mode 100644 index 0000000000..d306935ba8 --- /dev/null +++ b/backend/src/main/java/io/metersphere/ldap/domain/LdapInfo.java @@ -0,0 +1,16 @@ +package io.metersphere.ldap.domain; + +import lombok.Data; + +@Data +public class LdapInfo { + + private String url; + private String dn; + private String password; + private String ou; + private String filter; + private String mapping; + private String open; + +} diff --git a/backend/src/main/java/io/metersphere/service/SystemParameterService.java b/backend/src/main/java/io/metersphere/service/SystemParameterService.java index 6f60b47dda..3109862a25 100644 --- a/backend/src/main/java/io/metersphere/service/SystemParameterService.java +++ b/backend/src/main/java/io/metersphere/service/SystemParameterService.java @@ -7,12 +7,13 @@ import io.metersphere.commons.constants.ParamConstants; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.EncryptUtils; import io.metersphere.i18n.Translator; +import io.metersphere.ldap.LdapService; +import io.metersphere.ldap.domain.LdapInfo; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.mail.javamail.JavaMailSenderImpl; import org.springframework.stereotype.Service; - import javax.annotation.Resource; import javax.mail.MessagingException; import java.util.*; @@ -112,4 +113,47 @@ public class SystemParameterService { paramList.sort(Comparator.comparingInt(SystemParameter::getSort)); return paramList; } + + public void saveLdap(List parameters) { + SystemParameterExample example = new SystemParameterExample(); + parameters.forEach(param -> { + if (param.getParamKey().equals(ParamConstants.LDAP.PASSWORD.getValue())) { + String string = EncryptUtils.aesEncrypt(param.getParamValue()).toString(); + param.setParamValue(string); + } + example.createCriteria().andParamKeyEqualTo(param.getParamKey()); + if (systemParameterMapper.countByExample(example) > 0) { + systemParameterMapper.updateByPrimaryKey(param); + } else { + systemParameterMapper.insert(param); + } + example.clear(); + }); + } + + public LdapInfo getLdapInfo(String type) { + List params = getParamList(type); + LdapInfo ldap = new LdapInfo(); + if (!CollectionUtils.isEmpty(params)) { + for (SystemParameter param : params) { + if (StringUtils.equals(param.getParamKey(), ParamConstants.LDAP.URL.getValue())) { + ldap.setUrl(param.getParamValue()); + } else if (StringUtils.equals(param.getParamKey(), ParamConstants.LDAP.DN.getValue())) { + ldap.setDn(param.getParamValue()); + } else if (StringUtils.equals(param.getParamKey(), ParamConstants.LDAP.PASSWORD.getValue())) { + String password = EncryptUtils.aesDecrypt(param.getParamValue()).toString(); + ldap.setPassword(password); + } else if (StringUtils.equals(param.getParamKey(), ParamConstants.LDAP.OU.getValue())) { + ldap.setOu(param.getParamValue()); + } else if (StringUtils.equals(param.getParamKey(), ParamConstants.LDAP.FILTER.getValue())) { + ldap.setFilter(param.getParamValue()); + } else if (StringUtils.equals(param.getParamKey(), ParamConstants.LDAP.MAPPING.getValue())) { + ldap.setMapping(param.getParamValue()); + } else if (StringUtils.equals(param.getParamKey(), ParamConstants.LDAP.OPEN.getValue())) { + ldap.setOpen(param.getParamValue()); + } + } + } + return ldap; + } } diff --git a/frontend/src/business/components/settings/system/EmailSetting.vue b/frontend/src/business/components/settings/system/EmailSetting.vue new file mode 100644 index 0000000000..fd64a23082 --- /dev/null +++ b/frontend/src/business/components/settings/system/EmailSetting.vue @@ -0,0 +1,225 @@ + + + + + diff --git a/frontend/src/business/components/settings/system/LdapSetting.vue b/frontend/src/business/components/settings/system/LdapSetting.vue new file mode 100644 index 0000000000..e46883ba17 --- /dev/null +++ b/frontend/src/business/components/settings/system/LdapSetting.vue @@ -0,0 +1,120 @@ + + + + + diff --git a/frontend/src/business/components/settings/system/SystemParameterSetting.vue b/frontend/src/business/components/settings/system/SystemParameterSetting.vue index cb35f98613..62a674bd4b 100644 --- a/frontend/src/business/components/settings/system/SystemParameterSetting.vue +++ b/frontend/src/business/components/settings/system/SystemParameterSetting.vue @@ -1,228 +1,32 @@