don't cache user, if no internal user id was retrieved/assigned
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
991190b994
commit
27f14eee26
|
@ -527,6 +527,7 @@ class Access extends LDAPUtility implements IUserTools {
|
|||
* @param bool|null $newlyMapped
|
||||
* @param array|null $record
|
||||
* @return false|string with with the name to use in Nextcloud
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, array $record = null) {
|
||||
$newlyMapped = false;
|
||||
|
@ -586,7 +587,7 @@ class Access extends LDAPUtility implements IUserTools {
|
|||
// outside of core user management will still cache the user as non-existing.
|
||||
$originalTTL = $this->connection->ldapCacheTTL;
|
||||
$this->connection->setConfiguration(array('ldapCacheTTL' => 0));
|
||||
if(($isUser && !\OCP\User::userExists($intName))
|
||||
if(($isUser && $intName !== '' && !\OCP\User::userExists($intName))
|
||||
|| (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))) {
|
||||
if($mapper->map($fdn, $intName, $uuid)) {
|
||||
$this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL));
|
||||
|
@ -830,7 +831,9 @@ class Access extends LDAPUtility implements IUserTools {
|
|||
$recordsToUpdate = array_filter($ldapRecords, function($record) use ($isBackgroundJobModeAjax) {
|
||||
$newlyMapped = false;
|
||||
$uid = $this->dn2ocname($record['dn'][0], null, true, $newlyMapped, $record);
|
||||
$this->cacheUserExists($uid);
|
||||
if(is_string($uid)) {
|
||||
$this->cacheUserExists($uid);
|
||||
}
|
||||
return ($uid !== false) && ($newlyMapped || $isBackgroundJobModeAjax);
|
||||
});
|
||||
}
|
||||
|
@ -1022,7 +1025,7 @@ class Access extends LDAPUtility implements IUserTools {
|
|||
*
|
||||
* @param $filter
|
||||
* @param $base
|
||||
* @param null $attr
|
||||
* @param string[]|string|null $attr
|
||||
* @param int $limit optional, maximum results to be counted
|
||||
* @param int $offset optional, a starting point
|
||||
* @return array|false array with the search result as first value and pagedSearchOK as
|
||||
|
@ -1106,6 +1109,7 @@ class Access extends LDAPUtility implements IUserTools {
|
|||
|
||||
/**
|
||||
* executes an LDAP search, but counts the results only
|
||||
*
|
||||
* @param string $filter the LDAP filter for the search
|
||||
* @param array $base an array containing the LDAP subtree(s) that shall be searched
|
||||
* @param string|string[] $attr optional, array, one or more attributes that shall be
|
||||
|
@ -1115,7 +1119,7 @@ class Access extends LDAPUtility implements IUserTools {
|
|||
* @param bool $skipHandling indicates whether the pages search operation is
|
||||
* completed
|
||||
* @return int|false Integer or false if the search could not be initialized
|
||||
*
|
||||
* @throws ServerNotAvailableException
|
||||
*/
|
||||
private function count($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) {
|
||||
\OCP\Util::writeLog('user_ldap', 'Count filter: '.print_r($filter, true), \OCP\Util::DEBUG);
|
||||
|
@ -1130,8 +1134,7 @@ class Access extends LDAPUtility implements IUserTools {
|
|||
$this->connection->getConnectionResource();
|
||||
|
||||
do {
|
||||
$search = $this->executeSearch($filter, $base, $attr,
|
||||
$limitPerPage, $offset);
|
||||
$search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset);
|
||||
if($search === false) {
|
||||
return $counter > 0 ? $counter : false;
|
||||
}
|
||||
|
@ -1286,7 +1289,7 @@ class Access extends LDAPUtility implements IUserTools {
|
|||
*/
|
||||
public function sanitizeUsername($name) {
|
||||
if($this->connection->ldapIgnoreNamingRules) {
|
||||
return $name;
|
||||
return trim($name);
|
||||
}
|
||||
|
||||
// Transliteration
|
||||
|
|
|
@ -620,6 +620,13 @@ class AccessTest extends TestCase {
|
|||
->method('writeToCache')
|
||||
->with($this->stringStartsWith('userExists'), true);
|
||||
|
||||
$this->userMapper->expects($this->exactly($fakeLdapEntries['count']))
|
||||
->method('getNameByDN')
|
||||
->willReturnCallback(function($fdn) {
|
||||
$parts = ldap_explode_dn($fdn, false);
|
||||
return $parts[0];
|
||||
});
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$list = $this->access->fetchListOfUsers($filter, $attrs);
|
||||
$this->assertSame($expected, $list);
|
||||
|
|
Loading…
Reference in New Issue