Add dn filter support

Support has been added in both user and group searches
This commit is contained in:
Luca 2023-01-12 11:02:48 +01:00 committed by nitnelave
parent f979e16b95
commit aaa6b065cc
2 changed files with 32 additions and 2 deletions

View File

@ -12,7 +12,8 @@ use crate::domain::{
use super::{ use super::{
error::LdapResult, error::LdapResult,
utils::{ utils::{
expand_attribute_wildcards, get_user_id_from_distinguished_name, map_group_field, LdapInfo, expand_attribute_wildcards, get_group_id_from_distinguished_name,
get_user_id_from_distinguished_name, map_group_field, LdapInfo,
}, },
}; };
@ -126,6 +127,19 @@ fn convert_group_filter(
vec![], vec![],
)))), )))),
}, },
"dn" => Ok(
match get_group_id_from_distinguished_name(
value.to_ascii_lowercase().as_str(),
&ldap_info.base_dn,
&ldap_info.base_dn_str,
) {
Ok(value) => GroupRequestFilter::DisplayName(value),
Err(_) => {
warn!("Invalid dn filter on user: {}", value);
GroupRequestFilter::Not(Box::new(GroupRequestFilter::And(vec![])))
}
},
),
_ => match map_group_field(field) { _ => match map_group_field(field) {
Some(GroupColumn::DisplayName) => { Some(GroupColumn::DisplayName) => {
Ok(GroupRequestFilter::DisplayName(value.to_string())) Ok(GroupRequestFilter::DisplayName(value.to_string()))

View File

@ -6,7 +6,10 @@ use tracing::{debug, info, instrument, warn};
use crate::domain::{ use crate::domain::{
handler::{BackendHandler, UserRequestFilter}, handler::{BackendHandler, UserRequestFilter},
ldap::{error::LdapError, utils::expand_attribute_wildcards}, ldap::{
error::LdapError,
utils::{expand_attribute_wildcards, get_user_id_from_distinguished_name},
},
types::{GroupDetails, User, UserColumn, UserId}, types::{GroupDetails, User, UserColumn, UserId},
}; };
@ -147,6 +150,19 @@ fn convert_user_filter(ldap_info: &LdapInfo, filter: &LdapFilter) -> LdapResult<
vec![], vec![],
)))), )))),
}, },
"dn" => Ok(
match get_user_id_from_distinguished_name(
value.to_ascii_lowercase().as_str(),
&ldap_info.base_dn,
&ldap_info.base_dn_str,
) {
Ok(value) => UserRequestFilter::UserId(value),
Err(_) => {
warn!("Invalid dn filter on user: {}", value);
UserRequestFilter::Not(Box::new(UserRequestFilter::And(vec![])))
}
},
),
_ => match map_user_field(field) { _ => match map_user_field(field) {
Some(UserColumn::UserId) => Ok(UserRequestFilter::UserId(UserId::new(value))), Some(UserColumn::UserId) => Ok(UserRequestFilter::UserId(UserId::new(value))),
Some(field) => Ok(UserRequestFilter::Equality(field, value.clone())), Some(field) => Ok(UserRequestFilter::Equality(field, value.clone())),