pub struct IsAuthenticated;Expand description
IsAuthenticated - requires the user to be authenticated
§Examples
use reinhardt_auth::{Permission, IsAuthenticated, PermissionContext, SimpleUser, User};
use reinhardt_http::Request;
use hyper::{Method, Uri, Version, header::HeaderMap};
use bytes::Bytes;
use uuid::Uuid;
let permission = IsAuthenticated;
let request = Request::builder()
.method(Method::GET)
.uri("/")
.version(Version::HTTP_11)
.headers(HeaderMap::new())
.body(Bytes::new())
.build()
.unwrap();
// Anonymous user - permission denied
let context = PermissionContext {
request: &request,
is_authenticated: false,
is_admin: false,
is_active: false,
user: None,
};
assert!(!permission.has_permission(&context).await);
// Authenticated user - permission granted
let user = SimpleUser {
id: Uuid::new_v4(),
username: "alice".to_string(),
email: "alice@example.com".to_string(),
is_active: true,
is_admin: false,
is_staff: false,
is_superuser: false,
};
let context = PermissionContext {
request: &request,
is_authenticated: true,
is_admin: false,
is_active: true,
user: Some(Box::new(user)),
};
assert!(permission.has_permission(&context).await);Trait Implementations§
Source§impl<B> BitAnd<B> for IsAuthenticatedwhere
B: Permission,
impl<B> BitAnd<B> for IsAuthenticatedwhere
B: Permission,
Source§type Output = AndPermission<IsAuthenticated, B>
type Output = AndPermission<IsAuthenticated, B>
The resulting type after applying the
& operator.Source§impl<B> BitOr<B> for IsAuthenticatedwhere
B: Permission,
impl<B> BitOr<B> for IsAuthenticatedwhere
B: Permission,
Source§type Output = OrPermission<IsAuthenticated, B>
type Output = OrPermission<IsAuthenticated, B>
The resulting type after applying the
| operator.Source§impl Clone for IsAuthenticated
impl Clone for IsAuthenticated
Source§fn clone(&self) -> IsAuthenticated
fn clone(&self) -> IsAuthenticated
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 Default for IsAuthenticated
impl Default for IsAuthenticated
Source§fn default() -> IsAuthenticated
fn default() -> IsAuthenticated
Returns the “default value” for a type. Read more
Source§impl Not for IsAuthenticated
impl Not for IsAuthenticated
Source§type Output = NotPermission<IsAuthenticated>
type Output = NotPermission<IsAuthenticated>
The resulting type after applying the
! operator.Source§impl Permission for IsAuthenticated
impl Permission for IsAuthenticated
Source§fn has_permission<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
context: &'life1 PermissionContext<'life2>,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
IsAuthenticated: 'async_trait,
fn has_permission<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
context: &'life1 PermissionContext<'life2>,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
IsAuthenticated: 'async_trait,
Checks if the user has permission to perform the action Read more
impl Copy for IsAuthenticated
Auto Trait Implementations§
impl Freeze for IsAuthenticated
impl RefUnwindSafe for IsAuthenticated
impl Send for IsAuthenticated
impl Sync for IsAuthenticated
impl Unpin for IsAuthenticated
impl UnsafeUnpin for IsAuthenticated
impl UnwindSafe for IsAuthenticated
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().