Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MeterSphere
metersphere
提交
b35a9540
M
metersphere
项目概览
MeterSphere
/
metersphere
上一次同步 大约 3 年
通知
25
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
metersphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b35a9540
编写于
7月 02, 2020
作者:
C
Captain.B
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/master'
上级
48c0299c
fa59db44
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
105 addition
and
12 deletion
+105
-12
backend/src/main/java/io/metersphere/ldap/controller/LdapController.java
...n/java/io/metersphere/ldap/controller/LdapController.java
+18
-1
backend/src/main/java/io/metersphere/ldap/dao/PersonRepoImpl.java
...src/main/java/io/metersphere/ldap/dao/PersonRepoImpl.java
+5
-2
frontend/src/business/components/settings/system/LdapSetting.vue
...d/src/business/components/settings/system/LdapSetting.vue
+82
-9
未找到文件。
backend/src/main/java/io/metersphere/ldap/controller/LdapController.java
浏览文件 @
b35a9540
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
);
}
}
backend/src/main/java/io/metersphere/ldap/dao/PersonRepoImpl.java
浏览文件 @
b35a9540
...
...
@@ -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
);
...
...
frontend/src/business/components/settings/system/LdapSetting.vue
浏览文件 @
b35a9540
...
...
@@ -27,33 +27,58 @@
<div>
<el-button
type=
"primary"
size=
"small"
:disabled=
"!show"
@
click=
"testConnection"
>
测试连接
</el-button>
<el-button
type=
"primary"
size=
"small"
:disabled=
"!show"
>
测试登录
</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>
</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-form-item>
<el-form-item
label=
"密码"
prop=
"password"
>
<el-input
v-model=
"loginForm.password"
autocomplete=
"new-password"
placeholder=
"请输入密码"
show-password
/>
</el-form-item>
</el-form>
<span
slot=
"footer"
>
<ms-dialog-footer
@
cancel=
"loginVisible = false"
@
confirm=
"login('loginForm')"
/>
</span>
</el-dialog>
</el-card>
</div>
</
template
>
<
script
>
import
MsDialogFooter
from
"
../../common/components/MsDialogFooter
"
;
export
default
{
name
:
"
LdapSetting
"
,
components
:
{
MsDialogFooter
},
data
()
{
return
{
form
:
{
open
:
false
},
form
:
{
open
:
false
},
loginForm
:
{},
result
:
{},
show
:
true
,
showEdit
:
true
,
showSave
:
false
,
showCancel
:
false
,
loginVisible
:
false
,
rules
:
{
url
:
{
required
:
true
,
message
:
'
请输入LDAP地址
'
,
trigger
:
[
'
change
'
]},
dn
:
{
required
:
true
,
message
:
'
请输入DN
'
,
trigger
:
[
'
change
'
]},
password
:
{
required
:
true
,
message
:
'
请输入密码
'
,
trigger
:
[
'
change
'
]},
ou
:
{
required
:
true
,
message
:
'
请输入OU
'
,
trigger
:
[
'
change
'
]},
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
'
]},
},
loginFormRules
:
{
username
:
{
required
:
true
,
message
:
'
请输入用户名
'
,
trigger
:
'
blur
'
},
password
:
{
required
:
true
,
message
:
'
请输入密码
'
,
trigger
:
'
blur
'
}
}
}
},
...
...
@@ -65,6 +90,9 @@
this
.
result
=
this
.
$get
(
"
/system/ldap/info
"
,
response
=>
{
this
.
form
=
response
.
data
;
this
.
form
.
open
=
this
.
form
.
open
===
'
true
'
?
true
:
false
;
this
.
$nextTick
(()
=>
{
this
.
$refs
.
form
.
clearValidate
();
})
})
},
edit
()
{
...
...
@@ -81,10 +109,44 @@
this
.
init
();
},
testConnection
()
{
this
.
result
=
this
.
$post
(
"
/ldap/connect
"
,
this
.
form
,
response
=>
{
if
(
!
this
.
checkParam
())
{
return
false
;
}
this
.
result
=
this
.
$post
(
"
/ldap/test/connect
"
,
this
.
form
,
response
=>
{
this
.
$success
(
"
连接成功!
"
)
})
},
testLogin
()
{
if
(
!
this
.
checkParam
())
{
return
false
;
}
if
(
!
this
.
form
.
ou
)
{
this
.
$warning
(
"
LDAP OU不能为空!
"
);
return
false
;
}
this
.
loginForm
=
{};
this
.
loginVisible
=
true
;
},
checkParam
()
{
if
(
!
this
.
form
.
url
)
{
this
.
$warning
(
"
LDAP 地址不能为空!
"
);
return
false
;
}
if
(
!
this
.
form
.
dn
)
{
this
.
$warning
(
"
LDAP DN不能为空!
"
);
return
false
;
}
if
(
!
this
.
form
.
password
)
{
this
.
$warning
(
"
LDAP 密码不能为空!
"
);
return
false
;
}
return
true
;
},
save
(
form
)
{
let
param
=
[
...
...
@@ -111,6 +173,17 @@
return
false
;
}
})
},
login
(
form
)
{
this
.
$refs
[
form
].
validate
(
valid
=>
{
if
(
valid
)
{
this
.
result
=
this
.
$post
(
"
/ldap/test/login
"
,
this
.
loginForm
,
response
=>
{
this
.
$success
(
"
登录成功
"
)
});
}
else
{
return
false
;
}
})
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录