pub struct SecurityContext { /* private fields */ }Expand description
SecurityContext encapsulates the security-related information for a request or operation.
Built by the AuthN Resolver during authentication and passed through the request lifecycle.
Gears use this context together with the AuthZ Resolver to obtain access scopes.
Implementations§
Source§impl SecurityContext
impl SecurityContext
Sourcepub fn builder() -> SecurityContextBuilder
pub fn builder() -> SecurityContextBuilder
Create a new SecurityContext builder
Sourcepub fn anonymous() -> Self
pub fn anonymous() -> Self
Create an anonymous SecurityContext with no tenant, subject, or permissions.
Use this for unauthenticated / dev / auth-disabled contexts where no authenticated subject exists.
Sourcepub fn subject_id(&self) -> Uuid
pub fn subject_id(&self) -> Uuid
Get the subject ID (user, service, or system) associated with the security context
Sourcepub fn subject_type(&self) -> Option<&str>
pub fn subject_type(&self) -> Option<&str>
Get the subject type classification (e.g., “user”, “service”).
Sourcepub fn subject_tenant_id(&self) -> Uuid
pub fn subject_tenant_id(&self) -> Uuid
Get the subject’s home tenant ID (from AuthN token).
Sourcepub fn token_scopes(&self) -> &[String]
pub fn token_scopes(&self) -> &[String]
Get the token scopes. ["*"] means first-party / unrestricted.
Sourcepub fn is_anonymous(&self) -> bool
pub fn is_anonymous(&self) -> bool
Whether this context has no authenticated subject.
Anonymity is encoded as a nil subject_id / subject_tenant_id, the
same fields a real subject uses, so there is nothing on the type that
separates the two. Every consumer that cared was re-deriving this by
hand — ctx.subject_id().is_nil() || ctx.subject_tenant_id().is_nil(),
written out identically in the ledger and pricing gears — and a caller
that forgets the check treats an unauthenticated request as a subject in
the nil tenant.
Sourcepub fn has_scope(&self, scope: &str) -> bool
pub fn has_scope(&self, scope: &str) -> bool
Whether the token carries scope.
The wildcard "*" satisfies every scope: it is what a first-party
caller presents. An empty list satisfies none — it means no capability
was granted, which is why this is the accessor to reason with rather
than the raw list, where “empty” has repeatedly been read as its
opposite.
Sourcepub fn bearer_token(&self) -> Option<&SecretString>
pub fn bearer_token(&self) -> Option<&SecretString>
Get the original bearer token (for PDP forwarding).
Trait Implementations§
Source§impl Clone for SecurityContext
impl Clone for SecurityContext
Source§fn clone(&self) -> SecurityContext
fn clone(&self) -> SecurityContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more