pub struct AuthenticatedUser(/* private fields */);Expand description
Extractor for the authenticated user.
§Spring Equivalent
@AuthenticationPrincipal User user parameter or SecurityContextHolder.getContext().getAuthentication().getPrincipal()
§Usage
ⓘ
use actix_security_core::http::security::AuthenticatedUser;
async fn handler(user: AuthenticatedUser) -> impl Responder {
format!("Hello, {}!", user.get_username())
}§Errors
Returns 401 Unauthorized if the user is not authenticated.
Implementations§
Source§impl AuthenticatedUser
impl AuthenticatedUser
Sourcepub fn new(user: User) -> AuthenticatedUser
pub fn new(user: User) -> AuthenticatedUser
Creates a new AuthenticatedUser wrapper.
Sourcepub fn into_inner(self) -> User
pub fn into_inner(self) -> User
Returns the inner User.
Methods from Deref<Target = User>§
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.
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 Clone for AuthenticatedUser
impl Clone for AuthenticatedUser
Source§fn clone(&self) -> AuthenticatedUser
fn clone(&self) -> AuthenticatedUser
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for AuthenticatedUser
impl Debug for AuthenticatedUser
Source§impl Deref for AuthenticatedUser
impl Deref for AuthenticatedUser
Source§impl FromRequest for AuthenticatedUser
impl FromRequest for AuthenticatedUser
Source§type Future = Ready<Result<AuthenticatedUser, <AuthenticatedUser as FromRequest>::Error>>
type Future = Ready<Result<AuthenticatedUser, <AuthenticatedUser as FromRequest>::Error>>
Future that resolves to a
Self. Read moreSource§fn from_request(
req: &HttpRequest,
_payload: &mut Payload,
) -> <AuthenticatedUser as FromRequest>::Future
fn from_request( req: &HttpRequest, _payload: &mut Payload, ) -> <AuthenticatedUser as FromRequest>::Future
Create a
Self from request parts asynchronously.Auto Trait Implementations§
impl Freeze for AuthenticatedUser
impl RefUnwindSafe for AuthenticatedUser
impl Send for AuthenticatedUser
impl Sync for AuthenticatedUser
impl Unpin for AuthenticatedUser
impl UnwindSafe for AuthenticatedUser
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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