aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2025-01-30 11:49:58 +0100
committerAndy Scherzinger <info@andy-scherzinger.de>2025-02-09 21:55:34 +0100
commit8eb0041df8689b339efb251ea0776515d5cabaaf (patch)
tree284b99c46afad6af089c7786f79a7b12cc11936c /apps
parent4b12c1cd3293b0b123622a891e2497271c61efb9 (diff)
downloadnextcloud-server-8eb0041df8689b339efb251ea0776515d5cabaaf.tar.gz
nextcloud-server-8eb0041df8689b339efb251ea0776515d5cabaaf.zip
feat(user_ldap): upstream common code into Proxy class and add public getters for backends
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/user_ldap/lib/Group_Proxy.php25
-rw-r--r--apps/user_ldap/lib/Proxy.php41
-rw-r--r--apps/user_ldap/lib/User_Proxy.php40
3 files changed, 59 insertions, 47 deletions
diff --git a/apps/user_ldap/lib/Group_Proxy.php b/apps/user_ldap/lib/Group_Proxy.php
index 8ed3a5dd87d..2c9c6acfdd3 100644
--- a/apps/user_ldap/lib/Group_Proxy.php
+++ b/apps/user_ldap/lib/Group_Proxy.php
@@ -18,11 +18,10 @@ use OCP\GroupInterface;
use OCP\IConfig;
use OCP\IUserManager;
+/**
+ * @template-extends Proxy<Group_LDAP>
+ */
class Group_Proxy extends Proxy implements GroupInterface, IGroupLDAP, IGetDisplayNameBackend, INamedBackend, IDeleteGroupBackend, IBatchMethodsBackend, IIsAdminBackend {
- private $backends = [];
- private ?Group_LDAP $refBackend = null;
- private bool $isSetUp = false;
-
public function __construct(
private Helper $helper,
ILDAPWrapper $ldap,
@@ -31,24 +30,12 @@ class Group_Proxy extends Proxy implements GroupInterface, IGroupLDAP, IGetDispl
private IConfig $config,
private IUserManager $ncUserManager,
) {
- parent::__construct($ldap, $accessFactory);
+ parent::__construct($helper, $ldap, $accessFactory);
}
- protected function setup(): void {
- if ($this->isSetUp) {
- return;
- }
-
- $serverConfigPrefixes = $this->helper->getServerConfigurationPrefixes(true);
- foreach ($serverConfigPrefixes as $configPrefix) {
- $this->backends[$configPrefix] =
- new Group_LDAP($this->getAccess($configPrefix), $this->groupPluginManager, $this->config, $this->ncUserManager);
- if (is_null($this->refBackend)) {
- $this->refBackend = $this->backends[$configPrefix];
- }
- }
- $this->isSetUp = true;
+ protected function newInstance(string $configPrefix): Group_LDAP {
+ return new Group_LDAP($this->getAccess($configPrefix), $this->groupPluginManager, $this->config, $this->ncUserManager);
}
/**
diff --git a/apps/user_ldap/lib/Proxy.php b/apps/user_ldap/lib/Proxy.php
index ab8b9f451f0..fe86519884d 100644
--- a/apps/user_ldap/lib/Proxy.php
+++ b/apps/user_ldap/lib/Proxy.php
@@ -12,13 +12,24 @@ use OCA\User_LDAP\Mapping\UserMapping;
use OCP\ICache;
use OCP\Server;
+/**
+ * @template T
+ */
abstract class Proxy {
/** @var array<string,Access> */
private static array $accesses = [];
private ?bool $isSingleBackend = null;
private ?ICache $cache = null;
+ /** @var T[] */
+ protected array $backends = [];
+ /** @var ?T */
+ protected $refBackend = null;
+
+ protected bool $isSetUp = false;
+
public function __construct(
+ private Helper $helper,
private ILDAPWrapper $ldap,
private AccessFactory $accessFactory,
) {
@@ -28,6 +39,36 @@ abstract class Proxy {
}
}
+ protected function setup(): void {
+ if ($this->isSetUp) {
+ return;
+ }
+
+ $serverConfigPrefixes = $this->helper->getServerConfigurationPrefixes(true);
+ foreach ($serverConfigPrefixes as $configPrefix) {
+ $this->backends[$configPrefix] = $this->newInstance($configPrefix);
+
+ if (is_null($this->refBackend)) {
+ $this->refBackend = $this->backends[$configPrefix];
+ }
+ }
+
+ $this->isSetUp = true;
+ }
+
+ /**
+ * @return T
+ */
+ abstract protected function newInstance(string $configPrefix): object;
+
+ /**
+ * @return T
+ */
+ public function getBackend(string $configPrefix): object {
+ $this->setup();
+ return $this->backends[$configPrefix];
+ }
+
private function addAccess(string $configPrefix): void {
$userMap = Server::get(UserMapping::class);
$groupMap = Server::get(GroupMapping::class);
diff --git a/apps/user_ldap/lib/User_Proxy.php b/apps/user_ldap/lib/User_Proxy.php
index 5079830b83c..2739cdeba67 100644
--- a/apps/user_ldap/lib/User_Proxy.php
+++ b/apps/user_ldap/lib/User_Proxy.php
@@ -18,13 +18,10 @@ use OCP\User\Backend\IProvideEnabledStateBackend;
use OCP\UserInterface;
use Psr\Log\LoggerInterface;
+/**
+ * @template-extends Proxy<User_LDAP>
+ */
class User_Proxy extends Proxy implements IUserBackend, UserInterface, IUserLDAP, ILimitAwareCountUsersBackend, ICountMappedUsersBackend, IProvideEnabledStateBackend {
- /** @var User_LDAP[] */
- private array $backends = [];
- private ?User_LDAP $refBackend = null;
-
- private bool $isSetUp = false;
-
public function __construct(
private Helper $helper,
ILDAPWrapper $ldap,
@@ -34,30 +31,17 @@ class User_Proxy extends Proxy implements IUserBackend, UserInterface, IUserLDAP
private LoggerInterface $logger,
private DeletedUsersIndex $deletedUsersIndex,
) {
- parent::__construct($ldap, $accessFactory);
+ parent::__construct($helper, $ldap, $accessFactory);
}
- protected function setup(): void {
- if ($this->isSetUp) {
- return;
- }
-
- $serverConfigPrefixes = $this->helper->getServerConfigurationPrefixes(true);
- foreach ($serverConfigPrefixes as $configPrefix) {
- $this->backends[$configPrefix] = new User_LDAP(
- $this->getAccess($configPrefix),
- $this->notificationManager,
- $this->userPluginManager,
- $this->logger,
- $this->deletedUsersIndex,
- );
-
- if (is_null($this->refBackend)) {
- $this->refBackend = $this->backends[$configPrefix];
- }
- }
-
- $this->isSetUp = true;
+ protected function newInstance(string $configPrefix): User_LDAP {
+ return new User_LDAP(
+ $this->getAccess($configPrefix),
+ $this->notificationManager,
+ $this->userPluginManager,
+ $this->logger,
+ $this->deletedUsersIndex,
+ );
}
/**