actix_security_core/http/auth/
access.rs1#![allow(dead_code)]
10
11pub struct Access {
15 roles: Vec<&'static str>,
16 authorities: Vec<&'static str>,
17}
18
19impl Access {
20 pub fn new(roles: Vec<&'static str>, authorities: Vec<&'static str>) -> Self {
21 Access { roles, authorities }
22 }
23
24 pub fn has_role(&self, role: &str) -> bool {
25 self.roles.contains(&role)
26 }
27
28 pub fn has_authority(&self, authority: &str) -> bool {
29 self.authorities.contains(&authority)
30 }
31
32 pub fn has_any_role(&self, roles: &[&str]) -> bool {
33 roles.iter().any(|r| self.has_role(r))
34 }
35
36 pub fn has_any_authority(&self, authorities: &[&str]) -> bool {
37 authorities.iter().any(|a| self.has_authority(a))
38 }
39}
40
41pub type AccessFn = fn(access: &Access) -> bool;