Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to set named base filters #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

flartet
Copy link

@flartet flartet commented Nov 8, 2016

I realized multi-attribute queries were not possible and that the module itself was not completely made for it (attributeFilter as class variable) so I implemented the ability to set named base filters to apply to the LDAP requests. Changes are made in Directory.php and config.php

From the client, it's possible to set filters
Ldap::setNamedBaseFilters(['LDAP_EMPLOYEE_FILTER' => env('LDAP_EMPLOYEE_FILTER')]);
There is also the ability to add filters
Ldap::addNamedBaseFilters(['LDAP_EMPLOYEE_FILTER' => env('LDAP_EMPLOYEE_FILTER')]);

In my .env, here I set
LDAP_EMPLOYEE_FILTER=(&(eduPersonAffiliation=employee)#filters#)
It's a shame that you could not set arrays in .env but it's not a big deal.

To use the filter I set :
Ldap::useNamedFilter('LDAP_EMPLOYEE_FILTER')
returns true if ok or false if the name has not been set as a filter first.

Then a classic Ldap::find
Ldap::find('people')->where('supannAliasLogin', "*$username*")->get(['cn', 'supannAliasLogin']));

On the LDAP log side I have a request with
filter="(&(eduPersonAffiliation=employee)(|(supannAliasLogin=*florent*)))"
which is great for what I need.

I would be glad if you could have a look into it and integrate it or tell me what's wrong.
Thanks,
Florent.

Through 2 class variables :
$namedBaseFilters, associative array with 'baseFilterName' => 'filter with key for custom search replacement'
$currentFilterName, the name (or null), of the base filter to use
If a $currentFilterName is set, the corresponding filter is used in the main ldap request
Also 3 methods :
addNameBasedFilters / setNameBasedFilters to set the associative array of filters
useNamedFilter : to choose the base filter, it allows to switch the filter as much as needed
See comment in file. This is a more informative config option, at least to make visible the key to put in the custom base filter.
@XavRsl
Copy link
Owner

XavRsl commented Nov 10, 2016

Hi Florent,
Thank you for your work. It seems to be working. I've just tried it but I haven't got much time just now to take a closer look at it. I'll try and do that next week if it's OK with you.

Regards,

Xavier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants