pub struct AuthContext {
pub user_id: String,
pub roles: Vec<String>,
pub permissions: Vec<String>,
}Expand description
Authentication context
Fields§
§user_id: String§roles: Vec<String>§permissions: Vec<String>Implementations§
Source§impl AuthContext
impl AuthContext
pub fn new(user_id: String) -> Self
Sourcepub fn has_permission(&self, permission: &str) -> bool
pub fn has_permission(&self, permission: &str) -> bool
Whether permission (a canonical <resource>:<action>) is among what the caller holds.
Reads self.permissions and nothing else: with no grant resolver installed that is whatever
the host’s authentication put there, with one installed it is what the resolver loaded. An
empty list holds nothing. Wildcards (ticket:*, *:read, *:*) and the legacy spellings
are matched as crate::grants describes.
Sourcepub fn require(&self, permission: &str) -> Result<(), PermissionRequired>
pub fn require(&self, permission: &str) -> Result<(), PermissionRequired>
Refuse unless the caller holds permission.
The generated routes, transitions and verbs all call this. The error carries the permission,
and answers 403 with the violation permission_required and params.permission.
Sourcepub fn require_with(
&self,
permission: &str,
alternates: &[&str],
) -> Result<(), PermissionRequired>
pub fn require_with( &self, permission: &str, alternates: &[&str], ) -> Result<(), PermissionRequired>
require, also accepting any of alternates (legacy spellings a route
still honours for one release, such as the module-wide <module>:<action>). The refusal
always names permission.