Skip to main content

Principal

Struct Principal 

Source
pub struct Principal {
    pub subject: String,
    pub tenant: Option<String>,
    pub permissions: BTreeSet<String>,
}
Expand description

The authenticated caller: who they are, the tenant their requests are scoped to (if any), and the permissions they hold.

Built only by an Authenticator from verified credentials — never from a request argument. tenant of None means the caller is not tenant-scoped (a tenant-wide or single-tenant deployment); an empty Principal is the anonymous caller.

Fields§

§subject: String

A stable, loggable identity for the caller (the token’s subject). Never the bearer token itself. Empty for the anonymous principal.

§tenant: Option<String>

The tenant every tenant-scoped resource is constrained to, if any.

§permissions: BTreeSet<String>

The permissions the caller holds, compared verbatim against a facade method’s requires.

Implementations§

Source§

impl Principal

Source

pub fn anonymous() -> Principal

The anonymous principal: no subject, no tenant, no permissions.

Source

pub fn new<I, P>(subject: impl Into<String>, permissions: I) -> Principal
where I: IntoIterator<Item = P>, P: Into<String>,

A principal with the given subject holding permissions, belonging to no particular tenant. Use in_tenant to scope it.

Source

pub fn in_tenant<I, P>( subject: impl Into<String>, tenant: impl Into<String>, permissions: I, ) -> Principal
where I: IntoIterator<Item = P>, P: Into<String>,

A principal scoped to tenant, holding permissions.

Source

pub fn has(&self, permission: &str) -> bool

Whether the caller holds permission.

Source

pub fn owns(&self, resource_tenant: &str) -> bool

Whether the caller owns a resource belonging to resource_tenant.

True only when the caller has a tenant and it matches resource_tenant. An anonymous or tenant-less principal owns nothing — a missing tenant never grants cross-tenant access.

Trait Implementations§

Source§

impl Clone for Principal

Source§

fn clone(&self) -> Principal

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 Principal

Source§

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

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

impl Default for Principal

Source§

fn default() -> Principal

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

impl Eq for Principal

Source§

impl PartialEq for Principal

Source§

fn eq(&self, other: &Principal) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PrincipalExt for Principal

Source§

fn require_owns(&self, resource_tenant: &str) -> Result<(), Problem>

Asserts the caller owns a resource in resource_tenant, returning a 403 Problem otherwise. The advisory object-level (API1 / BOLA) counterpart to the function-level permission_guard; Scoped is the fail-closed one. Read more
Source§

impl StructuralPartialEq for Principal

Auto Trait Implementations§

§

impl Forget for Principal

§

impl Freeze for Principal
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const LeafNode<String, SetValZST> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<(String, SetValZST)>>: Freeze,

§

impl Move for Principal

§

impl RefUnwindSafe for Principal

§

impl Send for Principal
where RawVecInner: Send, NodeRef<Owned, String, SetValZST, LeafOrInternal>: Send, BoxRaw<(String, SetValZST)>: Send,

§

impl Sync for Principal
where RawVecInner: Sync, NodeRef<Owned, String, SetValZST, LeafOrInternal>: Sync, BoxRaw<(String, SetValZST)>: Sync,

§

impl Unpin for Principal
where *const u8 is !null: Unpin, *const LeafNode<String, SetValZST> is !null: Unpin, Box<(String, SetValZST)>: Unpin,

§

impl UnsafeUnpin for Principal
where *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const LeafNode<String, SetValZST> is !null: UnsafeUnpin, PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin, PhantomData<Box<(String, SetValZST)>>: UnsafeUnpin,

§

impl UnwindSafe for Principal
where RawVecInner: UnwindSafe, BTreeMap<String, SetValZST>: UnwindSafe,

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> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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