configurable rate limiter
This commit is contained in:
@@ -10,6 +10,8 @@ import org.springframework.lang.NonNull;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.filter.OncePerRequestFilter;
|
import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -24,6 +26,9 @@ public class RateLimitFilter extends OncePerRequestFilter {
|
|||||||
"/api/v1/auth/reset-password", new int[]{10, 15}
|
"/api/v1/auth/reset-password", new int[]{10, 15}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@Value("${app.rate-limit-enabled:true}")
|
||||||
|
private boolean enabled;
|
||||||
|
|
||||||
private final RateLimiterService rateLimiterService;
|
private final RateLimiterService rateLimiterService;
|
||||||
private final ApiErrorResponder apiErrorResponder;
|
private final ApiErrorResponder apiErrorResponder;
|
||||||
|
|
||||||
@@ -37,7 +42,7 @@ public class RateLimitFilter extends OncePerRequestFilter {
|
|||||||
@NonNull HttpServletResponse response,
|
@NonNull HttpServletResponse response,
|
||||||
@NonNull FilterChain filterChain) throws ServletException, IOException {
|
@NonNull FilterChain filterChain) throws ServletException, IOException {
|
||||||
String path = request.getRequestURI();
|
String path = request.getRequestURI();
|
||||||
int[] rule = RULES.get(path);
|
int[] rule = enabled ? RULES.get(path) : null;
|
||||||
|
|
||||||
if (rule != null) {
|
if (rule != null) {
|
||||||
String ip = extractIp(request);
|
String ip = extractIp(request);
|
||||||
|
|||||||
Reference in New Issue
Block a user