Skip to main content

Access

Enum Access 

Source
pub enum Access {
    None,
    User(Arc<User>),
}
Expand description

Authorization decision attached to a request Context.

Closed enum (no dyn): the dispatch layer reads ctx.access.can_read_table(db, t) and the compiler devirtualizes to a stack-resident match. Customer authentication plugins extend via AuthProvider — they produce an AuthIdentity which the framework resolves into a User; they do not implement Access directly.

Variants§

§

None

Unauthenticated request. Every permission check returns false; the only way through is a resource that explicitly opts into public access (e.g. via @access(public: [read])).

§

User(Arc<User>)

Authenticated user — RBAC decisions delegate to the inner User. Wrapped in Arc so cloning Access across the request pipeline is one atomic bump, not a deep Role copy.

Implementations§

Source§

impl Access

Source

pub const fn is_authenticated(&self) -> bool

true if the request authenticated as a user (any user).

Source

pub fn is_super_user(&self) -> bool

true if the request authenticated as a super-user role.

Source

pub fn role(&self) -> &str

Role identifier of the authenticated user, or empty string if unauthenticated.

Source

pub fn username(&self) -> &str

Username of the authenticated user, or empty string if unauthenticated.

Source

pub fn user(&self) -> Option<&User>

Some(user) if authenticated, None otherwise. Useful when the caller needs to reach into User-specific fields beyond the helper methods on Access.

Source

pub fn can_read_table(&self, database: &str, table: &str) -> bool

May the requester read records from database.table?

Source

pub fn can_insert_table(&self, database: &str, table: &str) -> bool

May the requester insert records into database.table?

Source

pub fn can_update_table(&self, database: &str, table: &str) -> bool

May the requester update records in database.table?

Source

pub fn can_delete_table(&self, database: &str, table: &str) -> bool

May the requester delete records from database.table?

Source

pub fn can_read_attribute( &self, database: &str, table: &str, attr: &str, ) -> bool

May the requester read field attr on database.table?

Source

pub fn can_write_attribute( &self, database: &str, table: &str, attr: &str, ) -> bool

May the requester write field attr on database.table?

Source

pub fn has_unrestricted_attributes(&self, database: &str, table: &str) -> bool

true if no per-attribute restrictions apply for database.table. Access::None returns true here because there is no user whose attribute grants need consulting — callers gate on is_authenticated separately if they need to distinguish “no user” from “user with full attributes”.

Source

pub fn filter_readable_attributes<'a>( &self, database: &str, table: &str, attrs: &[&'a str], ) -> Vec<&'a str>

Filter attrs to only those the requester may read on database.table. Super-users keep the full list; unauthenticated requests get an empty list.

Source

pub fn validate_writable_attributes( &self, database: &str, table: &str, attrs: &[&str], ) -> Result<(), Vec<String>>

Verify every attribute in attrs is writable. Super-users always succeed; unauthenticated requests fail listing every attribute as unauthorized.

§Errors

Returns Err(unauthorized) with the list of attribute names the requester may not write.

Source

pub fn filter_record(&self, database: &str, table: &str, record: &mut Value)

Filter a JSON object in-place, retaining only attributes the requester may read. Super-users pass-through. Unauthenticated requests reduce the object to empty.

Source

pub fn filter_records(&self, database: &str, table: &str, records: &mut [Value])

Filter every record in records via filter_record.

Trait Implementations§

Source§

impl Clone for Access

Source§

fn clone(&self) -> Access

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Access

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Access

Source§

fn default() -> Access

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more