Class DefaultLoginAttemptTracker
java.lang.Object
io.leandev.appfuse.security.lockout.core.DefaultLoginAttemptTracker
- All Implemented Interfaces:
LoginAttemptTracker
預設登入嘗試追蹤器實作
整合 AttemptStore 與 LockoutPolicy,提供完整的登入鎖定機制。
業務邏輯:
- 記錄失敗:累加失敗次數,達到閾值時觸發鎖定
- 檢查鎖定:判斷鎖定是否仍有效(到期時間 > 當前時間)
- 清除記錄:登入成功時清除所有記錄
鎖定期間行為:
- 鎖定期間的登入嘗試不增加失敗次數
- 鎖定到期後自動解除,使用者可繼續嘗試
- 鎖定到期後若再次失敗,失敗次數繼續累計
執行緒安全性:依賴 AttemptStore 實作的執行緒安全性。
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultLoginAttemptTracker(AttemptStore store, LockoutPolicy policy) 建構預設登入嘗試追蹤器 -
Method Summary
Modifier and TypeMethodDescriptionvoidclearAttempts(String principal) 清除失敗記錄intgetFailureCount(String principal) 取得當前失敗次數getRemainingLockoutTime(String principal) 取得剩餘鎖定時間boolean檢查帳號是否已鎖定intrecordFailure(String principal) 記錄登入失敗
-
Constructor Details
-
DefaultLoginAttemptTracker
建構預設登入嘗試追蹤器- Parameters:
store- 儲存機制policy- 鎖定策略
-
-
Method Details
-
recordFailure
Description copied from interface:LoginAttemptTracker記錄登入失敗
每次呼叫會累加失敗次數,當達到閾值時自動觸發鎖定機制。
- Specified by:
recordFailurein interfaceLoginAttemptTracker- Parameters:
principal- 使用者帳號- Returns:
- 當前失敗次數
-
isLocked
Description copied from interface:LoginAttemptTracker檢查帳號是否已鎖定
判斷標準:鎖定到期時間存在且晚於當前時間。
- Specified by:
isLockedin interfaceLoginAttemptTracker- Parameters:
principal- 使用者帳號- Returns:
- true 表示已鎖定,false 表示未鎖定
-
getRemainingLockoutTime
Description copied from interface:LoginAttemptTracker取得剩餘鎖定時間- Specified by:
getRemainingLockoutTimein interfaceLoginAttemptTracker- Parameters:
principal- 使用者帳號- Returns:
- 剩餘時間,若未鎖定或已過期則回傳 empty
-
clearAttempts
Description copied from interface:LoginAttemptTracker清除失敗記錄
通常在登入成功時呼叫,清除該使用者的所有失敗記錄與鎖定狀態。
- Specified by:
clearAttemptsin interfaceLoginAttemptTracker- Parameters:
principal- 使用者帳號
-
getFailureCount
Description copied from interface:LoginAttemptTracker取得當前失敗次數- Specified by:
getFailureCountin interfaceLoginAttemptTracker- Parameters:
principal- 使用者帳號- Returns:
- 失敗次數,若無記錄則回傳 0
-