Package filter
Class RateLimitingFilter
java.lang.Object
filter.RateLimitingFilter
- All Implemented Interfaces:
javax.servlet.Filter
Filter that restricts user from making DoS attacks and abuse
Limits number of requests using a sliding window
- Author:
- TAMIL MUGHILAN
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private static final long
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
Cleans up resources when filter is destroyed.void
doFilter
(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) Processes requests to enforce rate limiting on customers.void
init
(javax.servlet.FilterConfig filterConfig) Initializes the filter when application starts.private boolean
isStaticResource
(String path) Checks if the requested path is a static resource.
-
Field Details
-
MAX_REQUESTS_PER_MINUTE
private static final int MAX_REQUESTS_PER_MINUTE- See Also:
-
TIME_WINDOW_MS
private static final long TIME_WINDOW_MS- See Also:
-
requestMap
-
-
Constructor Details
-
RateLimitingFilter
public RateLimitingFilter()
-
-
Method Details
-
init
public void init(javax.servlet.FilterConfig filterConfig) Initializes the filter when application starts.- Specified by:
init
in interfacejavax.servlet.Filter
- Parameters:
filterConfig
- the filter configuration
-
doFilter
public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws IOException, javax.servlet.ServletException Processes requests to enforce rate limiting on customers. Blocks requests that exceed the allowed rate limit.- Specified by:
doFilter
in interfacejavax.servlet.Filter
- Parameters:
request
- the servlet requestresponse
- the servlet responsechain
- the filter chain- Throws:
IOException
- if an I/O error occursjavax.servlet.ServletException
- if a servlet error occurs
-
isStaticResource
Checks if the requested path is a static resource.- Parameters:
path
- the request path to check- Returns:
- true if it's a static resource, false otherwise
-
destroy
public void destroy()Cleans up resources when filter is destroyed.- Specified by:
destroy
in interfacejavax.servlet.Filter
-