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)]
struct LdapUser {
pub dn: String,
pub groups: Vec<String>,
pub mail: 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 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) => {
let (rs, _) = result.success().unwrap();
rs
@ -87,10 +88,15 @@ fn auth_user(auth: &BasicAuthentication) -> Result<LdapUser, AuthError> {
Some(mail) => mail.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);
Ok(LdapUser {
dn: base,
groups: groups,
mail: mail,
services: services,
})