Skip to content

Commit 8dd9641

Browse files
author
robin.kluth
committed
Make %onlyActive% for custom filter available
1 parent 4edcc77 commit 8dd9641

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/LdapAuth.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public function fetchUserData($attributes = "")
312312
}
313313

314314
/**
315-
* @param string $searchFor Search-Term
315+
* @param string|null $searchFor Search-Term
316316
* @param array|null $attributes Attributes to get back
317317
* @param string|null $searchFilter Filter string. Set %searchFor% als placeholder to search for $searchFor
318318
* @param integer $domainKey You can provide integer domainkey, this is then used as target domain! Otherwise it searches in all domains
@@ -321,7 +321,7 @@ public function fetchUserData($attributes = "")
321321
* @return array|false An Array with the results, indexed by their SID - false if an ERROR occured!
322322
* @throws \InvalidArgumentException
323323
*/
324-
public function searchUser(string $searchFor, $attributes = "", $searchFilter = "", bool $domainKey = false, bool $onlyActiveAccounts = false, bool $allDomainsHaveToBeReachable = false)
324+
public function searchUser(?string $searchFor, ?array $attributes = [], ?string $searchFilter = "", bool $domainKey = false, bool $onlyActiveAccounts = false, bool $allDomainsHaveToBeReachable = false)
325325
{
326326

327327
if (empty($attributes)) {
@@ -338,7 +338,7 @@ public function searchUser(string $searchFor, $attributes = "", $searchFilter =
338338
}
339339

340340
if (empty($searchFilter)) {
341-
$searchFilter = "(&(objectCategory=person)" . $onlyActive . "(|(objectSid=%searchFor%)(sIDHistory=%searchFor%)(samaccountname=*%searchFor%*)(mail=*%searchFor%*)(sn=*%searchFor%*)(givenName=*%searchFor%*)(l=%searchFor%)(physicalDeliveryOfficeName=%searchFor%)))";
341+
$searchFilter = "(&(objectCategory=person) %onlyActive% (|(objectSid=%searchFor%)(sIDHistory=%searchFor%)(samaccountname=*%searchFor%*)(mail=*%searchFor%*)(sn=*%searchFor%*)(givenName=*%searchFor%*)(l=%searchFor%)(physicalDeliveryOfficeName=%searchFor%)))";
342342
}
343343

344344
if (empty($searchFor) && strpos($searchFilter, '%searchFor%') !== false) {
@@ -372,7 +372,7 @@ public function searchUser(string $searchFor, $attributes = "", $searchFilter =
372372
continue;
373373
}
374374

375-
$searchFilter = str_replace("%searchFor%", addslashes($searchFor), $searchFilter);
375+
$searchFilter = str_replace(["%searchFor%", "%onlyActive%"], [addslashes($searchFor), $onlyActive], $searchFilter);
376376

377377
Yii::debug('Search-Filter: ' . $searchFilter, __METHOD__);
378378

@@ -547,7 +547,7 @@ public static function handleEntry($entry)
547547
$count = $value['count'];
548548
$newVal = "";
549549
for ($i = 0; $i < $count; $i++) {
550-
$newVal .= $value[$i];
550+
$newVal .= $value[$i]; // Concat? Wouldnt it be better to return an array with all values??
551551
}
552552
$newEntry[$attr] = $newVal;
553553
}

0 commit comments

Comments
 (0)