Skip to main content

Principal

Struct Principal 

#[non_exhaustive]
pub struct Principal { pub id: PrincipalId, pub user_id: String, pub roles: Vec<String>, pub scopes: Vec<String>, pub auth_method: AuthMethod, pub mfa_verified: bool, pub expires_at: u64, pub allowed_aliases: Vec<AgentAlias>, }

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§id: PrincipalId§user_id: String

Human/account identifier from the identity source (e.g. OIDC sub). Equals id.0 for a real user; sentinel for AuthMethod::SharedOperator.

§roles: Vec<String>

Coarse roles the identity source asserted (drives IamPolicy mapping).

§scopes: Vec<String>

Fine-grained scopes/capabilities granted this session.

§auth_method: AuthMethod

How this principal authenticated.

§mfa_verified: bool

Whether a second factor was completed (drives any step-up policy).

§expires_at: u64

Session expiry, UNIX seconds; 0 = no expiry.

§allowed_aliases: Vec<AgentAlias>

Agent aliases this principal MAY bind at session/new. Empty + no roles ⇒ the AuthMethod::SharedOperator fallback (“any configured alias”, today’s behaviour).

Implementations§

Source§

impl Principal

Source

pub fn shared_operator() -> Self

Source

pub fn new( id: impl Into<PrincipalId>, user_id: impl Into<String>, auth_method: AuthMethod, ) -> Self

Construct an authenticated principal with the given subject id and method. Grants default to empty; attach claims via the with_* builder setters. This is the construction path other crates (the providers) must use because the struct is #[non_exhaustive].

Source

pub fn with_roles(self, roles: Vec<String>) -> Self

Attach the role claims the identity source asserted.

Source

pub fn with_scopes(self, scopes: Vec<String>) -> Self

Attach the scope claims granted this session.

Source

pub fn with_mfa_verified(self, mfa_verified: bool) -> Self

Mark MFA as completed.

Source

pub fn with_expires_at(self, expires_at: u64) -> Self

Set the session expiry (UNIX seconds; 0 = none).

Source

pub fn with_allowed_aliases(self, allowed_aliases: Vec<AgentAlias>) -> Self

Attach the agent aliases this principal may bind.

Source

pub fn is_authenticated(&self) -> bool

true once a distinct identity source authenticated this principal — i.e. not unbound (AuthMethod::None) and not the shared-operator sentinel. A2A distinct-principal routing keys on this.

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) · §

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

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

impl<'de> Deserialize<'de> for Principal

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Principal

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · §

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Principal

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Principal

Source§

impl StructuralPartialEq for Principal

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, 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> 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,