mirror of
https://github.com/nitnelave/lldap.git
synced 2023-04-12 14:25:13 +00:00
ldap: Add support for "dn" attribute
This commit is contained in:
parent
9874449d66
commit
438ac2818a
@ -88,7 +88,7 @@ fn get_user_id_from_distinguished_name(
|
||||
}
|
||||
}
|
||||
|
||||
fn get_user_attribute(user: &User, attribute: &str) -> Result<Vec<String>> {
|
||||
fn get_user_attribute(user: &User, attribute: &str, dn: &str) -> Result<Vec<String>> {
|
||||
match attribute {
|
||||
"objectClass" => Ok(vec![
|
||||
"inetOrgPerson".to_string(),
|
||||
@ -96,6 +96,7 @@ fn get_user_attribute(user: &User, attribute: &str) -> Result<Vec<String>> {
|
||||
"mailAccount".to_string(),
|
||||
"person".to_string(),
|
||||
]),
|
||||
"dn" => Ok(vec![dn.to_string()]),
|
||||
"uid" => Ok(vec![user.user_id.clone()]),
|
||||
"mail" => Ok(vec![user.email.clone()]),
|
||||
"givenName" => Ok(vec![user.first_name.clone()]),
|
||||
@ -112,14 +113,15 @@ fn make_ldap_search_user_result_entry(
|
||||
base_dn_str: &str,
|
||||
attributes: &[String],
|
||||
) -> Result<LdapSearchResultEntry> {
|
||||
let dn = format!("cn={},ou=people,{}", user.user_id, base_dn_str);
|
||||
Ok(LdapSearchResultEntry {
|
||||
dn: format!("cn={},ou=people,{}", user.user_id, base_dn_str),
|
||||
dn: dn.clone(),
|
||||
attributes: attributes
|
||||
.iter()
|
||||
.map(|a| {
|
||||
Ok(LdapPartialAttribute {
|
||||
atype: a.to_string(),
|
||||
vals: get_user_attribute(&user, a)?,
|
||||
vals: get_user_attribute(&user, a, &dn)?,
|
||||
})
|
||||
})
|
||||
.collect::<Result<Vec<LdapPartialAttribute>>>()?,
|
||||
@ -707,6 +709,7 @@ mod tests {
|
||||
filter: LdapFilter::And(vec![]),
|
||||
attrs: vec![
|
||||
"objectClass".to_string(),
|
||||
"dn".to_string(),
|
||||
"uid".to_string(),
|
||||
"mail".to_string(),
|
||||
"givenName".to_string(),
|
||||
@ -729,6 +732,10 @@ mod tests {
|
||||
"person".to_string()
|
||||
]
|
||||
},
|
||||
LdapPartialAttribute {
|
||||
atype: "dn".to_string(),
|
||||
vals: vec!["cn=bob_1,ou=people,dc=example,dc=com".to_string()]
|
||||
},
|
||||
LdapPartialAttribute {
|
||||
atype: "uid".to_string(),
|
||||
vals: vec!["bob_1".to_string()]
|
||||
@ -763,6 +770,10 @@ mod tests {
|
||||
"person".to_string()
|
||||
]
|
||||
},
|
||||
LdapPartialAttribute {
|
||||
atype: "dn".to_string(),
|
||||
vals: vec!["cn=jim,ou=people,dc=example,dc=com".to_string()]
|
||||
},
|
||||
LdapPartialAttribute {
|
||||
atype: "uid".to_string(),
|
||||
vals: vec!["jim".to_string()]
|
||||
|
Loading…
Reference in New Issue
Block a user