pub struct IsAuthenticatedOrReadOnly;Expand description
IsAuthenticatedOrReadOnly - authenticated for writes, allow reads
This permission allows read-only access (GET, HEAD, OPTIONS) to all users, but requires authentication for write operations (POST, PUT, PATCH, DELETE).
§Examples
use reinhardt_auth::{Permission, IsAuthenticatedOrReadOnly, PermissionContext};
use reinhardt_http::Request;
use hyper::{Method, Uri, Version, header::HeaderMap};
use bytes::Bytes;
let permission = IsAuthenticatedOrReadOnly;
// GET request from anonymous user - allowed
let mut request = Request::builder()
.method(Method::GET)
.uri("/")
.version(Version::HTTP_11)
.headers(HeaderMap::new())
.body(Bytes::new())
.build()
.unwrap();
request.method = Method::GET;
let context = PermissionContext {
request: &request,
is_authenticated: false,
is_admin: false,
is_active: false,
user: None,
};
assert!(permission.has_permission(&context).await);
// POST request from anonymous user - denied
request.method = Method::POST;
let context = PermissionContext {
request: &request,
is_authenticated: false,
is_admin: false,
is_active: false,
user: None,
};
assert!(!permission.has_permission(&context).await);
// POST request from authenticated user - allowed
let context = PermissionContext {
request: &request,
is_authenticated: true,
is_admin: false,
is_active: true,
user: None,
};
assert!(permission.has_permission(&context).await);Trait Implementations§
Source§impl<B> BitAnd<B> for IsAuthenticatedOrReadOnlywhere
B: Permission,
impl<B> BitAnd<B> for IsAuthenticatedOrReadOnlywhere
B: Permission,
Source§type Output = AndPermission<IsAuthenticatedOrReadOnly, B>
type Output = AndPermission<IsAuthenticatedOrReadOnly, B>
The resulting type after applying the
& operator.Source§impl<B> BitOr<B> for IsAuthenticatedOrReadOnlywhere
B: Permission,
impl<B> BitOr<B> for IsAuthenticatedOrReadOnlywhere
B: Permission,
Source§type Output = OrPermission<IsAuthenticatedOrReadOnly, B>
type Output = OrPermission<IsAuthenticatedOrReadOnly, B>
The resulting type after applying the
| operator.Source§impl Clone for IsAuthenticatedOrReadOnly
impl Clone for IsAuthenticatedOrReadOnly
Source§fn clone(&self) -> IsAuthenticatedOrReadOnly
fn clone(&self) -> IsAuthenticatedOrReadOnly
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 IsAuthenticatedOrReadOnly
impl Default for IsAuthenticatedOrReadOnly
Source§fn default() -> IsAuthenticatedOrReadOnly
fn default() -> IsAuthenticatedOrReadOnly
Returns the “default value” for a type. Read more
Source§impl Not for IsAuthenticatedOrReadOnly
impl Not for IsAuthenticatedOrReadOnly
Source§type Output = NotPermission<IsAuthenticatedOrReadOnly>
type Output = NotPermission<IsAuthenticatedOrReadOnly>
The resulting type after applying the
! operator.Source§impl Permission for IsAuthenticatedOrReadOnly
impl Permission for IsAuthenticatedOrReadOnly
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,
IsAuthenticatedOrReadOnly: '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,
IsAuthenticatedOrReadOnly: 'async_trait,
Checks if the user has permission to perform the action Read more
impl Copy for IsAuthenticatedOrReadOnly
Auto Trait Implementations§
impl Freeze for IsAuthenticatedOrReadOnly
impl RefUnwindSafe for IsAuthenticatedOrReadOnly
impl Send for IsAuthenticatedOrReadOnly
impl Sync for IsAuthenticatedOrReadOnly
impl Unpin for IsAuthenticatedOrReadOnly
impl UnsafeUnpin for IsAuthenticatedOrReadOnly
impl UnwindSafe for IsAuthenticatedOrReadOnly
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().