Skip to content

Commit 55b0229

Browse files
author
robin.kluth
committed
Correct empty searchString handling.
1 parent 31b60c9 commit 55b0229

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
@@ -314,7 +314,7 @@ public function fetchUserData($attributes = "")
314314
/**
315315
* @param string $searchFor Search-Term
316316
* @param array|null $attributes Attributes to get back
317-
* @param string|null $searchFilter Filter string
317+
* @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
319319
* @param bool $onlyActiveAccounts SHould the search result only contain active accounts? => https://www.der-windows-papst.de/2016/12/18/active-directory-useraccountcontrol-values/
320320
* @return array An Array with the results, indexed by their SID
@@ -323,10 +323,6 @@ public function fetchUserData($attributes = "")
323323
public function searchUser(string $searchFor, $attributes = "", $searchFilter = "", $domainKey = false, $onlyActiveAccounts = false)
324324
{
325325

326-
if (empty($searchFor)) {
327-
throw new InvalidArgumentException("Search term is empty!");
328-
}
329-
330326
if (empty($attributes)) {
331327
$attributes = ['sn', 'objectSid', 'sIDHistory', 'givenName', 'mail', 'telephoneNumber', 'l', 'physicalDeliveryOfficeName'];
332328
}
@@ -344,6 +340,10 @@ public function searchUser(string $searchFor, $attributes = "", $searchFilter =
344340
$searchFilter = "(&(objectCategory=person)" . $onlyActive . "(|(objectSid=%searchFor%)(sIDHistory=%searchFor%)(samaccountname=*%searchFor%*)(mail=*%searchFor%*)(sn=*%searchFor%*)(givenName=*%searchFor%*)(l=%searchFor%)(physicalDeliveryOfficeName=%searchFor%)))";
345341
}
346342

343+
if (empty($searchFor) && strpos($searchFilter, '%searchFor%') === false) {
344+
throw new InvalidArgumentException("Search term is empty but the filter has a placeholder set! Set a term or set a new filter.");
345+
}
346+
347347
// Default set
348348
$domains = $this->domains;
349349

0 commit comments

Comments
 (0)