pub struct Principal {
pub subject: String,
pub provider: String,
pub roles: BTreeSet<String>,
pub claims: BTreeMap<String, String>,
}Expand description
An authenticated (or anonymous) caller, carried in request extensions.
A principal is what an IdentityProvider produces from credentials and
what an Authorizer consumes. It is intentionally a flat bag of strings
so that identities from different providers (static tokens, OIDC claims,
mTLS subjects) share one shape; richer typing can come later without
changing the seam.
Fields§
§subject: StringStable subject identifier, unique within provider (e.g. an OIDC
sub, a certificate SAN, or a static-token label).
provider: StringName of the IdentityProvider that vouched for this principal.
roles: BTreeSet<String>Roles used by role-based authorizers.
claims: BTreeMap<String, String>Arbitrary provider claims (e.g. tenant, email, scope).
Implementations§
Source§impl Principal
impl Principal
Sourcepub fn anonymous() -> Self
pub fn anonymous() -> Self
The unauthenticated caller. Present whenever a surface does not require authentication, so handlers never deal with an absent identity.
Sourcepub fn new(provider: impl Into<String>, subject: impl Into<String>) -> Self
pub fn new(provider: impl Into<String>, subject: impl Into<String>) -> Self
Builds a principal with subject vouched for by provider.
Sourcepub fn with_claim(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_claim( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Adds a claim (builder style).
Sourcepub fn is_anonymous(&self) -> bool
pub fn is_anonymous(&self) -> bool
Whether this is the anonymous principal.
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<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> 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