Map ldap fields to internal fields

This commit is contained in:
Valentin Tolmer 2021-04-14 21:22:08 +02:00
parent c48da8b758
commit 9459f53a13
2 changed files with 23 additions and 3 deletions

View file

@ -28,8 +28,8 @@ impl Default for Configuration {
http_port: 17170,
secret_pepper: String::from("secretsecretpepper"),
ldap_base_dn: String::from("dc=example,dc=com"),
ldap_user_dn: String::new(),
ldap_user_pass: String::new(),
ldap_user_dn: String::from("cn=admin,dc=example,dc=com"),
ldap_user_pass: String::from("password"),
database_url: String::from("sqlite://users.db?mode=rwc"),
verbose: false,
}

View file

@ -77,6 +77,26 @@ fn is_subtree(subtree: &[(String, String)], base_tree: &[(String, String)]) -> b
true
}
fn map_field(field: &str) -> Result<String> {
Ok(if field == "uid" {
"user_id".to_string()
} else if field == "mail" {
"email".to_string()
} else if field == "cn" {
"display_name".to_string()
} else if field == "givenName" {
"first_name".to_string()
} else if field == "sn" {
"last_name".to_string()
} else if field == "avatar" {
"avatar".to_string()
} else if field == "creationDate" {
"creation_date".to_string()
} else {
bail!("Unknown field: {}", field);
})
}
fn convert_filter(filter: &LdapFilter) -> Result<RequestFilter> {
match filter {
LdapFilter::And(filters) => Ok(RequestFilter::And(
@ -93,7 +113,7 @@ fn convert_filter(filter: &LdapFilter) -> Result<RequestFilter> {
)),
LdapFilter::Not(filter) => Ok(RequestFilter::Not(Box::new(convert_filter(&*filter)?))),
LdapFilter::Equality(field, value) => {
Ok(RequestFilter::Equality(field.clone(), value.clone()))
Ok(RequestFilter::Equality(map_field(field)?, value.clone()))
}
_ => bail!("Unsupported filter"),
}