fabaccess-bffh/bffhd/authorization/mod.rs

29 lines
740 B
Rust
Raw Normal View History

2022-03-12 17:31:53 +01:00
use std::sync::Arc;
use crate::authorization::permissions::Permission;
2022-03-15 17:52:47 +01:00
use crate::authorization::roles::{Role, Roles};
2022-03-15 16:28:11 +01:00
use crate::Users;
2022-03-15 17:52:47 +01:00
use crate::users::UserRef;
2022-03-10 20:52:34 +01:00
pub mod permissions;
2022-03-12 17:31:53 +01:00
pub mod roles;
#[derive(Clone)]
pub struct AuthorizationHandle {
2022-03-15 16:28:11 +01:00
users: Users,
2022-03-15 17:52:47 +01:00
roles: Roles,
2022-03-12 17:31:53 +01:00
}
impl AuthorizationHandle {
2022-03-15 17:52:47 +01:00
pub fn new(users: Users, roles: Roles) -> Self {
Self { users, roles }
2022-03-12 17:31:53 +01:00
}
2022-03-15 17:52:47 +01:00
pub fn get_user_roles(&self, uid: impl AsRef<str>) -> Option<Vec<String>> {
2022-03-15 16:28:11 +01:00
let user = self.users.get_user(uid.as_ref())?;
2022-03-15 17:52:47 +01:00
Some(user.userdata.roles.clone())
2022-03-12 17:31:53 +01:00
}
pub fn is_permitted<'a>(&self, roles: impl IntoIterator<Item=&'a Role>, perm: impl AsRef<Permission>) -> bool {
unimplemented!()
}
}