pub struct Principal {
pub username: String,
pub account_id: String,
pub scopes: Vec<String>,
}Expand description
Authenticated principal — attached to every authorized JMAP request by the
auth middleware (crate::auth::JmapAuthLayer).
Method handlers receive &Principal and use it to enforce that the
accountId named in each JMAP request belongs to the authenticated
caller. See Principal::owns_account.
Fields§
§username: StringUsername of the authenticated user (e.g. alice@example.com).
account_id: StringCanonical account identifier this principal owns.
JMAP requests carrying a different accountId are rejected with
JmapErrorType::Forbidden.
scopes: Vec<String>Granted scopes (e.g. capability URIs the principal is allowed to use).
An empty set means “all scopes” — refine when scope-based authorization
is wired in (see follow-ups in TODO.md).
Implementations§
Source§impl Principal
impl Principal
Sourcepub fn from_username(username: impl Into<String>) -> Self
pub fn from_username(username: impl Into<String>) -> Self
Build a principal from a username, deriving the canonical account_id
the same way the session endpoint does.
Sourcepub fn owns_account(&self, requested_account_id: &str) -> bool
pub fn owns_account(&self, requested_account_id: &str) -> bool
True iff requested_account_id equals this principal’s owned account
OR this principal has been granted the SCOPE_ADMIN scope.
Trait Implementations§
impl Eq for Principal
impl StructuralPartialEq for Principal
Auto Trait Implementations§
impl Freeze for Principal
impl RefUnwindSafe for Principal
impl Send for Principal
impl Sync for Principal
impl Unpin for Principal
impl UnsafeUnpin for Principal
impl UnwindSafe for Principal
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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>
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>
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request