From 429db14a00b893d55f2d4e5126c2fc68dfa6cc99 Mon Sep 17 00:00:00 2001 From: Côme Chilliet Date: Mon, 24 Apr 2023 16:03:40 +0200 Subject: Fix multiple LDAP configuration support by fixing AccessFactory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It must not reuse the same OCA\User_LDAP\User\Manager instance for several Access instances. Signed-off-by: Côme Chilliet --- apps/user_ldap/lib/AccessFactory.php | 6 ++---- apps/user_ldap/lib/Jobs/Sync.php | 19 ++----------------- 2 files changed, 4 insertions(+), 21 deletions(-) (limited to 'apps/user_ldap') diff --git a/apps/user_ldap/lib/AccessFactory.php b/apps/user_ldap/lib/AccessFactory.php index f0820f1444f..72797ef1626 100644 --- a/apps/user_ldap/lib/AccessFactory.php +++ b/apps/user_ldap/lib/AccessFactory.php @@ -26,11 +26,11 @@ namespace OCA\User_LDAP; use OCA\User_LDAP\User\Manager; use OCP\IConfig; use OCP\IUserManager; +use OCP\Server; use Psr\Log\LoggerInterface; class AccessFactory { private ILDAPWrapper $ldap; - private Manager $userManager; private Helper $helper; private IConfig $config; private IUserManager $ncUserManager; @@ -38,13 +38,11 @@ class AccessFactory { public function __construct( ILDAPWrapper $ldap, - Manager $userManager, Helper $helper, IConfig $config, IUserManager $ncUserManager, LoggerInterface $logger) { $this->ldap = $ldap; - $this->userManager = $userManager; $this->helper = $helper; $this->config = $config; $this->ncUserManager = $ncUserManager; @@ -55,7 +53,7 @@ class AccessFactory { return new Access( $connection, $this->ldap, - $this->userManager, + Server::get(Manager::class), $this->helper, $this->config, $this->ncUserManager, diff --git a/apps/user_ldap/lib/Jobs/Sync.php b/apps/user_ldap/lib/Jobs/Sync.php index 1ba24af5399..f8a9b14d02f 100644 --- a/apps/user_ldap/lib/Jobs/Sync.php +++ b/apps/user_ldap/lib/Jobs/Sync.php @@ -31,7 +31,6 @@ use OCA\User_LDAP\ConnectionFactory; use OCA\User_LDAP\Helper; use OCA\User_LDAP\LDAP; use OCA\User_LDAP\Mapping\UserMapping; -use OCA\User_LDAP\User\Manager; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\TimedJob; use OCP\IAvatarManager; @@ -48,8 +47,6 @@ class Sync extends TimedJob { protected $ldapHelper; /** @var LDAP */ protected $ldap; - /** @var Manager */ - protected $userManager; /** @var UserMapping */ protected $mapper; /** @var IConfig */ @@ -69,9 +66,8 @@ class Sync extends TimedJob { /** @var AccessFactory */ protected $accessFactory; - public function __construct(Manager $userManager, ITimeFactory $time) { + public function __construct(ITimeFactory $time) { parent::__construct($time); - $this->userManager = $userManager; $this->setInterval( (int)\OC::$server->getConfig()->getAppValue( 'user_ldap', @@ -350,10 +346,6 @@ class Sync extends TimedJob { $this->notificationManager = \OC::$server->getNotificationManager(); } - if (isset($argument['userManager'])) { - $this->userManager = $argument['userManager']; - } - if (isset($argument['mapper'])) { $this->mapper = $argument['mapper']; } else { @@ -369,14 +361,7 @@ class Sync extends TimedJob { if (isset($argument['accessFactory'])) { $this->accessFactory = $argument['accessFactory']; } else { - $this->accessFactory = new AccessFactory( - $this->ldap, - $this->userManager, - $this->ldapHelper, - $this->config, - $this->ncUserManager, - $this->logger - ); + $this->accessFactory = \OCP\Server::get(AccessFactory::class); } } } -- cgit v1.2.3 From 802363f0f60eeb9fecaed45051e929458e9eb849 Mon Sep 17 00:00:00 2001 From: Côme Chilliet Date: Thu, 27 Apr 2023 09:08:57 +0200 Subject: Adapt Sync job tests to the constructor change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/user_ldap/tests/Jobs/SyncTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'apps/user_ldap') diff --git a/apps/user_ldap/tests/Jobs/SyncTest.php b/apps/user_ldap/tests/Jobs/SyncTest.php index 8d23efb4da8..3d9fc54e631 100644 --- a/apps/user_ldap/tests/Jobs/SyncTest.php +++ b/apps/user_ldap/tests/Jobs/SyncTest.php @@ -43,7 +43,6 @@ use OCP\Notification\IManager; use Test\TestCase; class SyncTest extends TestCase { - /** @var array */ protected $arguments; /** @var Helper|\PHPUnit\Framework\MockObject\MockObject */ @@ -99,7 +98,7 @@ class SyncTest extends TestCase { 'accessFactory' => $this->accessFactory, ]; - $this->sync = new Sync($this->userManager, $this->createMock(ITimeFactory::class)); + $this->sync = new Sync($this->createMock(ITimeFactory::class)); } public function intervalDataProvider() { -- cgit v1.2.3 From 967955358c2693aafb1e43795b09cf24e460929b Mon Sep 17 00:00:00 2001 From: Côme Chilliet Date: Thu, 27 Apr 2023 11:21:53 +0200 Subject: Add comment about Manager instance not being shared MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/user_ldap/lib/AccessFactory.php | 1 + 1 file changed, 1 insertion(+) (limited to 'apps/user_ldap') diff --git a/apps/user_ldap/lib/AccessFactory.php b/apps/user_ldap/lib/AccessFactory.php index 72797ef1626..693f7e8ba12 100644 --- a/apps/user_ldap/lib/AccessFactory.php +++ b/apps/user_ldap/lib/AccessFactory.php @@ -50,6 +50,7 @@ class AccessFactory { } public function get(Connection $connection): Access { + /* Each Access instance gets its own Manager instance, see OCA\User_LDAP\AppInfo\Application::register() */ return new Access( $connection, $this->ldap, -- cgit v1.2.3