LDAP: getGroups to use paged searches
This commit is contained in:
parent
5b3c9518dc
commit
1b2279c935
|
@ -206,22 +206,30 @@ class GROUP_LDAP extends lib\Access implements \OCP\GroupInterface {
|
||||||
if(!$this->enabled) {
|
if(!$this->enabled) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
$cachekey = 'getGroups-'.$search.'-'.$limit.'-'.$offset;
|
||||||
|
|
||||||
if($this->connection->isCached('getGroups')) {
|
//Check cache before driving unnecessary searches
|
||||||
$ldap_groups = $this->connection->getFromCache('getGroups');
|
\OCP\Util::writeLog('user_ldap', 'getGroups '.$cachekey, \OCP\Util::DEBUG);
|
||||||
} else {
|
$ldap_groups = $this->connection->getFromCache($cachekey);
|
||||||
$ldap_groups = $this->fetchListOfGroups($this->connection->ldapGroupFilter, array($this->connection->ldapGroupDisplayName, 'dn'));
|
if(!is_null($ldap_groups)) {
|
||||||
$ldap_groups = $this->ownCloudGroupNames($ldap_groups);
|
return $ldap_groups;
|
||||||
$this->connection->writeToCache('getGroups', $ldap_groups);
|
|
||||||
}
|
}
|
||||||
$this->groupSearch = $search;
|
|
||||||
if(!empty($this->groupSearch)) {
|
// if we'd pass -1 to LDAP search, we'd end up in a Protocol error. With a limit of 0, we get 0 results. So we pass null.
|
||||||
$ldap_groups = array_filter($ldap_groups, array($this, 'groupMatchesFilter'));
|
if($limit <= 0) {
|
||||||
}
|
|
||||||
if($limit = -1) {
|
|
||||||
$limit = null;
|
$limit = null;
|
||||||
}
|
}
|
||||||
return array_slice($ldap_groups, $offset, $limit);
|
$search = empty($search) ? '*' : '*'.$search.'*';
|
||||||
|
$filter = $this->combineFilterWithAnd(array(
|
||||||
|
$this->connection->ldapGroupFilter,
|
||||||
|
$this->connection->ldapGroupDisplayName.'='.$search
|
||||||
|
));
|
||||||
|
\OCP\Util::writeLog('user_ldap', 'getGroups Filter '.$filter, \OCP\Util::DEBUG);
|
||||||
|
$ldap_groups = $this->fetchListOfGroups($filter, array($this->connection->ldapGroupDisplayName, 'dn'), $limit, $offset);
|
||||||
|
$ldap_groups = $this->ownCloudGroupNames($ldap_groups);
|
||||||
|
|
||||||
|
$this->connection->writeToCache($cachekey, $ldap_groups);
|
||||||
|
return $ldap_groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function groupMatchesFilter($group) {
|
public function groupMatchesFilter($group) {
|
||||||
|
|
Loading…
Reference in New Issue