feat: 新增ldap

This commit is contained in:
fit2cloud-chenyw 2021-09-06 18:35:46 +08:00
parent cec9a85be0
commit b7bcdd1fbf
12 changed files with 318 additions and 5 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>dataease-server</artifactId>
<groupId>io.dataease</groupId>
<version>1.2.0</version>
<version>1.3.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -316,7 +316,7 @@
<dependency>
<groupId>io.dataease</groupId>
<artifactId>dataease-plugin-interface</artifactId>
<version>1.2</version>
<version>1.3</version>
</dependency>
<dependency>
@ -337,6 +337,11 @@
<version>5.7.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-ldap</artifactId>
</dependency>
<!--<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>

View File

@ -0,0 +1,28 @@
package io.dataease.plugins.server;
import io.dataease.plugins.config.SpringContextUtil;
import io.dataease.plugins.xpack.display.dto.response.SysSettingDto;
import io.dataease.plugins.xpack.ldap.dto.response.LdapInfo;
import io.dataease.plugins.xpack.ldap.service.LdapXpackService;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RequestMapping("/api/ldap")
@RestController
public class XLdapServer {
@GetMapping("/info")
public LdapInfo getLdapInfo() {
LdapXpackService ldapXpackService = SpringContextUtil.getBean(LdapXpackService.class);
return ldapXpackService.info();
}
@PostMapping("/save")
public void save(@RequestBody List<SysSettingDto> settings) {
LdapXpackService ldapXpackService = SpringContextUtil.getBean(LdapXpackService.class);
ldapXpackService.save(settings);
}
}

View File

@ -6,7 +6,7 @@
<parent>
<artifactId>dataease-server</artifactId>
<groupId>io.dataease</groupId>
<version>1.2.0</version>
<version>1.3.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -496,7 +496,38 @@ export default {
new_passwd: '新密码',
confirm_passwd: '确认密码',
change_password: '修改密码',
search_by_name: '按姓名搜索'
search_by_name: '按姓名搜索',
import_ldap: '导入LDAP用户'
},
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={0}, 如:(uid={0})]',
input_mapping_placeholder: '如:{"username":"uid","name":"sn","email":"mail"}, username映射的选项可能是cn或uid或sAMAccountName',
test_connect: '测试连接',
test_login: '测试登录',
edit: '编辑',
login_success: '登录成功',
url_cannot_be_empty: 'LDAP 地址不能为空',
dn_cannot_be_empty: 'LDAP DN不能为空',
ou_cannot_be_empty: 'LDAP OU不能为空',
filter_cannot_be_empty: 'LDAP 用户过滤器不能为空',
mapping_cannot_be_empty: 'LDAP 用户属性映射不能为空',
password_cannot_be_empty: 'LDAP 密码不能为空'
},
role: {
menu_authorization: '菜单授权',

View File

@ -0,0 +1,21 @@
<template>
<router-view />
</template>
<script>
export default ({
data() {
return {
}
},
created() {
this.$store.dispatch('app/toggleSideBarHide', false)
},
method: {
}
})
</script>

View File

@ -0,0 +1,21 @@
<template>
<h2>this is sso page</h2>
</template>
<script>
export default ({
data() {
return {
}
},
created() {
this.$store.dispatch('app/toggleSideBarHide', false)
},
method: {
}
})
</script>

View File

@ -0,0 +1,10 @@
<template>
<h2>
this is display settings page
</h2>
</template>
<script>
export default {
}
</script>

View File

@ -0,0 +1,191 @@
<template>
<layout-content :header="$t('user.import_ldap') " back-name="system-user">
<el-form ref="importUserForm" :model="form" :rules="rule" size="small" label-width="auto" label-position="right">
<el-form-item :label="$t('commons.organization')" prop="deptId">
<treeselect
ref="deptTreeSelect"
v-model="form.deptId"
:options="depts"
:load-options="loadDepts"
:auto-load-root-options="false"
:placeholder="$t('user.choose_org')"
@open="filterData"
/>
</el-form-item>
<el-form-item :label="$t('commons.role')" prop="roleIds">
<el-select
ref="roleSelect"
v-model="form.roleIds"
filterable
style="width: 100%"
multiple
:placeholder="$t('commons.please_select')"
@remove-tag="deleteTag"
@change="changeRole"
>
<el-option
v-for="item in roles"
:key="item.name"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="save">{{ $t('commons.confirm') }}</el-button>
<el-button @click="cancel">{{ $t('commons.cancel') }}</el-button>
</el-form-item>
</el-form>
</layout-content>
</template>
<script>
import LayoutContent from '@/components/business/LayoutContent'
import { getDeptTree, treeByDeptId } from '@/api/system/dept'
import { addUser, allRoles } from '@/api/system/user'
export default {
components: { LayoutContent },
data() {
return {
form: {
roles: [{
id: ''
}]
},
rule: {
roleIds: [{ required: true, message: this.$t('user.input_roles'), trigger: 'change' }],
deptId: [],
enable: []
},
defaultForm: { enabled: 1, deptId: null, roleIds: [2] },
depts: null,
roles: [],
roleDatas: [],
userRoles: []
}
},
created() {
this.initRoles()
},
mounted() {
this.bindKey()
},
destroyed() {
this.unBindKey()
},
methods: {
entryKey(event) {
const keyCode = event.keyCode
if (keyCode === 13) {
this.save()
}
},
bindKey() {
document.addEventListener('keypress', this.entryKey)
},
unBindKey() {
document.removeEventListener('keypress', this.entryKey)
},
create() {
this.depts = null
this.form = Object.assign({}, this.defaultForm)
},
initRoles() {
allRoles().then(res => {
this.roles = res.data
})
},
//
loadDepts({ action, parentNode, callback }) {
if (action === 'LOAD_ROOT_OPTIONS' && !this.form.deptId) {
const _self = this
treeByDeptId(0).then(res => {
const results = res.data.map(node => {
if (node.hasChildren && !node.children) {
node.children = null
}
return node
})
_self.depts = results
callback()
})
}
if (action === 'LOAD_CHILDREN_OPTIONS') {
const _self = this
getDeptTree(parentNode.id).then(res => {
parentNode.children = res.data.map(function(obj) {
return _self.normalizer(obj)
})
callback()
})
}
},
normalizer(node) {
if (node.hasChildren) {
node.children = null
}
return {
id: node.deptId,
label: node.name,
children: node.children
}
},
deleteTag(value) {
this.userRoles.forEach(function(data, index) {
if (data.id === value) {
this.userRoles.splice(index, value)
}
}.bind(this))
},
changeRole(value) {
this.userRoles = []
value.forEach(function(data, index) {
const role = { id: data }
this.userRoles.push(role)
}.bind(this))
},
cancel() {
this.$refs.importUserForm.resetFields()
},
save() {
this.$refs.importUserForm.validate(valid => {
if (valid) {
const method = addUser
method(this.form).then(res => {
this.$success(this.$t('commons.save_success'))
this.backToList()
})
} else {
return false
}
})
},
backToList() {
this.$router.push({ name: 'system-user' })
},
filterData(instanceId) {
this.$refs.roleSelect && this.$refs.roleSelect.blur && this.$refs.roleSelect.blur()
if (!this.depts) {
return
}
const results = this.depts.map(node => {
if (node.hasChildren) {
node.children = null
}
return node
})
this.depts = results
}
}
}
</script>

View File

@ -12,6 +12,9 @@
>
<template #toolbar>
<el-button v-permission="['user:add']" icon="el-icon-circle-plus-outline" @click="create">{{ $t('user.create') }}</el-button>
<!-- <el-button v-permission="['user:import']" icon="el-icon-download" @click="importLdap">{{ $t('user.import_ldap') }}</el-button> -->
<el-button icon="el-icon-download" @click="importLdap">{{ $t('user.import_ldap') }}</el-button>
</template>
<el-table-column prop="username" label="ID" />
@ -479,6 +482,9 @@ export default {
},
btnDisabled(row) {
return row.userId === 1
},
importLdap() {
this.$router.push({ name: 'system-user-import' })
}
}
}

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.dataease</groupId>
<artifactId>dataease-server</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
<packaging>pom</packaging>
<parent>