acl: Return details to caller when authenticating user

This commit is contained in:
George Kaklamanos 2023-11-20 21:36:28 +02:00
parent 6d752cd050
commit 3215630aab
No known key found for this signature in database
GPG key ID: C0CAB8A6BDC9399D

View file

@ -20,6 +20,13 @@ pub struct ResourceShortcuts {
pub id: i8, pub id: i8,
} }
#[derive(Deserialize, Debug)]
pub struct LogEntry {
pub username: String,
pub resource: String,
pub method: String,
}
impl PartialEq for AuthMethod { impl PartialEq for AuthMethod {
fn eq(&self, other: &Self) -> bool{ fn eq(&self, other: &Self) -> bool{
(self.method == other.method) (self.method == other.method)
@ -82,13 +89,22 @@ pub trait ACL {
self.add_shortcut(username, resource, shortcut); self.add_shortcut(username, resource, shortcut);
} }
fn auth_user(&self, method: String, identifier: String, shortcut: i8) { fn auth_user(&self, method: String, identifier: String, shortcut: i8) -> Option<LogEntry> {
if let Some(username) = self.get_username(method, identifier) { let mut ret = None;
if let Some(username) = self.get_username(method.clone(), identifier) {
if let Some(resource) = self.get_resource(username.clone(), shortcut) { if let Some(resource) = self.get_resource(username.clone(), shortcut) {
if self.is_allowed(username.clone(), resource).is_some() { if self
println!("Open Sesame! {}", username); .is_allowed(username.clone(), resource.clone())
.is_some()
{
ret = Some(LogEntry {
username,
resource,
method,
});
} }
} }
} }
ret
} }
} }