Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
前端资源
RuoYi-Vue
提交
ab992f48
R
RuoYi-Vue
项目概览
前端资源
/
RuoYi-Vue
12 个月 前同步成功
通知
5
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
RuoYi-Vue
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ab992f48
编写于
3月 13, 2020
作者:
R
RuoYi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修复防重复提交注解无效问题
上级
baea48be
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
172 addition
and
13 deletion
+172
-13
ruoyi/src/main/java/com/ruoyi/common/filter/RepeatableFilter.java
...c/main/java/com/ruoyi/common/filter/RepeatableFilter.java
+48
-0
ruoyi/src/main/java/com/ruoyi/common/filter/RepeatedlyRequestWrapper.java
...ava/com/ruoyi/common/filter/RepeatedlyRequestWrapper.java
+84
-0
ruoyi/src/main/java/com/ruoyi/common/filter/XssFilter.java
ruoyi/src/main/java/com/ruoyi/common/filter/XssFilter.java
+1
-1
ruoyi/src/main/java/com/ruoyi/common/filter/XssHttpServletRequestWrapper.java
...com/ruoyi/common/filter/XssHttpServletRequestWrapper.java
+1
-1
ruoyi/src/main/java/com/ruoyi/framework/config/FilterConfig.java
...rc/main/java/com/ruoyi/framework/config/FilterConfig.java
+16
-2
ruoyi/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java
...yi/framework/interceptor/impl/SameUrlDataInterceptor.java
+22
-9
未找到文件。
ruoyi/src/main/java/com/ruoyi/common/filter/RepeatableFilter.java
0 → 100644
浏览文件 @
ab992f48
package
com.ruoyi.common.filter
;
import
java.io.IOException
;
import
javax.servlet.Filter
;
import
javax.servlet.FilterChain
;
import
javax.servlet.FilterConfig
;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletRequest
;
import
javax.servlet.ServletResponse
;
import
javax.servlet.http.HttpServletRequest
;
import
com.ruoyi.common.enums.HttpMethod
;
/**
* Repeatable 过滤器
*
* @author ruoyi
*/
public
class
RepeatableFilter
implements
Filter
{
@Override
public
void
init
(
FilterConfig
filterConfig
)
throws
ServletException
{
}
@Override
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
,
FilterChain
chain
)
throws
IOException
,
ServletException
{
HttpServletRequest
req
=
(
HttpServletRequest
)
request
;
if
(
HttpMethod
.
PUT
.
name
().
equals
(
req
.
getMethod
())
||
HttpMethod
.
POST
.
name
().
equals
(
req
.
getMethod
()))
{
RepeatedlyRequestWrapper
repeatedlyRequest
=
new
RepeatedlyRequestWrapper
((
HttpServletRequest
)
request
);
chain
.
doFilter
(
repeatedlyRequest
,
response
);
}
else
{
chain
.
doFilter
(
request
,
response
);
}
}
@Override
public
void
destroy
()
{
}
}
ruoyi/src/main/java/com/ruoyi/common/filter/RepeatedlyRequestWrapper.java
0 → 100644
浏览文件 @
ab992f48
package
com.ruoyi.common.filter
;
import
java.io.BufferedReader
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.nio.charset.Charset
;
import
javax.servlet.ReadListener
;
import
javax.servlet.ServletInputStream
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequestWrapper
;
import
com.ruoyi.common.utils.StringUtils
;
/**
* 构建可重复读取inputStream的request
*
* @author ruoyi
*/
public
class
RepeatedlyRequestWrapper
extends
HttpServletRequestWrapper
{
private
final
byte
[]
body
;
public
RepeatedlyRequestWrapper
(
HttpServletRequest
request
)
throws
IOException
{
super
(
request
);
body
=
readBytes
(
request
.
getReader
(),
"utf-8"
);
}
@Override
public
BufferedReader
getReader
()
throws
IOException
{
return
new
BufferedReader
(
new
InputStreamReader
(
getInputStream
()));
}
@Override
public
ServletInputStream
getInputStream
()
throws
IOException
{
final
ByteArrayInputStream
bais
=
new
ByteArrayInputStream
(
body
);
return
new
ServletInputStream
()
{
@Override
public
boolean
isFinished
()
{
return
false
;
}
@Override
public
boolean
isReady
()
{
return
false
;
}
@Override
public
void
setReadListener
(
ReadListener
listener
)
{
}
@Override
public
int
read
()
throws
IOException
{
return
bais
.
read
();
}
};
}
/**
* 通过BufferedReader和字符编码集转换成byte数组
*/
private
byte
[]
readBytes
(
BufferedReader
br
,
String
encoding
)
throws
IOException
{
String
str
=
null
,
retStr
=
""
;
while
((
str
=
br
.
readLine
())
!=
null
)
{
retStr
+=
str
;
}
if
(
StringUtils
.
isNotBlank
(
retStr
))
{
return
retStr
.
getBytes
(
Charset
.
forName
(
encoding
));
}
return
null
;
}
}
ruoyi/src/main/java/com/ruoyi/common/
xss
/XssFilter.java
→
ruoyi/src/main/java/com/ruoyi/common/
filter
/XssFilter.java
浏览文件 @
ab992f48
package
com.ruoyi.common.
xss
;
package
com.ruoyi.common.
filter
;
import
java.io.IOException
;
import
java.util.ArrayList
;
...
...
ruoyi/src/main/java/com/ruoyi/common/
xss
/XssHttpServletRequestWrapper.java
→
ruoyi/src/main/java/com/ruoyi/common/
filter
/XssHttpServletRequestWrapper.java
浏览文件 @
ab992f48
package
com.ruoyi.common.
xss
;
package
com.ruoyi.common.
filter
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
...
...
ruoyi/src/main/java/com/ruoyi/framework/config/FilterConfig.java
浏览文件 @
ab992f48
...
...
@@ -7,8 +7,9 @@ import org.springframework.beans.factory.annotation.Value;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
com.ruoyi.common.filter.RepeatableFilter
;
import
com.ruoyi.common.filter.XssFilter
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.xss.XssFilter
;
/**
* Filter配置
...
...
@@ -36,11 +37,24 @@ public class FilterConfig
registration
.
setFilter
(
new
XssFilter
());
registration
.
addUrlPatterns
(
StringUtils
.
split
(
urlPatterns
,
","
));
registration
.
setName
(
"xssFilter"
);
registration
.
setOrder
(
Integer
.
MAX_VALU
E
);
registration
.
setOrder
(
FilterRegistrationBean
.
HIGHEST_PRECEDENC
E
);
Map
<
String
,
String
>
initParameters
=
new
HashMap
<
String
,
String
>();
initParameters
.
put
(
"excludes"
,
excludes
);
initParameters
.
put
(
"enabled"
,
enabled
);
registration
.
setInitParameters
(
initParameters
);
return
registration
;
}
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
@Bean
public
FilterRegistrationBean
someFilterRegistration
()
{
FilterRegistrationBean
registration
=
new
FilterRegistrationBean
();
registration
.
setFilter
(
new
RepeatableFilter
());
registration
.
addUrlPatterns
(
"/*"
);
registration
.
setName
(
"repeatableFilter"
);
registration
.
setOrder
(
FilterRegistrationBean
.
LOWEST_PRECEDENCE
);
return
registration
;
}
}
ruoyi/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java
浏览文件 @
ab992f48
...
...
@@ -2,14 +2,19 @@ package com.ruoyi.framework.interceptor.impl;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpSession
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
com.alibaba.fastjson.JSONObject
;
import
com.ruoyi.common.filter.RepeatedlyRequestWrapper
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.utils.http.HttpHelper
;
import
com.ruoyi.framework.interceptor.RepeatSubmitInterceptor
;
import
com.ruoyi.framework.redis.RedisCache
;
/**
* 判断请求url和数据是否和上一次相同,
* 判断请求url和数据是否和上一次相同,
* 如果和上次相同,则是重复提交表单。 有效时间为10秒内。
*
* @author ruoyi
...
...
@@ -23,6 +28,9 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
public
final
String
SESSION_REPEAT_KEY
=
"repeatData"
;
@Autowired
private
RedisCache
redisCache
;
/**
* 间隔时间,单位:秒 默认10秒
*
...
...
@@ -39,8 +47,14 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
@Override
public
boolean
isRepeatSubmit
(
HttpServletRequest
request
)
{
// 本次参数及系统时间
String
nowParams
=
JSONObject
.
toJSONString
(
request
.
getParameterMap
());
RepeatedlyRequestWrapper
repeatedlyRequest
=
(
RepeatedlyRequestWrapper
)
request
;
String
nowParams
=
HttpHelper
.
getBodyString
(
repeatedlyRequest
);
// body参数为空,获取Parameter的数据
if
(
StringUtils
.
isEmpty
(
nowParams
))
{
nowParams
=
JSONObject
.
toJSONString
(
request
.
getParameterMap
());
}
Map
<
String
,
Object
>
nowDataMap
=
new
HashMap
<
String
,
Object
>();
nowDataMap
.
put
(
REPEAT_PARAMS
,
nowParams
);
nowDataMap
.
put
(
REPEAT_TIME
,
System
.
currentTimeMillis
());
...
...
@@ -48,8 +62,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
// 请求地址(作为存放session的key值)
String
url
=
request
.
getRequestURI
();
HttpSession
session
=
request
.
getSession
();
Object
sessionObj
=
session
.
getAttribute
(
SESSION_REPEAT_KEY
);
Object
sessionObj
=
redisCache
.
getCacheObject
(
SESSION_REPEAT_KEY
);
if
(
sessionObj
!=
null
)
{
Map
<
String
,
Object
>
sessionMap
=
(
Map
<
String
,
Object
>)
sessionObj
;
...
...
@@ -62,9 +75,9 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
}
}
}
Map
<
String
,
Object
>
session
Map
=
new
HashMap
<
String
,
Object
>();
session
Map
.
put
(
url
,
nowDataMap
);
session
.
setAttribute
(
SESSION_REPEAT_KEY
,
sessionMap
);
Map
<
String
,
Object
>
cache
Map
=
new
HashMap
<
String
,
Object
>();
cache
Map
.
put
(
url
,
nowDataMap
);
redisCache
.
setCacheObject
(
SESSION_REPEAT_KEY
,
cacheMap
,
intervalTime
,
TimeUnit
.
SECONDS
);
return
false
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录