pub struct AuthManager { /* private fields */ }Expand description
Server-side authentication manager.
Holds user credentials, in-flight SCRAM handshakes, and active bearer tokens.
Implementations§
Source§impl AuthManager
impl AuthManager
Sourcepub fn new(users: HashMap<String, UserRecord>, token_ttl: Duration) -> Self
pub fn new(users: HashMap<String, UserRecord>, token_ttl: Duration) -> Self
Create a new AuthManager with the given user records and token TTL.
Sourcepub fn with_token_ttl(self, duration: Duration) -> Self
pub fn with_token_ttl(self, duration: Duration) -> Self
Builder method to configure the token TTL.
Sourcepub fn from_toml_str(content: &str) -> Result<Self, String>
pub fn from_toml_str(content: &str) -> Result<Self, String>
Create an AuthManager from TOML content string.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Returns true if authentication is enabled (there are registered users).
Sourcepub fn handle_hello(
&self,
username: &str,
client_first_b64: Option<&str>,
) -> Result<String, String>
pub fn handle_hello( &self, username: &str, client_first_b64: Option<&str>, ) -> Result<String, String>
Handle a HELLO request: look up user, create SCRAM handshake.
client_first_b64 is the optional base64-encoded client-first-message
containing the client nonce. If absent, the server generates a nonce
(but the handshake will fail if the client expects its own nonce).
Returns the WWW-Authenticate header value for the 401 response.
Unknown users receive a fake but plausible challenge to prevent
username enumeration.
Sourcepub fn handle_scram(
&self,
handshake_token: &str,
data: &str,
) -> Result<(String, String), String>
pub fn handle_scram( &self, handshake_token: &str, data: &str, ) -> Result<(String, String), String>
Handle a SCRAM request: verify client proof, issue auth token.
Returns (auth_token, authentication_info_header_value).
Sourcepub fn validate_token(&self, token: &str) -> Option<AuthUser>
pub fn validate_token(&self, token: &str) -> Option<AuthUser>
Validate a bearer token and return the associated user.
Returns None if the token is unknown or has expired. Expired
tokens are automatically removed under a single write lock to
avoid TOCTOU races.
Sourcepub fn revoke_token(&self, token: &str) -> bool
pub fn revoke_token(&self, token: &str) -> bool
Remove a bearer token (logout / close).
Sourcepub fn check_permission(user: &AuthUser, required: &str) -> bool
pub fn check_permission(user: &AuthUser, required: &str) -> bool
Check whether a user has a required permission.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for AuthManager
impl !RefUnwindSafe for AuthManager
impl Send for AuthManager
impl Sync for AuthManager
impl Unpin for AuthManager
impl UnsafeUnpin for AuthManager
impl UnwindSafe for AuthManager
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
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more