Skip to content

Commit

Permalink
[BUGFIX] Allow more than 500 users to be imported
Browse files Browse the repository at this point in the history
Related: #34
Related: #46
  • Loading branch information
xperseguers committed Oct 23, 2024
1 parent 079a6a7 commit 5f9ffc7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
7 changes: 5 additions & 2 deletions Classes/Library/Ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ public function validateUser(
* @param bool $firstEntry
* @param int $limit
* @param bool $continueLastSearch
* @param bool $usePagination
* @return array
*/
public function search(
Expand All @@ -197,7 +198,8 @@ public function search(
array $attributes = [],
bool $firstEntry = false,
int $limit = 0,
bool $continueLastSearch = false
bool $continueLastSearch = false,
bool $usePagination = true
): array
{
$result = [];
Expand All @@ -212,7 +214,8 @@ public function search(
$firstEntry ? 1 : $limit,
$timeLimit,
$dereferenceAliases,
$continueLastSearch
$continueLastSearch,
$usePagination
)) {
if ($firstEntry) {
$result = $this->ldapUtility->getFirstEntry();
Expand Down
5 changes: 3 additions & 2 deletions Classes/Library/LdapGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function selectFromMembership(
continue;
}
if ($extendedCheck) {
$ldapGroup = $ldapInstance->search($groupDn, $filter, $attributes);
$ldapGroup = $ldapInstance->search($groupDn, $filter, $attributes, false, 0, false, false);
} else {
$parts = explode(',', $groupDn);
list($firstAttribute, $value) = explode('=', $parts[0]);
Expand Down Expand Up @@ -115,7 +115,8 @@ public static function selectFromUser(
$filter = str_replace('{USERDN}', $ldapInstance->escapeDnForFilter($userDn), $filter);
$filter = str_replace('{USERUID}', $ldapInstance->escapeDnForFilter($userUid), $filter);

$groups = $ldapInstance->search($baseDn, $filter, $attributes);
// Known limitation: we support up to 500 (\Causal\IgLdapSsoAuth\Utility\LdapUtility::MAX_ENTRIES) groups per user
$groups = $ldapInstance->search($baseDn, $filter, $attributes, false, 0, false, false);
return $groups;
}

Expand Down
25 changes: 15 additions & 10 deletions Classes/Utility/LdapUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ public function search(
int $sizeLimit = 0,
int $timeLimit = 0,
int $dereferenceAliases = LDAP_DEREF_NEVER,
bool $continueLastSearch = false
bool $continueLastSearch = false,
bool $usePagination = true
): bool
{
if (!$baseDn) {
Expand All @@ -350,18 +351,22 @@ public function search(
}

if ($this->connection) {
if (!$continueLastSearch) {
// Reset the pagination cookie
$this->paginationCookie = null;
}
$controls = null;
if ($usePagination) {
if (!$continueLastSearch) {
// Reset the pagination cookie
$this->paginationCookie = null;
}

$ldapControls = ldap_read($this->connection, '', '(objectClass=*)', ['supportedControl']);
$ldapEntries = ldap_get_entries($this->connection, $ldapControls);
if (isset($ldapEntries[0]['supportedcontrol']) && in_array(LDAP_CONTROL_PAGEDRESULTS, $ldapEntries[0]['supportedcontrol'])) {
$this->hasPagination = true;
}

$ldapControls = ldap_read($this->connection, '', '(objectClass=*)', ['supportedControl']);
$ldapEntries = ldap_get_entries($this->connection, $ldapControls);
if (isset($ldapEntries[0]['supportedcontrol']) && in_array(LDAP_CONTROL_PAGEDRESULTS, $ldapEntries[0]['supportedcontrol'])) {
$this->hasPagination = true;
$controls = [['oid' => LDAP_CONTROL_PAGEDRESULTS, 'value' => ['size' => static::MAX_ENTRIES, 'cookie' => $this->paginationCookie]]];
}

$controls = [['oid' => LDAP_CONTROL_PAGEDRESULTS, 'value' => ['size' => static::MAX_ENTRIES, 'cookie' => $this->paginationCookie]]];
$this->searchResult = @ldap_search(
$this->connection,
$baseDn,
Expand Down

0 comments on commit 5f9ffc7

Please sign in to comment.