Jig*_*shi 5 java security web-applications java-ee
环境:
基于Java-EE的Web应用程序
问题:
需要限制用户在同一秒内发出超过5个(例如)请求(主要是BOT)
解决方案:
作为一个基本设计,我计划Map在应用范围内实现2个同步
Map<String, Map<Long, Integer>>
Run Code Online (Sandbox Code Playgroud)
String 是for sessionId的请求
Long 是目前的第二个代表
Integer 是要保持请求数
处理:
第0步:
配置a Filter拦截每个请求
步骤1:
确定地图我将看到当前minute是奇数然后我将添加数据mapOne,我将清除mapTwo
第2步:
流程图
int requestNoForThisSecond = mapXX.get(request.getSession().getId()).get(currentSecondRepresantationInLong);
if(requestNoForThisSecond <= 5){
requestNoForThisSecond++;
mapXX.get(request.getSession().getId()).put(currentSecondRepresantationInLong, requestNoForThisSecond);
}else{
response.sendRedirect();// redirect to some captcha page
}
Run Code Online (Sandbox Code Playgroud)
第4步:
如果会话到期/用户注销,也会删除会话条目
这是该问题的基本设计
你们中的任何一个人有更好的想法/建议吗?