This commit is contained in:
shiziyuan9527 2020-07-02 17:34:36 +08:00
parent fa59db4418
commit f9c9709fd3
11 changed files with 175 additions and 52 deletions

View File

@ -5,6 +5,7 @@ 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.i18n.Translator;
import io.metersphere.ldap.service.LdapService;
import io.metersphere.ldap.domain.LdapInfo;
import io.metersphere.service.SystemParameterService;
@ -30,7 +31,7 @@ public class LdapController {
String isOpen = systemParameterService.getValue(ParamConstants.LDAP.OPEN.getValue());
if (StringUtils.isBlank(isOpen) || StringUtils.equals(Boolean.FALSE.toString(), isOpen)) {
MSException.throwException("LDAP 认证未启用!");
MSException.throwException(Translator.get("ldap_authentication_not_enabled"));
}
ldapService.authenticate(request);

View File

@ -5,6 +5,7 @@ import io.metersphere.commons.constants.ParamConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.EncryptUtils;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.i18n.Translator;
import io.metersphere.ldap.domain.Person;
import io.metersphere.service.SystemParameterService;
import org.apache.commons.lang3.StringUtils;
@ -42,13 +43,13 @@ public class PersonRepoImpl implements PersonRepo {
} catch (AuthenticationException e) {
LogUtil.error("ldap authenticate failed..." + e);
System.out.println("Login failed: " + e);
MSException.throwException("用户认证失败!");
MSException.throwException(Translator.get("authentication_failed"));
return false;
} catch (Exception e) {
// Context creation failed - authentication did not succeed
LogUtil.error("ldap authenticate failed..." + e);
System.out.println("Login failed: " + e);
MSException.throwException("连接失败");
MSException.throwException(Translator.get("ldap_connect_fail"));
return false;
} finally {
// It is imperative that the created DirContext instance is always closed
@ -78,7 +79,7 @@ public class PersonRepoImpl implements PersonRepo {
});
if (result.size() != 1) {
throw new RuntimeException("User not found or not unique");
throw new RuntimeException(Translator.get("user_not_found_or_not_unique"));
}
return result.get(0);
@ -126,19 +127,19 @@ public class PersonRepoImpl implements PersonRepo {
private void preConnect(String url, String dn, String ou, String password) {
if (StringUtils.isBlank(url)) {
MSException.throwException("ldap url is null");
MSException.throwException(Translator.get("ldap_url_is_null"));
}
if (StringUtils.isBlank(dn)) {
MSException.throwException("ldap dn is null");
MSException.throwException(Translator.get("ldap_dn_is_null"));
}
if (StringUtils.isBlank(ou)) {
MSException.throwException("ldap ou is null");
MSException.throwException(Translator.get("ldap_ou_is_null"));
}
if (StringUtils.isBlank(password)) {
MSException.throwException("ldap password is null");
MSException.throwException(Translator.get("ldap_password_is_null"));
}
}

View File

@ -32,10 +32,10 @@ public class LdapService {
} else if (user.size() == 0) {
MSException.throwException(Translator.get("user_not_exist") + username);
} else {
MSException.throwException("Found multiple users");
MSException.throwException(Translator.get("find_more_user"));
}
} catch (CommunicationException e) {
MSException.throwException("LDAP Server connection failed!");
MSException.throwException(Translator.get("ldap_connect_fail"));
}
personRepo.authenticate(dn, credentials);
}

View File

@ -113,3 +113,14 @@ test_case_report_template_repeat=The workspace has the same name template
plan_name_already_exists=Test plan name already exists
test_case_already_exists_excel=There are duplicate test cases in the import file
api_test_name_already_exists=Test name already exists
#ldap
ldap_url_is_null=LDAP address is empty
ldap_dn_is_null=LDAP binding DN is empty
ldap_ou_is_null=LDAP parameter OU is empty
ldap_password_is_null=LDAP password is empty
ldap_connect_fail=Connection failed
authentication_failed=User authentication failed
user_not_found_or_not_unique=User does not exist or is not unique
find_more_user=Multiple users found
ldap_authentication_not_enabled=LDAP authentication is not enabled

View File

@ -114,6 +114,16 @@ plan_name_already_exists=测试计划名称已存在
test_case_already_exists_excel=导入文件中存在重复用例
api_test_name_already_exists=测试名称已经存在
#ldap
ldap_url_is_null=LDAP地址为空
ldap_dn_is_null=LDAP绑定DN为空
ldap_ou_is_null=LDAP参数OU为空
ldap_password_is_null=LDAP密码为空
ldap_connect_fail=连接失败
authentication_failed=用户认证失败
user_not_found_or_not_unique=用户不存在或者不唯一
find_more_user=查找到多个用户
ldap_authentication_not_enabled=LDAP认证未启用

View File

@ -114,3 +114,13 @@ plan_name_already_exists=測試計劃名稱已存在
test_case_already_exists_excel=導入文件中存在重復用例
api_test_name_already_exists=測試名稱已經存在
#ldap
ldap_url_is_null=LDAP地址為空
ldap_dn_is_null=LDAP綁定DN為空
ldap_ou_is_null=LDAP參數OU為空
ldap_password_is_null=LDAP密碼為空
ldap_connect_fail=連接失敗
authentication_failed=用戶認證失敗
user_not_found_or_not_unique=用戶不存在或者不唯一
find_more_user=查找到多個用戶
ldap_authentication_not_enabled=LDAP認證未啟用

View File

@ -2,44 +2,49 @@
<div>
<el-card class="box-card" v-loading="result.loading">
<el-form :model="form" size="small" :rules="rules" :disabled="show" ref="form">
<el-form-item label="LDAP地址" prop="url">
<el-input v-model="form.url" placeholder="请输入LDAP地址 (如 ldap://localhost:389)"></el-input>
<el-form-item :label="$t('ldap.url')" prop="url">
<el-input v-model="form.url" :placeholder="$t('ldap.input_url_placeholder')"></el-input>
</el-form-item>
<el-form-item label="绑定DN" prop="dn">
<el-input v-model="form.dn" placeholder="请输入DN"></el-input>
<el-form-item :label="$t('ldap.dn')" prop="dn">
<el-input v-model="form.dn" :placeholder="$t('ldap.input_dn')"></el-input>
</el-form-item>
<el-form-item label="密码" prop="password">
<el-input v-model="form.password" placeholder="请输入密码" show-password auto-complete="new-password"></el-input>
<el-form-item :label="$t('ldap.password')" prop="password">
<el-input v-model="form.password" :placeholder="$t('ldap.input_password')" show-password
auto-complete="new-password"></el-input>
</el-form-item>
<el-form-item label="用户OU" prop="ou">
<el-input v-model="form.ou" placeholder="输入用户OU (使用|分隔各OU)"></el-input>
<el-form-item :label="$t('ldap.ou')" prop="ou">
<el-input v-model="form.ou" :placeholder="$t('ldap.input_ou_placeholder')"></el-input>
</el-form-item>
<el-form-item label="用户过滤器" prop="filter">
<el-input v-model="form.filter" placeholder="输入过滤器 [可能的选项是cn或uid或sAMAccountName=%(user)s]"></el-input>
<el-form-item :label="$t('ldap.filter')" prop="filter">
<el-input v-model="form.filter" :placeholder="$t('ldap.input_filter_placeholder')"></el-input>
</el-form-item>
<el-form-item label="LDAP属性映射" prop="mapping">
<el-input v-model="form.mapping" placeholder="属性映射"></el-input>
<el-form-item :label="$t('ldap.mapping')" prop="mapping">
<el-input v-model="form.mapping" :placeholder="$t('ldap.input_mapping')"></el-input>
</el-form-item>
<el-form-item label="启用LDAP认证" prop="open">
<el-form-item :label="$t('ldap.open')" prop="open">
<el-checkbox v-model="form.open"></el-checkbox>
</el-form-item>
</el-form>
<div>
<el-button type="primary" size="small" :disabled="!show" @click="testConnection">测试连接</el-button>
<el-button type="primary" size="small" :disabled="!show" @click="testLogin">测试登录</el-button>
<el-button v-if="showEdit" size="small" @click="edit">编辑</el-button>
<el-button type="success" v-if="showSave" size="small" @click="save('form')">保存</el-button>
<el-button type="info" v-if="showCancel" size="small" @click="cancel">取消</el-button>
<el-button type="primary" size="small" :disabled="!show" @click="testConnection">{{$t('ldap.test_connect')}}
</el-button>
<el-button type="primary" size="small" :disabled="!show" @click="testLogin">{{$t('ldap.test_login')}}
</el-button>
<el-button v-if="showEdit" size="small" @click="edit">{{$t('ldap.edit')}}</el-button>
<el-button type="success" v-if="showSave" size="small" @click="save('form')">{{$t('commons.save')}}</el-button>
<el-button type="info" v-if="showCancel" size="small" @click="cancel">{{$t('commons.cancel')}}</el-button>
</div>
<el-dialog title="测试登录" :visible.sync="loginVisible" width="30%" destroy-on-close v-loading="result.loading">
<el-form :model="loginForm" :rules="loginFormRules" ref="loginForm" label-width="80px">
<el-form-item label="用户名" prop="username">
<el-input v-model="loginForm.username" autocomplete="off" placeholder="请输入用户名"/>
<el-dialog :title="$t('ldap.test_login')" :visible.sync="loginVisible" width="30%" destroy-on-close
v-loading="result.loading">
<el-form :model="loginForm" :rules="loginFormRules" ref="loginForm" label-width="90px">
<el-form-item :label="$t('commons.username')" prop="username">
<el-input v-model="loginForm.username" autocomplete="off" :placeholder="$t('ldap.input_username')"/>
</el-form-item>
<el-form-item label="密码" prop="password" >
<el-input v-model="loginForm.password" autocomplete="new-password" placeholder="请输入密码" show-password/>
<el-form-item :label="$t('commons.password')" prop="password">
<el-input v-model="loginForm.password" autocomplete="new-password" :placeholder="$t('ldap.input_password')"
show-password/>
</el-form-item>
</el-form>
<span slot="footer">
@ -55,6 +60,7 @@
<script>
import MsDialogFooter from "../../common/components/MsDialogFooter";
export default {
name: "LdapSetting",
components: {
@ -71,14 +77,14 @@
showCancel: false,
loginVisible: false,
rules: {
url: {required: true, message: '请输入LDAP地址', trigger: ['change','blur']},
dn: {required: true, message: '请输入DN', trigger: ['change','blur']},
password: {required: true, message: '请输入密码', trigger: ['change','blur']},
ou: {required: true, message: '请输入OU', trigger: ['change','blur']},
url: {required: true, message: this.$t('ldap.input_url'), trigger: ['change', 'blur']},
dn: {required: true, message: this.$t('ldap.input_dn'), trigger: ['change', 'blur']},
password: {required: true, message: this.$t('ldap.input_password'), trigger: ['change', 'blur']},
ou: {required: true, message: this.$t('ldap.input_ou'), trigger: ['change', 'blur']},
},
loginFormRules: {
username: {required: true, message: '请输入用户名', trigger: 'blur'},
password: {required: true, message: '请输入密码', trigger: 'blur'}
username: {required: true, message: this.$t('ldap.input_username'), trigger: 'blur'},
password: {required: true, message: this.$t('ldap.input_password'), trigger: 'blur'}
}
}
},
@ -113,7 +119,7 @@
return false;
}
this.result = this.$post("/ldap/test/connect", this.form, response => {
this.$success("连接成功!")
this.$success(this.$t('commons.connection_successful'));
})
},
testLogin() {
@ -122,7 +128,7 @@
}
if (!this.form.ou) {
this.$warning("LDAP OU不能为空");
this.$warning(this.$t('ldap.ou_cannot_be_empty'));
return false;
}
@ -131,17 +137,17 @@
},
checkParam() {
if (!this.form.url) {
this.$warning("LDAP 地址不能为空!");
this.$warning(this.$t('ldap.url_cannot_be_empty'));
return false;
}
if (!this.form.dn) {
this.$warning("LDAP DN不能为空");
this.$warning(this.$t('ldap.dn_cannot_be_empty'));
return false;
}
if (!this.form.password) {
this.$warning("LDAP 密码不能为空!");
this.$warning(this.$t('ldap.password_cannot_be_empty'));
return false;
}
@ -166,7 +172,7 @@
this.showEdit = true;
this.showSave = false;
this.showCancel = false;
this.$success("保存成功")
this.$success(this.$t('commons.save_success'));
this.init();
});
} else {
@ -178,7 +184,7 @@
this.$refs[form].validate(valid => {
if (valid) {
this.result = this.$post("/ldap/test/login", this.loginForm, response => {
this.$success("登录成功")
this.$success(this.$t('ldap.login_success'));
});
} else {
return false;

View File

@ -1,10 +1,10 @@
<template>
<div>
<el-tabs class="system-setting" v-model="activeName">
<el-tab-pane label="邮箱设置" name="email">
<el-tab-pane :label="$t('system_parameter_setting.mailbox_service_settings')" name="email">
<email-setting/>
</el-tab-pane>
<el-tab-pane label="LDAP设置" name="ldap">
<el-tab-pane :label="$t('system_parameter_setting.ldap_setting')" name="ldap">
<ldap-setting/>
</el-tab-pane>
</el-tabs>

View File

@ -549,7 +549,8 @@ export default {
'check_in': 'Check in',
},
system_parameter_setting: {
'mailbox_service_settings': 'Mailbox Service Settings',
'mailbox_service_settings': 'Mailbox Settings',
'ldap_setting': 'LDAP Setting',
'test_connection': 'Test connection',
'SMTP_host': 'SMTP host',
'SMTP_port': 'SMTP port',
@ -562,5 +563,32 @@ export default {
},
i18n: {
'home': 'Home'
},
ldap: {
'url': 'LDAP URL',
'dn': 'Bind DN',
'password': 'Password',
'ou': 'User OU',
'filter': 'User Filter',
'mapping': 'LDAP Mapping',
'open': 'Enable LDAP Authentication',
'input_url': 'Please enter LDAP url',
'input_dn': 'Please enter DN',
'input_password': 'Please enter the password',
'input_ou': 'Please enter user OU',
'input_filter': 'Please enter a user filter',
'input_mapping': 'Please enter LDAP attribute mapping',
'input_username': 'please enter user name',
'input_url_placeholder': 'Please enter the LDAP address (eg ldap://localhost:389)',
'input_ou_placeholder': 'Enter user OU (use | to separate each OU)',
'input_filter_placeholder': 'Input filter [Possible options are cn or uid or sAMAccountName=%(user)s]',
'test_connect': 'Test Connection',
'test_login': 'Test Login',
'edit': 'Edit',
'login_success': 'login success',
'url_cannot_be_empty': 'LDAP address cannot be empty',
'dn_cannot_be_empty': 'LDAP DN cannot be empty',
'ou_cannot_be_empty': 'LDAP OU cannot be empty',
'password_cannot_be_empty': 'LDAP password cannot be empty',
}
};

View File

@ -547,7 +547,8 @@ export default {
'check_in': '校验中',
},
system_parameter_setting: {
'mailbox_service_settings': '邮件服务设置',
'mailbox_service_settings': '邮件设置',
'ldap_setting': 'LDAP设置',
'test_connection': '测试连接',
'SMTP_host': 'SMTP主机',
'SMTP_port': 'SMTP端口',
@ -559,5 +560,32 @@ export default {
},
i18n: {
'home': '首页'
},
ldap: {
'url': 'LDAP地址',
'dn': '绑定DN',
'password': '密码',
'ou': '用户OU',
'filter': '用户过滤器',
'mapping': 'LDAP属性映射',
'open': '启用LDAP认证',
'input_url': '请输入LDAP地址',
'input_dn': '请输入DN',
'input_password': '请输入密码',
'input_ou': '请输入用户OU',
'input_filter': '请输入用户过滤器',
'input_mapping': '请输入LDAP属性映射',
'input_username': '请输入用户名',
'input_url_placeholder': '请输入LDAP地址 (如 ldap://localhost:389)',
'input_ou_placeholder': '输入用户OU (使用|分隔各OU)',
'input_filter_placeholder': '输入过滤器 [可能的选项是cn或uid或sAMAccountName=%(user)s]',
'test_connect': '测试连接',
'test_login': '测试登录',
'edit': '编辑',
'login_success': '登录成功',
'url_cannot_be_empty': 'LDAP 地址不能为空',
'dn_cannot_be_empty': 'LDAP DN不能为空',
'ou_cannot_be_empty': 'LDAP OU不能为空',
'password_cannot_be_empty': 'LDAP 密码不能为空',
}
};

View File

@ -547,7 +547,8 @@ export default {
'check_in': '校驗中',
},
system_parameter_setting: {
'mailbox_service_settings': '郵件服務設定',
'mailbox_service_settings': '郵件設置',
'ldap_setting': 'LDAP設置',
'test_connection': '測試連結',
'SMTP_host': 'SMTP主機',
'SMTP_port': 'SMTP埠',
@ -559,5 +560,32 @@ export default {
},
i18n: {
'home': '首頁'
},
ldap: {
'url': 'LDAP地址',
'dn': '綁定DN',
'password': '密碼',
'ou': '用戶OU',
'filter': '用戶過濾器',
'mapping': 'LDAP屬性映射',
'open': '啟用LDAP認證',
'input_url': '請輸入LDAP地址',
'input_dn': '請輸入DN',
'input_password': '請輸入密碼',
'input_ou': '請輸入用戶OU',
'input_filter': '請輸入用戶過濾器',
'input_mapping': '請輸入LDAP屬性映射',
'input_username': '請輸入用戶名',
'input_url_placeholder': '請輸入LDAP地址 (如 ldap://localhost:389)',
'input_ou_placeholder': '輸入用戶OU (使用|分隔各OU)',
'input_filter_placeholder': '輸入過濾器 [可能的選項是cn或uid或sAMAccountName=%(user)s]',
'test_connect': '測試連接',
'test_login': '測試登錄',
'edit': '編輯',
'login_success': '登錄成功',
'url_cannot_be_empty': 'LDAP 地址不能為空',
'dn_cannot_be_empty': 'LDAP DN不能為空',
'ou_cannot_be_empty': 'LDAP OU不能為空',
'password_cannot_be_empty': 'LDAP 密碼不能為空',
}
};