From 9459f53a13d15ed4355dec533030978e39b08ee6 Mon Sep 17 00:00:00 2001 From: Valentin Tolmer Date: Wed, 14 Apr 2021 21:22:08 +0200 Subject: [PATCH] Map ldap fields to internal fields --- src/infra/configuration.rs | 4 ++-- src/infra/ldap_handler.rs | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/infra/configuration.rs b/src/infra/configuration.rs index 42269d4..1491b3b 100644 --- a/src/infra/configuration.rs +++ b/src/infra/configuration.rs @@ -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, } diff --git a/src/infra/ldap_handler.rs b/src/infra/ldap_handler.rs index b7804e7..f80a2c2 100644 --- a/src/infra/ldap_handler.rs +++ b/src/infra/ldap_handler.rs @@ -77,6 +77,26 @@ fn is_subtree(subtree: &[(String, String)], base_tree: &[(String, String)]) -> b true } +fn map_field(field: &str) -> Result { + 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 { match filter { LdapFilter::And(filters) => Ok(RequestFilter::And( @@ -93,7 +113,7 @@ fn convert_filter(filter: &LdapFilter) -> Result { )), 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"), }