Environment:
Java-EE Based Web Application
Problem :
It is necessary to limit the user to receiving more than 5 (for example) requests within the same second (BOTs mainly)
Solution :
As a base project, I plan to have 2 synchronized Map in the application area
Map<String, Map<Long, Integer>>
String is for sessionId request
Long for the current second view
Integer - hold the number of requests
Process:
Step 0:
Configure Filter to intercept each request
Step 1:
determine the map I will see if the current minute odd, then I will add data to mapOne and I will clear mapTwo
Step 2:
process map
int requestNoForThisSecond = mapXX.get(request.getSession().getId()).get(currentSecondRepresantationInLong); if(requestNoForThisSecond <= 5){ requestNoForThisSecond++; mapXX.get(request.getSession().getId()).put(currentSecondRepresantationInLong, requestNoForThisSecond); }else{ response.sendRedirect();
Step 4:
also delete the session record if the session ends / the user logs out
This is a very simple design for the problem.
Do any of you have a better idea / suggestion?
source share