Class CachePasswordLoginRateLimiter
java.lang.Object
io.leandev.appfuse.security.auth.CachePasswordLoginRateLimiter
- All Implemented Interfaces:
PasswordLoginRateLimiter, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationEventPublisherAware
public final class CachePasswordLoginRateLimiter
extends Object
implements PasswordLoginRateLimiter, org.springframework.context.ApplicationEventPublisherAware
同一連線 IP+trim/lowercase(ROOT) username 的滾動視窗限流。
預設五次/60 秒;被拒請求不延長視窗,成功登入不重置配額。 synchronized 僅保障同一實作物件內的讀/判定/寫入;同用途 cache 只能有一個 owner。 淘汰、重啟或 cache 故障可能失去配額;此實作不承諾全叢集硬上限。 cache expiry 只用於清理,視窗由 Clock 與已接受時間判斷,不以 TTI 滑動等待時間。
Spring bean 會自動以 AuditApplicationEvent 發出 CACHE_UNAVAILABLE/CACHE_RECOVERED; 非 Spring 消費端可顯式接入 publisher。只在 cache 邊界降級,不略過認證與 SQL Session。
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordcache 值是有界的不可變接受時間快照,不含 IP、username 或憑證。Nested classes/interfaces inherited from interface PasswordLoginRateLimiter
PasswordLoginRateLimiter.Decision -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCachePasswordLoginRateLimiter(Cache<String, CachePasswordLoginRateLimiter.Window> cache, int limit, Duration window, Clock clock) CachePasswordLoginRateLimiter(Cache<String, CachePasswordLoginRateLimiter.Window> cache, Clock clock) -
Method Summary
Modifier and TypeMethodDescriptionvoidsetApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher publisher)
-
Field Details
-
DEFAULT_LIMIT
public static final int DEFAULT_LIMIT- See Also:
-
DEFAULT_WINDOW
-
-
Constructor Details
-
CachePasswordLoginRateLimiter
public CachePasswordLoginRateLimiter(Cache<String, CachePasswordLoginRateLimiter.Window> cache, Clock clock) -
CachePasswordLoginRateLimiter
public CachePasswordLoginRateLimiter(Cache<String, CachePasswordLoginRateLimiter.Window> cache, int limit, Duration window, Clock clock)
-
-
Method Details
-
evaluate
- Specified by:
evaluatein interfacePasswordLoginRateLimiter
-
setApplicationEventPublisher
public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher publisher) - Specified by:
setApplicationEventPublisherin interfaceorg.springframework.context.ApplicationEventPublisherAware
-