Class CacheAttemptStore

java.lang.Object
io.leandev.appfuse.security.lockout.store.CacheAttemptStore
All Implemented Interfaces:
AttemptStore

public class CacheAttemptStore extends Object implements AttemptStore

快取儲存實作

使用 AppFuse Cache 儲存失敗次數與鎖定狀態。

適用場景

  • 需要自動過期清理的環境
  • 需要統一快取監控的環境
  • 未來需要擴充 Redis 支援分散式的環境

優點

  • 支援 TTL/TTI 自動過期,避免記憶體持續增長
  • 與其他快取(如 token 黑名單)使用相同技術棧
  • 支援統計與監控功能
  • 未來可透過 Redis 實作支援分散式部署

執行緒安全性:依賴底層 Cache 實作的執行緒安全性。

Since:
1.0
  • Constructor Details

    • CacheAttemptStore

      public CacheAttemptStore(Cache<String, AttemptRecord> cache)
      建構快取儲存實作
      Parameters:
      cache - 快取實例
  • Method Details

    • getFailureCount

      public int getFailureCount(String principal)
      Description copied from interface: AttemptStore
      取得使用者的失敗次數
      Specified by:
      getFailureCount in interface AttemptStore
      Parameters:
      principal - 使用者帳號
      Returns:
      失敗次數,若無記錄則回傳 0
    • incrementFailureCount

      public int incrementFailureCount(String principal)
      Description copied from interface: AttemptStore
      遞增使用者的失敗次數
      Specified by:
      incrementFailureCount in interface AttemptStore
      Parameters:
      principal - 使用者帳號
      Returns:
      遞增後的失敗次數
    • setLockoutTime

      public void setLockoutTime(String principal, LocalDateTime unlockTime)
      Description copied from interface: AttemptStore
      設定使用者的鎖定到期時間
      Specified by:
      setLockoutTime in interface AttemptStore
      Parameters:
      principal - 使用者帳號
      unlockTime - 鎖定到期時間
    • getLockoutTime

      public Optional<LocalDateTime> getLockoutTime(String principal)
      Description copied from interface: AttemptStore
      取得使用者的鎖定到期時間
      Specified by:
      getLockoutTime in interface AttemptStore
      Parameters:
      principal - 使用者帳號
      Returns:
      鎖定到期時間,若無記錄則回傳 empty
    • clear

      public void clear(String principal)
      Description copied from interface: AttemptStore
      清除使用者的所有記錄(失敗次數與鎖定狀態)
      Specified by:
      clear in interface AttemptStore
      Parameters:
      principal - 使用者帳號