2020-10-26 12:58:55 +01:00
|
|
|
use serde::{Serialize, Deserialize};
|
|
|
|
use std::fmt;
|
|
|
|
use crate::db::access::RoleIdentifier;
|
2020-10-28 16:25:33 +01:00
|
|
|
use std::collections::HashMap;
|
2020-10-26 12:58:55 +01:00
|
|
|
|
|
|
|
/// A Person, from the Authorization perspective
|
2020-11-10 14:56:28 +01:00
|
|
|
#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)]
|
2020-11-24 14:16:22 +01:00
|
|
|
pub struct AuthzContext {
|
2020-10-28 16:25:33 +01:00
|
|
|
/// The identification of this user.
|
|
|
|
pub id: UserIdentifier,
|
2020-10-26 12:58:55 +01:00
|
|
|
|
|
|
|
/// A Person has N ≥ 0 roles.
|
|
|
|
/// Persons are only ever given roles, not permissions directly
|
2020-10-28 16:25:33 +01:00
|
|
|
pub roles: Vec<RoleIdentifier>,
|
|
|
|
|
|
|
|
/// Additional data storage
|
|
|
|
#[serde(flatten)]
|
|
|
|
kv: HashMap<Box<[u8]>, Box<[u8]>>,
|
2020-10-26 12:58:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for UserIdentifier {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2020-11-24 14:16:22 +01:00
|
|
|
let r = write!(f, "{}", self.uid)?;
|
2020-10-28 23:24:02 +01:00
|
|
|
if let Some(ref s) = self.subuid {
|
2020-10-26 12:58:55 +01:00
|
|
|
write!(f, "+{}", s)?;
|
|
|
|
}
|
2020-10-28 23:24:02 +01:00
|
|
|
if let Some(ref l) = self.location {
|
2020-10-26 12:58:55 +01:00
|
|
|
write!(f, "@{}", l)?;
|
|
|
|
}
|
2020-11-24 14:16:22 +01:00
|
|
|
Ok(r)
|
2020-10-26 12:58:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// User Database Trait
|
|
|
|
pub trait UserDB {
|
|
|
|
fn get_user(&self, uid: UserIdentifier) -> Option<User>;
|
|
|
|
}
|