Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
多鱼的夏天
RuoYi-Cloud-Docker
提交
f91f931c
R
RuoYi-Cloud-Docker
项目概览
多鱼的夏天
/
RuoYi-Cloud-Docker
通知
210
Star
7
Fork
6
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
RuoYi-Cloud-Docker
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f91f931c
编写于
12月 15, 2021
作者:
R
RuoYi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
自定义xss校验注解实现
上级
329e124d
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
93 addition
and
4 deletion
+93
-4
ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysUser.java
...em/src/main/java/com/ruoyi/system/api/domain/SysUser.java
+4
-3
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/bean/BeanValidators.java
...java/com/ruoyi/common/core/utils/bean/BeanValidators.java
+24
-0
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/xss/Xss.java
...mon-core/src/main/java/com/ruoyi/common/core/xss/Xss.java
+27
-0
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/xss/XssValidator.java
...src/main/java/com/ruoyi/common/core/xss/XssValidator.java
+29
-0
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysNotice.java
...stem/src/main/java/com/ruoyi/system/domain/SysNotice.java
+2
-1
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java
...ava/com/ruoyi/system/service/impl/SysUserServiceImpl.java
+7
-0
未找到文件。
ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysUser.java
浏览文件 @
f91f931c
...
...
@@ -2,9 +2,7 @@ package com.ruoyi.system.api.domain;
import
java.util.Date
;
import
java.util.List
;
import
javax.validation.constraints.Email
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.Size
;
import
javax.validation.constraints.*
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
...
...
@@ -13,6 +11,7 @@ import com.ruoyi.common.core.annotation.Excel.ColumnType;
import
com.ruoyi.common.core.annotation.Excel.Type
;
import
com.ruoyi.common.core.annotation.Excels
;
import
com.ruoyi.common.core.web.domain.BaseEntity
;
import
com.ruoyi.common.core.xss.Xss
;
/**
* 用户对象 sys_user
...
...
@@ -131,6 +130,7 @@ public class SysUser extends BaseEntity
this
.
deptId
=
deptId
;
}
@Xss
(
message
=
"用户昵称不能包含脚本字符"
)
@Size
(
min
=
0
,
max
=
30
,
message
=
"用户昵称长度不能超过30个字符"
)
public
String
getNickName
()
{
...
...
@@ -142,6 +142,7 @@ public class SysUser extends BaseEntity
this
.
nickName
=
nickName
;
}
@Xss
(
message
=
"用户账号不能包含脚本字符"
)
@NotBlank
(
message
=
"用户账号不能为空"
)
@Size
(
min
=
0
,
max
=
30
,
message
=
"用户账号长度不能超过30个字符"
)
public
String
getUserName
()
...
...
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/bean/BeanValidators.java
0 → 100644
浏览文件 @
f91f931c
package
com.ruoyi.common.core.utils.bean
;
import
java.util.Set
;
import
javax.validation.ConstraintViolation
;
import
javax.validation.ConstraintViolationException
;
import
javax.validation.Validator
;
/**
* bean对象属性验证
*
* @author ruoyi
*/
public
class
BeanValidators
{
public
static
void
validateWithException
(
Validator
validator
,
Object
object
,
Class
<?>...
groups
)
throws
ConstraintViolationException
{
Set
<
ConstraintViolation
<
Object
>>
constraintViolations
=
validator
.
validate
(
object
,
groups
);
if
(!
constraintViolations
.
isEmpty
())
{
throw
new
ConstraintViolationException
(
constraintViolations
);
}
}
}
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/xss/Xss.java
0 → 100644
浏览文件 @
f91f931c
package
com.ruoyi.common.core.xss
;
import
javax.validation.Constraint
;
import
javax.validation.Payload
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
/**
* 自定义xss校验注解
*
* @author ruoyi
*/
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Target
(
value
=
{
ElementType
.
METHOD
,
ElementType
.
FIELD
,
ElementType
.
CONSTRUCTOR
,
ElementType
.
PARAMETER
})
@Constraint
(
validatedBy
=
{
XssValidator
.
class
})
public
@interface
Xss
{
String
message
()
default
"不允许任何脚本运行"
;
Class
<?>[]
groups
()
default
{};
Class
<?
extends
Payload
>[]
payload
()
default
{};
}
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/xss/XssValidator.java
0 → 100644
浏览文件 @
f91f931c
package
com.ruoyi.common.core.xss
;
import
javax.validation.ConstraintValidator
;
import
javax.validation.ConstraintValidatorContext
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* 自定义xss校验注解实现
*
* @author ruoyi
*/
public
class
XssValidator
implements
ConstraintValidator
<
Xss
,
String
>
{
private
final
String
HTML_PATTERN
=
"<(\\S*?)[^>]*>.*?|<.*? />"
;
@Override
public
boolean
isValid
(
String
value
,
ConstraintValidatorContext
constraintValidatorContext
)
{
return
!
containsHtml
(
value
);
}
public
boolean
containsHtml
(
String
value
)
{
Pattern
pattern
=
Pattern
.
compile
(
HTML_PATTERN
);
Matcher
matcher
=
pattern
.
matcher
(
value
);
return
matcher
.
matches
();
}
}
\ No newline at end of file
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysNotice.java
浏览文件 @
f91f931c
...
...
@@ -4,8 +4,8 @@ import javax.validation.constraints.NotBlank;
import
javax.validation.constraints.Size
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
com.ruoyi.common.core.web.domain.BaseEntity
;
import
com.ruoyi.common.core.xss.Xss
;
/**
* 通知公告表 sys_notice
...
...
@@ -46,6 +46,7 @@ public class SysNotice extends BaseEntity
this
.
noticeTitle
=
noticeTitle
;
}
@Xss
(
message
=
"公告标题不能包含脚本字符"
)
@NotBlank
(
message
=
"公告标题不能为空"
)
@Size
(
min
=
0
,
max
=
50
,
message
=
"公告标题不能超过50个字符"
)
public
String
getNoticeTitle
()
...
...
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java
浏览文件 @
f91f931c
...
...
@@ -3,6 +3,7 @@ package com.ruoyi.system.service.impl;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
javax.validation.Validator
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -13,6 +14,7 @@ import com.ruoyi.common.core.constant.UserConstants;
import
com.ruoyi.common.core.exception.ServiceException
;
import
com.ruoyi.common.core.utils.SpringUtils
;
import
com.ruoyi.common.core.utils.StringUtils
;
import
com.ruoyi.common.core.utils.bean.BeanValidators
;
import
com.ruoyi.common.datascope.annotation.DataScope
;
import
com.ruoyi.common.security.utils.SecurityUtils
;
import
com.ruoyi.system.api.domain.SysRole
;
...
...
@@ -56,6 +58,9 @@ public class SysUserServiceImpl implements ISysUserService
@Autowired
private
ISysConfigService
configService
;
@Autowired
protected
Validator
validator
;
/**
* 根据条件分页查询用户列表
*
...
...
@@ -513,6 +518,7 @@ public class SysUserServiceImpl implements ISysUserService
SysUser
u
=
userMapper
.
selectUserByUserName
(
user
.
getUserName
());
if
(
StringUtils
.
isNull
(
u
))
{
BeanValidators
.
validateWithException
(
validator
,
user
);
user
.
setPassword
(
SecurityUtils
.
encryptPassword
(
password
));
user
.
setCreateBy
(
operName
);
this
.
insertUser
(
user
);
...
...
@@ -521,6 +527,7 @@ public class SysUserServiceImpl implements ISysUserService
}
else
if
(
isUpdateSupport
)
{
BeanValidators
.
validateWithException
(
validator
,
user
);
user
.
setUpdateBy
(
operName
);
this
.
updateUser
(
user
);
successNum
++;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录