Struct Subject
pub struct Subject(/* private fields */);Expand description
Authorization subject for Casbin policy checks and resource isolation.
A simple newtype over Option<String>:
Some(name)= authenticated user with bare usernameNone= anonymous (unauthenticated)
All identity types (Local, ApiToken, Peer, Claims) produce bare usernames. There are no namespace prefixes — a user named “alice” is just “alice” regardless of how they authenticated.
§Display
Subject::new("alice") displays as "alice", used directly
as the Casbin subject string. Anonymous displays as "anonymous".
§Validation
validate() ensures names contain only [a-zA-Z0-9._-].
Implementations§
§impl Subject
impl Subject
pub fn new(name: impl Into<String>) -> Subject
pub fn new(name: impl Into<String>) -> Subject
Create an authenticated subject with the given username.
pub fn is_anonymous(&self) -> bool
pub fn is_anonymous(&self) -> bool
Check if this subject is anonymous.
pub fn validate(&self) -> Result<(), Error>
pub fn validate(&self) -> Result<(), Error>
Validate that the name contains only safe characters [a-zA-Z0-9._-].
This prevents path traversal and other injection attacks when the subject is used in filesystem paths or policy strings.
Note: federated subjects (containing ://) intentionally bypass this
validation — call validate() only for local subjects.
pub fn federated(iss: &str, sub: &str) -> Subject
pub fn federated(iss: &str, sub: &str) -> Subject
Create a federated subject for a principal from a foreign issuer.
Format: "{issuer_url}:{local_sub}" — for example
"https://node-a:alice". The :// in the URL makes federated subjects
unambiguously distinguishable from local bare usernames.
The resulting subject is used directly as the Casbin subject string so federation-aware policies can match on the issuer prefix.
pub fn is_federated(&self) -> bool
pub fn is_federated(&self) -> bool
Returns true if this subject originated from a foreign issuer.
Federated subjects contain "://" (from the issuer URL); local bare
usernames never do.
Trait Implementations§
impl Eq for Subject
impl StructuralPartialEq for Subject
Auto Trait Implementations§
impl Freeze for Subject
impl RefUnwindSafe for Subject
impl Send for Subject
impl Sync for Subject
impl Unpin for Subject
impl UnsafeUnpin for Subject
impl UnwindSafe for Subject
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,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more