pub struct User { /* private fields */ }Expand description
Represents an authenticated user with roles and authorities.
§Spring Equivalent
UserDetails / User
§Example
use actix_security_core::http::security::User;
let user = User::new("admin".into(), "password".into())
.roles(&["ADMIN".into(), "USER".into()])
.authorities(&["users:read".into(), "users:write".into()]);
assert!(user.has_role("ADMIN"));
assert!(user.has_authority("users:read"));Implementations§
Source§impl User
impl User
Sourcepub fn new(username: String, password: String) -> User
pub fn new(username: String, password: String) -> User
Creates a new user with username and plain-text password.
§Note
For production use, prefer with_encoded_password with a proper
password encoder like Argon2.
Sourcepub fn with_encoded_password(username: &str, encoded_password: String) -> User
pub fn with_encoded_password(username: &str, encoded_password: String) -> User
Creates a new user with username and pre-encoded password.
§Spring Security Equivalent
User.withUsername().password("{bcrypt}$2a$...").build()
§Example
use actix_security_core::http::security::{User, Argon2PasswordEncoder, PasswordEncoder};
let encoder = Argon2PasswordEncoder::new();
let encoded = encoder.encode("secret");
let user = User::with_encoded_password("admin", encoded)
.roles(&["ADMIN".into()]);Sourcepub fn get_username(&self) -> &str
pub fn get_username(&self) -> &str
Returns the username.
Sourcepub fn get_password(&self) -> &str
pub fn get_password(&self) -> &str
Returns the password (for authentication checks).
Returns the user’s authorities.
Adds authorities to the user (builder pattern).
Sourcepub fn has_any_role(&self, roles: &[&str]) -> bool
pub fn has_any_role(&self, roles: &[&str]) -> bool
Checks if the user has ANY of the specified roles (OR logic).
Sourcepub fn has_all_roles(&self, roles: &[&str]) -> bool
pub fn has_all_roles(&self, roles: &[&str]) -> bool
Checks if the user has ALL of the specified roles (AND logic).
Checks if the user has a specific authority.
Checks if the user has ANY of the specified authorities (OR logic).
Checks if the user has ALL of the specified authorities (AND logic).
Trait Implementations§
Source§impl From<&User> for SessionUser
impl From<&User> for SessionUser
Source§fn from(user: &User) -> SessionUser
fn from(user: &User) -> SessionUser
Source§impl From<SessionUser> for User
impl From<SessionUser> for User
Source§fn from(session_user: SessionUser) -> User
fn from(session_user: SessionUser) -> User
Auto Trait Implementations§
impl Freeze for User
impl RefUnwindSafe for User
impl Send for User
impl Sync for User
impl Unpin for User
impl UnwindSafe for User
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 moreSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.