#![allow(dead_code)]
pub struct Access {
roles: Vec<&'static str>,
authorities: Vec<&'static str>,
}
impl Access {
pub fn new(roles: Vec<&'static str>, authorities: Vec<&'static str>) -> Self {
Access { roles, authorities }
}
pub fn has_role(&self, role: &str) -> bool {
self.roles.contains(&role)
}
pub fn has_authority(&self, authority: &str) -> bool {
self.authorities.contains(&authority)
}
pub fn has_any_role(&self, roles: &[&str]) -> bool {
roles.iter().any(|r| self.has_role(r))
}
pub fn has_any_authority(&self, authorities: &[&str]) -> bool {
authorities.iter().any(|a| self.has_authority(a))
}
}
pub type AccessFn = fn(access: &Access) -> bool;