Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
符节科技
Jap
提交
f3baf3c9
Jap
项目概览
符节科技
/
Jap
9 个月 前同步成功
通知
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 搜索 >>
提交
f3baf3c9
编写于
10月 08, 2021
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
feat: Verify non-empty
上级
320d14fa
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
147 addition
and
1 deletion
+147
-1
jap-core/src/main/java/com/fujieid/jap/core/annotation/NotEmpty.java
...c/main/java/com/fujieid/jap/core/annotation/NotEmpty.java
+41
-0
jap-core/src/main/java/com/fujieid/jap/core/util/JapValidator.java
...src/main/java/com/fujieid/jap/core/util/JapValidator.java
+60
-0
jap-ldap/src/main/java/com/fujieid/jap/ldap/LdapConfig.java
jap-ldap/src/main/java/com/fujieid/jap/ldap/LdapConfig.java
+6
-1
jap-ldap/src/test/java/com/fujieid/jap/ldap/LdapConfigTest.java
...ap/src/test/java/com/fujieid/jap/ldap/LdapConfigTest.java
+40
-0
未找到文件。
jap-core/src/main/java/com/fujieid/jap/core/annotation/NotEmpty.java
0 → 100644
浏览文件 @
f3baf3c9
/*
* 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.core.annotation
;
import
java.lang.annotation.*
;
/**
* The annotated element must not be {@code null} nor empty. Supported types are:
* <ul>
* <li>{@code CharSequence} (length of character sequence is evaluated)</li>
* <li>{@code Collection} (collection size is evaluated)</li>
* <li>{@code Map} (map size is evaluated)</li>
* <li>Array (array length is evaluated)</li>
* </ul>
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0.0
* @since 1.0.6
*/
@Documented
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Target
({
ElementType
.
FIELD
,
ElementType
.
PARAMETER
})
public
@interface
NotEmpty
{
String
value
()
default
""
;
String
message
();
}
jap-core/src/main/java/com/fujieid/jap/core/util/JapValidator.java
0 → 100644
浏览文件 @
f3baf3c9
/*
* 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.core.util
;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.ReflectUtil
;
import
com.fujieid.jap.core.annotation.NotEmpty
;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0.0
* @since 1.0.6
*/
public
class
JapValidator
{
public
static
List
<
String
>
validate
(
Object
o
)
{
List
<
String
>
errors
=
new
ArrayList
<>();
if
(
null
==
o
)
{
return
errors
;
}
Field
[]
fields
=
ReflectUtil
.
getFields
(
o
.
getClass
());
if
(
ArrayUtil
.
isEmpty
(
fields
))
{
return
errors
;
}
for
(
Field
field
:
fields
)
{
Annotation
[]
annotations
=
field
.
getAnnotations
();
if
(
ArrayUtil
.
isEmpty
(
annotations
))
{
return
errors
;
}
for
(
Annotation
annotation
:
annotations
)
{
if
(
annotation
instanceof
NotEmpty
)
{
Object
object
=
ReflectUtil
.
getFieldValue
(
o
,
field
);
if
(
ObjectUtil
.
isEmpty
(
object
))
{
errors
.
add
(((
NotEmpty
)
annotation
).
message
());
}
}
}
}
return
errors
;
}
}
jap-ldap/src/main/java/com/fujieid/jap/ldap/LdapConfig.java
浏览文件 @
f3baf3c9
...
...
@@ -15,6 +15,7 @@
*/
package
com.fujieid.jap.ldap
;
import
com.fujieid.jap.core.annotation.NotEmpty
;
import
com.fujieid.jap.core.config.AuthenticateConfig
;
/**
...
...
@@ -26,18 +27,22 @@ public class LdapConfig extends AuthenticateConfig {
/**
* LDAP data source URL, such as ldap://localhost:389
*/
@NotEmpty
(
message
=
"LDAP data source URL cannot be empty."
)
private
String
url
;
/**
* LDAP user name, such as: cn=admin,dc=example,dc=org
*/
@NotEmpty
(
message
=
"LDAP bindDn cannot be empty."
)
private
String
bindDn
;
/**
* LDAP
use
r password
* LDAP
administrato
r password
*/
@NotEmpty
(
message
=
"LDAP administrator password cannot be empty"
)
private
String
credentials
;
/**
* Basic catalog
*/
@NotEmpty
(
message
=
"LDAP Basic catalog cannot be empty"
)
private
String
baseDn
;
/**
* Query conditions, such as: (&(objectClass=organizationalPerson)(uid=%s))
...
...
jap-ldap/src/test/java/com/fujieid/jap/ldap/LdapConfigTest.java
0 → 100644
浏览文件 @
f3baf3c9
/*
* 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.util.JapValidator
;
import
org.junit.Test
;
import
java.util.List
;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0.0
* @since 1.0.0
*/
public
class
LdapConfigTest
{
@Test
public
void
annotationTest
()
{
LdapConfig
config
=
new
LdapConfig
()
.
setUrl
(
"1"
)
.
setCredentials
(
"a"
);
List
<
String
>
errors
=
JapValidator
.
validate
(
config
);
for
(
String
error
:
errors
)
{
System
.
out
.
println
(
error
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录