Skip to content
Snippets Groups Projects
Verified Commit e9f12591 authored by Damien's avatar Damien
Browse files

FEAT #13273 TIME 2:20 Add ldap filters

parent c5380078
No related branches found
No related tags found
No related merge requests found
...@@ -140,6 +140,7 @@ function getUsersEntries($xmlfile) ...@@ -140,6 +140,7 @@ function getUsersEntries($xmlfile)
foreach ($xmlfile->filter->dn as $valueDN) { foreach ($xmlfile->filter->dn as $valueDN) {
if ((string)$valueDN['type'] == 'users') { if ((string)$valueDN['type'] == 'users') {
$dn = (string)$valueDN['id']; $dn = (string)$valueDN['id'];
$filters = empty((string)$valueDN->user) ? null : (string)$valueDN->user;
} }
} }
if (empty($dn)) { if (empty($dn)) {
...@@ -159,7 +160,7 @@ function getUsersEntries($xmlfile) ...@@ -159,7 +160,7 @@ function getUsersEntries($xmlfile)
return ['errors' => 'Ldap bind failed : Authentication failed']; return ['errors' => 'Ldap bind failed : Authentication failed'];
} }
$search = @ldap_search($ldap, $dn, 'cn=*'); $search = @ldap_search($ldap, $dn, ($filters ?? 'cn=*'));
if ($search === false) { if ($search === false) {
return ['errors' => 'Ldap search failed : ' . ldap_error($ldap)]; return ['errors' => 'Ldap search failed : ' . ldap_error($ldap)];
} }
...@@ -217,6 +218,7 @@ function getEntitiesEntries($xmlfile) ...@@ -217,6 +218,7 @@ function getEntitiesEntries($xmlfile)
foreach ($xmlfile->filter->dn as $valueDN) { foreach ($xmlfile->filter->dn as $valueDN) {
if ((string)$valueDN['type'] == 'entities') { if ((string)$valueDN['type'] == 'entities') {
$dn = (string)$valueDN['id']; $dn = (string)$valueDN['id'];
$filters = empty((string)$valueDN->user) ? null : (string)$valueDN->user;
} }
} }
if (empty($dn)) { if (empty($dn)) {
...@@ -236,7 +238,7 @@ function getEntitiesEntries($xmlfile) ...@@ -236,7 +238,7 @@ function getEntitiesEntries($xmlfile)
return ['errors' => 'Ldap bind failed : Authentication failed']; return ['errors' => 'Ldap bind failed : Authentication failed'];
} }
$search = ldap_search($ldap, $dn, 'cn=*'); $search = ldap_search($ldap, $dn, ($filters ?? 'cn=*'));
$entries = mb_convert_encoding(ldap_get_entries($ldap, $search), 'utf-8'); $entries = mb_convert_encoding(ldap_get_entries($ldap, $search), 'utf-8');
$ldapEntries = []; $ldapEntries = [];
......
...@@ -45,9 +45,11 @@ ...@@ -45,9 +45,11 @@
<filter> <filter>
<!-- Chemin ou se trouve les utilisateurs de l'application --> <!-- Chemin ou se trouve les utilisateurs de l'application -->
<dn id="OU=Utilisateurs,DC=maarch,DC=com" type="users"> <dn id="OU=Utilisateurs,DC=maarch,DC=com" type="users">
<user>(cn=*)</user>
</dn> </dn>
<!-- Chemin ou se trouve les entités de l'application --> <!-- Chemin ou se trouve les entités de l'application -->
<dn id="OU=Services,DC=maarch,DC=com" type="entities"> <dn id="OU=Services,DC=maarch,DC=com" type="entities">
<user>(cn=*)</user>
</dn> </dn>
</filter> </filter>
</root> </root>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment