mirror of
https://github.com/nextcloud/server.git
synced 2026-06-09 16:50:55 -04:00
fix(user_ldap): Move accesses to AccessFactory instead of static var
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
8acc505aef
commit
84ba78fe6d
2 changed files with 24 additions and 19 deletions
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -7,6 +9,8 @@
|
|||
|
||||
namespace OCA\User_LDAP;
|
||||
|
||||
use OCA\User_LDAP\Mapping\GroupMapping;
|
||||
use OCA\User_LDAP\Mapping\UserMapping;
|
||||
use OCA\User_LDAP\User\Manager;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\IAppConfig;
|
||||
|
|
@ -15,6 +19,8 @@ use OCP\Server;
|
|||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class AccessFactory {
|
||||
/** @var array<string,Access> */
|
||||
private array $accesses = [];
|
||||
|
||||
public function __construct(
|
||||
private ILDAPWrapper $ldap,
|
||||
|
|
@ -23,6 +29,8 @@ class AccessFactory {
|
|||
private IUserManager $ncUserManager,
|
||||
private LoggerInterface $logger,
|
||||
private IEventDispatcher $dispatcher,
|
||||
private UserMapping $userMapping,
|
||||
private GroupMapping $groupMapping,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -39,4 +47,19 @@ class AccessFactory {
|
|||
$this->dispatcher,
|
||||
);
|
||||
}
|
||||
|
||||
public function getAccessForPrefix(string $configPrefix): Access {
|
||||
if (!isset(self::$accesses[$configPrefix])) {
|
||||
$this->addAccess($configPrefix);
|
||||
}
|
||||
return $this->accesses[$configPrefix];
|
||||
}
|
||||
|
||||
private function addAccess(string $configPrefix): void {
|
||||
$connector = new Connection($this->ldap, $configPrefix);
|
||||
$access = $this->get($connector);
|
||||
$access->setUserMapper($this->userMapping);
|
||||
$access->setGroupMapper($this->groupMapping);
|
||||
$this->accesses[$configPrefix] = $access;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@
|
|||
|
||||
namespace OCA\User_LDAP;
|
||||
|
||||
use OCA\User_LDAP\Mapping\GroupMapping;
|
||||
use OCA\User_LDAP\Mapping\UserMapping;
|
||||
use OCP\ICache;
|
||||
use OCP\ICacheFactory;
|
||||
use OCP\Server;
|
||||
|
|
@ -18,8 +16,6 @@ use OCP\Server;
|
|||
* @template T
|
||||
*/
|
||||
abstract class Proxy {
|
||||
/** @var array<string,Access> */
|
||||
private static array $accesses = [];
|
||||
private ?bool $isSingleBackend = null;
|
||||
private ?ICache $cache = null;
|
||||
|
||||
|
|
@ -71,22 +67,8 @@ abstract class Proxy {
|
|||
return $this->backends[$configPrefix];
|
||||
}
|
||||
|
||||
private function addAccess(string $configPrefix): void {
|
||||
$userMap = Server::get(UserMapping::class);
|
||||
$groupMap = Server::get(GroupMapping::class);
|
||||
|
||||
$connector = new Connection($this->ldap, $configPrefix);
|
||||
$access = $this->accessFactory->get($connector);
|
||||
$access->setUserMapper($userMap);
|
||||
$access->setGroupMapper($groupMap);
|
||||
self::$accesses[$configPrefix] = $access;
|
||||
}
|
||||
|
||||
protected function getAccess(string $configPrefix): Access {
|
||||
if (!isset(self::$accesses[$configPrefix])) {
|
||||
$this->addAccess($configPrefix);
|
||||
}
|
||||
return self::$accesses[$configPrefix];
|
||||
return $this->accessFactory->getAccessForPrefix($configPrefix);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue