Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
JSH ERP
Commits
8108d639
Commit
8108d639
authored
May 21, 2022
by
季圣华
Browse files
将日志写入的用户超时逻辑改为限定为同一个账号
parent
a2061b1a
Changes
4
Hide whitespace changes
Inline
Side-by-side
jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/LogMapperEx.java
View file @
8108d639
...
...
@@ -30,6 +30,7 @@ public interface LogMapperEx {
@Param
(
"content"
)
String
content
);
Long
getCountByIpAndDate
(
@Param
(
"userId"
)
Long
userId
,
@Param
(
"moduleName"
)
String
moduleName
,
@Param
(
"clientIp"
)
String
clientIp
,
@Param
(
"createTime"
)
String
createTime
);
...
...
jshERP-boot/src/main/java/com/jsh/erp/service/log/LogService.java
View file @
8108d639
...
...
@@ -150,10 +150,10 @@ public class LogService {
if
(
userId
!=
null
)
{
String
clientIp
=
getLocalIp
(
request
);
String
createTime
=
Tools
.
getNow3
();
Long
count
=
logMapperEx
.
getCountByIpAndDate
(
moduleName
,
clientIp
,
createTime
);
Long
count
=
logMapperEx
.
getCountByIpAndDate
(
userId
,
moduleName
,
clientIp
,
createTime
);
if
(
count
>
0
)
{
//如果某
1
个IP在同1秒内连续操作两遍,此时需要删除该redis记录,使其退出,防止恶意攻击
redisService
.
deleteObjectBy
Key
AndIp
(
"clientIp"
,
clientIp
,
"userId"
);
//如果某
个用户某
个IP在同1秒内连续操作两遍,此时需要删除该redis记录,使其退出,防止恶意攻击
redisService
.
deleteObjectBy
User
AndIp
(
userId
,
clientIp
);
}
else
{
Log
log
=
new
Log
();
log
.
setUserId
(
userId
);
...
...
jshERP-boot/src/main/java/com/jsh/erp/service/redis/RedisService.java
View file @
8108d639
...
...
@@ -99,21 +99,17 @@ public class RedisService {
/**
* @author jisheng hua
* description:
* 将信息从redis中移除,比对key和ip
*@date: 2021/08/21 22:10
* @Param: request
* @Param: key
* @Param: ip
* @Param: deleteKey
* @return Object
* 将信息从redis中移除,比对user和ip
* @param userId
* @param clientIp
*/
public
void
deleteObjectBy
Key
AndIp
(
String
key
,
String
ip
,
String
deleteKey
){
public
void
deleteObjectBy
User
AndIp
(
Long
userId
,
String
clientIp
){
Set
<
String
>
tokens
=
redisTemplate
.
keys
(
"*"
);
for
(
String
token
:
tokens
)
{
Object
value
=
redisTemplate
.
opsForHash
().
get
(
token
,
key
);
if
(
value
!=
null
&&
value
.
equals
(
ip
))
{
redisTemplate
.
opsForHash
().
delete
(
token
,
deleteKey
);
Object
userIdValue
=
redisTemplate
.
opsForHash
().
get
(
token
,
"userId"
);
Object
clientIpValue
=
redisTemplate
.
opsForHash
().
get
(
token
,
"clientIp"
);
if
(
userIdValue
!=
null
&&
clientIpValue
!=
null
&&
userIdValue
.
equals
(
userId
.
toString
())
&&
clientIpValue
.
equals
(
clientIp
))
{
redisTemplate
.
opsForHash
().
delete
(
token
,
"userId"
);
}
}
}
...
...
jshERP-boot/src/main/resources/mapper_xml/LogMapperEx.xml
View file @
8108d639
...
...
@@ -75,7 +75,8 @@
</select>
<select
id=
"getCountByIpAndDate"
resultType=
"java.lang.Long"
>
select count(1) from jsh_log where operation=#{moduleName} and client_ip=#{clientIp} and create_time=#{createTime}
select count(1) from jsh_log
where user_id=#{userId} and operation=#{moduleName} and client_ip=#{clientIp} and create_time=#{createTime}
</select>
<insert
id=
"insertLogWithUserId"
parameterType=
"com.jsh.erp.datasource.entities.Log"
>
...
...
Write
Preview
Supports
Markdown
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