Skip to content

Commit

Permalink
Make %onlyActive% for custom filter available
Browse files Browse the repository at this point in the history
  • Loading branch information
robin.kluth committed Aug 22, 2022
1 parent 4edcc77 commit 8dd9641
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/LdapAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public function fetchUserData($attributes = "")
}

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

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

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

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

$searchFilter = str_replace("%searchFor%", addslashes($searchFor), $searchFilter);
$searchFilter = str_replace(["%searchFor%", "%onlyActive%"], [addslashes($searchFor), $onlyActive], $searchFilter);

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

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

0 comments on commit 8dd9641

Please sign in to comment.