Add LDAP group memberships to returned data

This commit is contained in:
Alex Wright 2020-02-29 16:49:24 +01:00
parent f32681d95d
commit 998e3de74b
1 changed files with 7 additions and 1 deletions

View File

@ -48,6 +48,7 @@ pub enum AuthError {
#[derive(Debug)] #[derive(Debug)]
struct LdapUser { struct LdapUser {
pub dn: String, pub dn: String,
pub groups: Vec<String>,
pub mail: Vec<String>, pub mail: Vec<String>,
pub services: Vec<String>, pub services: Vec<String>,
} }
@ -69,7 +70,7 @@ fn auth_user(auth: &BasicAuthentication) -> Result<LdapUser, AuthError> {
}; };
let filter = format!("(uid={})", auth.username); let filter = format!("(uid={})", auth.username);
let s = match ldap.search(&base, Scope::Subtree, &filter, vec!["mail", "enabledService"]) { let s = match ldap.search(&base, Scope::Subtree, &filter, vec!["mail", "enabledService", "memberOf"]) {
Ok(result) => { Ok(result) => {
let (rs, _) = result.success().unwrap(); let (rs, _) = result.success().unwrap();
rs rs
@ -87,10 +88,15 @@ fn auth_user(auth: &BasicAuthentication) -> Result<LdapUser, AuthError> {
Some(mail) => mail.to_vec(), Some(mail) => mail.to_vec(),
None => [].to_vec(), None => [].to_vec(),
}; };
let groups = match se.attrs.get("memberOf") {
Some(groups) => groups.to_vec(),
None => [].to_vec(),
};
info!("Authentication success for {:?}", base); info!("Authentication success for {:?}", base);
Ok(LdapUser { Ok(LdapUser {
dn: base, dn: base,
groups: groups,
mail: mail, mail: mail,
services: services, services: services,
}) })