增加防御代码,防止恶意攻击(优化)
This commit is contained in:
@@ -30,6 +30,7 @@ public interface LogMapperEx {
|
|||||||
@Param("content") String content);
|
@Param("content") String content);
|
||||||
|
|
||||||
Long getCountByIpAndDate(
|
Long getCountByIpAndDate(
|
||||||
|
@Param("moduleName") String moduleName,
|
||||||
@Param("clientIp") String clientIp,
|
@Param("clientIp") String clientIp,
|
||||||
@Param("createTime") String createTime);
|
@Param("createTime") String createTime);
|
||||||
}
|
}
|
||||||
@@ -150,7 +150,7 @@ public class LogService {
|
|||||||
if(userId!=null) {
|
if(userId!=null) {
|
||||||
String clientIp = getLocalIp(request);
|
String clientIp = getLocalIp(request);
|
||||||
String createTime = Tools.getNow3();
|
String createTime = Tools.getNow3();
|
||||||
Long count = logMapperEx.getCountByIpAndDate(clientIp, createTime);
|
Long count = logMapperEx.getCountByIpAndDate(moduleName, clientIp, createTime);
|
||||||
if(count > 0) {
|
if(count > 0) {
|
||||||
//如果某1个IP在同1秒内连续操作两遍,此时需要删除该redis记录,使其退出,防止恶意攻击
|
//如果某1个IP在同1秒内连续操作两遍,此时需要删除该redis记录,使其退出,防止恶意攻击
|
||||||
redisService.deleteObjectByKeyAndIp("clientIp", clientIp, "userId");
|
redisService.deleteObjectByKeyAndIp("clientIp", clientIp, "userId");
|
||||||
|
|||||||
@@ -72,6 +72,6 @@
|
|||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getCountByIpAndDate" resultType="java.lang.Long">
|
<select id="getCountByIpAndDate" resultType="java.lang.Long">
|
||||||
select count(1) from jsh_log where client_ip=#{clientIp} and create_time=#{createTime}
|
select count(1) from jsh_log where operation=#{moduleName} and client_ip=#{clientIp} and create_time=#{createTime}
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user