Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beyond-clouds
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
段启岩
beyond-clouds
Commits
426eb3e5
Commit
426eb3e5
authored
Feb 14, 2020
by
段启岩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新流量控制校验
parent
2fa8eecb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
src/main/java/cn/meteor/beyondclouds/core/aop/PreventDuplicateSubmission.java
+9
-0
src/main/java/cn/meteor/beyondclouds/util/Md5Utils.java
+21
-0
No files found.
src/main/java/cn/meteor/beyondclouds/core/aop/PreventDuplicateSubmission.java
View file @
426eb3e5
...
...
@@ -17,9 +17,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.springframework.web.cors.CorsUtils
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.DataInputStream
;
import
java.io.ObjectInputStream
;
import
java.util.Objects
;
import
java.util.concurrent.locks.Lock
;
/**
...
...
@@ -95,6 +100,10 @@ public class PreventDuplicateSubmission {
private
Object
process
(
ProceedingJoinPoint
jp
)
throws
Throwable
{
String
token
=
jp
.
getSignature
().
toString
();
token
=
SubjectUtils
.
getSubject
().
getIdentification
()
+
":"
+
token
;
HttpServletRequest
request
=
((
ServletRequestAttributes
)
(
RequestContextHolder
.
currentRequestAttributes
())).
getRequest
();
if
(
null
!=
request
)
{
token
+=
request
.
getRequestURI
();
}
Lock
lock
=
redisLockFactory
.
createLock
(
Md5Utils
.
encode
(
token
));
if
(
lock
.
tryLock
())
{
try
{
...
...
src/main/java/cn/meteor/beyondclouds/util/Md5Utils.java
View file @
426eb3e5
...
...
@@ -29,4 +29,25 @@ public class Md5Utils {
return
""
;
}
}
public
static
String
encode
(
byte
[]
data
)
{
try
{
MessageDigest
digest
=
MessageDigest
.
getInstance
(
"md5"
);
byte
[]
bs
=
digest
.
digest
(
data
);
String
hexString
=
""
;
for
(
byte
b
:
bs
)
{
int
temp
=
b
&
255
;
if
(
temp
<
16
&&
temp
>=
0
)
{
hexString
=
hexString
+
"0"
+
Integer
.
toHexString
(
temp
);
}
else
{
hexString
=
hexString
+
Integer
.
toHexString
(
temp
);
}
}
return
hexString
;
}
catch
(
NoSuchAlgorithmException
e
)
{
e
.
printStackTrace
();
return
""
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment