From 9d239c368f767dc1c4416299d098930d4eb78d9d Mon Sep 17 00:00:00 2001 From: Dave Machado Date: Sat, 12 Sep 2026 14:23:25 -0700 Subject: [PATCH] chore(backend): remove unused LoginRateLimitService (#2613) Co-authored-by: Dave Machado <15134885+davemachado@users.noreply.github.com> --- .../service/LoginRateLimitService.java | 46 ------------------- 1 file changed, 46 deletions(-) delete mode 100644 backend/src/main/java/org/booklore/config/security/service/LoginRateLimitService.java diff --git a/backend/src/main/java/org/booklore/config/security/service/LoginRateLimitService.java b/backend/src/main/java/org/booklore/config/security/service/LoginRateLimitService.java deleted file mode 100644 index d4249ee05..000000000 --- a/backend/src/main/java/org/booklore/config/security/service/LoginRateLimitService.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.booklore.config.security.service; - -import com.github.benmanes.caffeine.cache.Cache; -import com.github.benmanes.caffeine.cache.Caffeine; -import lombok.extern.slf4j.Slf4j; -import org.booklore.exception.ApiError; -import org.booklore.model.enums.AuditAction; -import org.booklore.service.audit.AuditService; -import org.springframework.stereotype.Service; - -import java.time.Duration; -import java.util.concurrent.atomic.AtomicInteger; - -@Slf4j -@Service -public class LoginRateLimitService { - - private static final int MAX_ATTEMPTS = 5; - - private final Cache attemptCache; - private final AuditService auditService; - - public LoginRateLimitService(AuditService auditService) { - this.auditService = auditService; - this.attemptCache = Caffeine.newBuilder() - .maximumSize(1000) - .expireAfterWrite(Duration.ofMinutes(15)) - .build(); - } - - public void checkRateLimit(String ip) { - AtomicInteger attempts = attemptCache.getIfPresent(ip); - if (attempts != null && attempts.get() >= MAX_ATTEMPTS) { - auditService.log(AuditAction.LOGIN_RATE_LIMITED, "Login rate limited for IP: " + ip); - throw ApiError.RATE_LIMITED.createException(); - } - } - - public void recordFailedAttempt(String ip) { - attemptCache.get(ip, k -> new AtomicInteger(0)).incrementAndGet(); - } - - public void resetAttempts(String ip) { - attemptCache.invalidate(ip); - } -}