Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
符节科技
Jap
提交
759293fc
Jap
项目概览
符节科技
/
Jap
8 个月 前同步成功
通知
90
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Jap
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
759293fc
编写于
10月 04, 2021
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
feat: Add LdapStrategy
上级
df0cc19d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
110 addition
and
3 deletion
+110
-3
jap-ldap/src/main/java/com/fujieid/jap/ldap/LdapConfig.java
jap-ldap/src/main/java/com/fujieid/jap/ldap/LdapConfig.java
+27
-0
jap-ldap/src/main/java/com/fujieid/jap/ldap/LdapStrategy.java
...ldap/src/main/java/com/fujieid/jap/ldap/LdapStrategy.java
+77
-0
jap-ldap/src/main/java/com/fujieid/jap/ldap/template/LdapDefaultTemplate.java
...va/com/fujieid/jap/ldap/template/LdapDefaultTemplate.java
+5
-2
jap-ldap/src/main/java/com/fujieid/jap/ldap/template/LdapTemplate.java
...main/java/com/fujieid/jap/ldap/template/LdapTemplate.java
+1
-1
未找到文件。
jap-ldap/src/main/java/com/fujieid/jap/ldap/LdapConfig.java
浏览文件 @
759293fc
...
...
@@ -52,6 +52,15 @@ public class LdapConfig extends AuthenticateConfig {
*/
private
String
trustStorePassword
;
/**
* Get the user name from request through {@code request.getParameter(`usernameField`)}, which defaults to "username"
*/
private
String
usernameField
=
"username"
;
/**
* Get the password from request through {@code request.getParameter(`passwordField`)}, which defaults to "password"
*/
private
String
passwordField
=
"password"
;
public
String
getUrl
()
{
return
url
;
}
...
...
@@ -114,4 +123,22 @@ public class LdapConfig extends AuthenticateConfig {
this
.
trustStorePassword
=
trustStorePassword
;
return
this
;
}
public
String
getUsernameField
()
{
return
usernameField
;
}
public
LdapConfig
setUsernameField
(
String
usernameField
)
{
this
.
usernameField
=
usernameField
;
return
this
;
}
public
String
getPasswordField
()
{
return
passwordField
;
}
public
LdapConfig
setPasswordField
(
String
passwordField
)
{
this
.
passwordField
=
passwordField
;
return
this
;
}
}
jap-ldap/src/main/java/com/fujieid/jap/ldap/LdapStrategy.java
0 → 100644
浏览文件 @
759293fc
/*
* Copyright (c) 2020-2040, 北京符节科技有限公司 (support@fujieid.com & https://www.fujieid.com).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com.fujieid.jap.ldap
;
import
com.fujieid.jap.core.JapUser
;
import
com.fujieid.jap.core.JapUserService
;
import
com.fujieid.jap.core.cache.JapCache
;
import
com.fujieid.jap.core.config.AuthenticateConfig
;
import
com.fujieid.jap.core.config.JapConfig
;
import
com.fujieid.jap.core.exception.JapException
;
import
com.fujieid.jap.core.result.JapErrorCode
;
import
com.fujieid.jap.core.result.JapResponse
;
import
com.fujieid.jap.core.store.JapUserStore
;
import
com.fujieid.jap.core.strategy.AbstractJapStrategy
;
import
com.fujieid.jap.http.JapHttpRequest
;
import
com.fujieid.jap.http.JapHttpResponse
;
import
com.fujieid.jap.ldap.model.LdapPerson
;
import
com.fujieid.jap.ldap.template.LdapDefaultTemplate
;
import
com.fujieid.jap.ldap.template.LdapTemplate
;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0.0
* @since 1.0.6
*/
public
class
LdapStrategy
extends
AbstractJapStrategy
{
public
LdapStrategy
(
JapUserService
japUserService
,
JapConfig
japConfig
)
{
super
(
japUserService
,
japConfig
);
}
public
LdapStrategy
(
JapUserService
japUserService
,
JapConfig
japConfig
,
JapCache
japCache
)
{
super
(
japUserService
,
japConfig
,
japCache
);
}
public
LdapStrategy
(
JapUserService
japUserService
,
JapConfig
japConfig
,
JapUserStore
japUserStore
,
JapCache
japCache
)
{
super
(
japUserService
,
japConfig
,
japUserStore
,
japCache
);
}
@Override
public
JapResponse
authenticate
(
AuthenticateConfig
config
,
JapHttpRequest
request
,
JapHttpResponse
response
)
{
JapUser
sessionUser
=
this
.
checkSession
(
request
,
response
);
if
(
null
!=
sessionUser
)
{
return
JapResponse
.
success
(
sessionUser
);
}
try
{
this
.
checkAuthenticateConfig
(
config
,
LdapConfig
.
class
);
}
catch
(
JapException
e
)
{
return
JapResponse
.
error
(
e
.
getErrorCode
(),
e
.
getErrorMessage
());
}
LdapConfig
ldapConfig
=
(
LdapConfig
)
config
;
String
username
=
request
.
getParameter
(
ldapConfig
.
getUsernameField
());
String
password
=
request
.
getParameter
(
ldapConfig
.
getPasswordField
());
LdapTemplate
ldapTemplate
=
new
LdapDefaultTemplate
(
new
LdapDataSource
(
ldapConfig
));
LdapPerson
ldapPerson
=
ldapTemplate
.
login
(
username
,
password
);
JapUser
japUser
=
this
.
japUserService
.
createAndGetLdapUser
(
ldapPerson
);
if
(
null
==
japUser
)
{
return
JapResponse
.
error
(
JapErrorCode
.
UNABLE_SAVE_USERINFO
);
}
return
this
.
loginSuccess
(
japUser
,
request
,
response
);
}
}
jap-ldap/src/main/java/com/fujieid/jap/ldap/template/LdapDefaultTemplate.java
浏览文件 @
759293fc
...
...
@@ -81,9 +81,12 @@ public class LdapDefaultTemplate implements LdapTemplate {
}
@Override
public
boolea
n
login
(
String
userName
,
String
password
)
{
public
LdapPerso
n
login
(
String
userName
,
String
password
)
{
LdapPerson
ldapPerson
=
this
.
findPerson
(
userName
);
LdapPasswordMatch
ldapPasswordMatch
=
LdapPasswordMatchFactory
.
getMatcherByPassword
(
ldapPerson
.
getPassword
());
return
ldapPasswordMatch
.
matches
(
password
,
ldapPerson
.
getPassword
());
if
(
ldapPasswordMatch
.
matches
(
password
,
ldapPerson
.
getPassword
()))
{
return
ldapPerson
;
}
return
null
;
}
}
jap-ldap/src/main/java/com/fujieid/jap/ldap/template/LdapTemplate.java
浏览文件 @
759293fc
...
...
@@ -26,5 +26,5 @@ public interface LdapTemplate {
LdapPerson
findPerson
(
String
userName
);
boolea
n
login
(
String
userName
,
String
password
);
LdapPerso
n
login
(
String
userName
,
String
password
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录