pub struct LockoutPolicy { /* private fields */ }Expand description
Per-principal lockout policy. A “principal” is typically the user id (so a stuffing attack against one account can’t lock out others) or, before the user is known, the client IP.
Implementations§
Source§impl LockoutPolicy
impl LockoutPolicy
Sourcepub fn new(
backend: Arc<dyn RateLimitBackend>,
max_attempts: u32,
window_secs: u32,
) -> Self
pub fn new( backend: Arc<dyn RateLimitBackend>, max_attempts: u32, window_secs: u32, ) -> Self
max_attempts failed logins allowed per window_secs sliding window.
Sourcepub fn fail_open(self) -> Self
pub fn fail_open(self) -> Self
If the backend is unavailable, allow the attempt instead of blocking (default is fail-closed — deny). Use only when availability outranks the brute-force risk for this deployment.
Sourcepub async fn check(&self, principal: &str) -> Result<()>
pub async fn check(&self, principal: &str) -> Result<()>
Count this login attempt against the principal’s sliding window and reject once the threshold is crossed.
The backend exposes only an incrementing hit (no peek), so — exactly
like the framework’s DistributedRateLimit fronting /auth/login — this
counts every attempt, not only failures. Call it once at the top of
login, keyed by a principal that identifies the target before the user
is known (e.g. tenant + email, or the client IP), so unknown-user
probing is throttled too and the response can’t enumerate accounts.
Returns IdentityError::AccountLocked when the window is exhausted, or
IdentityError::Unavailable when the backend is down and the policy is
fail-closed (the default).
Auto Trait Implementations§
impl !RefUnwindSafe for LockoutPolicy
impl !UnwindSafe for LockoutPolicy
impl Freeze for LockoutPolicy
impl Send for LockoutPolicy
impl Sync for LockoutPolicy
impl Unpin for LockoutPolicy
impl UnsafeUnpin for LockoutPolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request