Skip to main content

SecurityExt

Trait SecurityExt 

Source
pub trait SecurityExt {
    // Required methods
    fn get_user(&self) -> Option<User>;
    fn is_authenticated(&self) -> bool;
    fn has_role(&self, role: &str) -> bool;
    fn has_any_role(&self, roles: &[&str]) -> bool;
    fn has_authority(&self, authority: &str) -> bool;
    fn has_any_authority(&self, authorities: &[&str]) -> bool;
}
Expand description

Extension trait for HttpRequest to check authentication.

Required Methods§

Source

fn get_user(&self) -> Option<User>

Returns a clone of the authenticated user if present.

Source

fn is_authenticated(&self) -> bool

Returns true if a user is authenticated.

Source

fn has_role(&self, role: &str) -> bool

Checks if the authenticated user has the specified role.

Source

fn has_any_role(&self, roles: &[&str]) -> bool

Checks if the authenticated user has any of the specified roles.

Source

fn has_authority(&self, authority: &str) -> bool

Checks if the authenticated user has the specified authority.

Source

fn has_any_authority(&self, authorities: &[&str]) -> bool

Checks if the authenticated user has any of the specified authorities.

Implementations on Foreign Types§

Source§

impl SecurityExt for HttpRequest

Source§

fn get_user(&self) -> Option<User>

Source§

fn is_authenticated(&self) -> bool

Source§

fn has_role(&self, role: &str) -> bool

Source§

fn has_any_role(&self, roles: &[&str]) -> bool

Source§

fn has_authority(&self, authority: &str) -> bool

Source§

fn has_any_authority(&self, authorities: &[&str]) -> bool

Implementors§