aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2022-10-24 16:09:06 +0200
committerCôme Chilliet <come.chilliet@nextcloud.com>2022-10-25 09:52:35 +0200
commit4130a4cbd8e5bb4506ac30a19a91b088aa35dd24 (patch)
tree1649216df56b9a685eec56cd694cef4f7ccbfa50
parent6435191a6e96600db9efbad8514d6c2eff1375d1 (diff)
downloadnextcloud-server-4130a4cbd8e5bb4506ac30a19a91b088aa35dd24.tar.gz
nextcloud-server-4130a4cbd8e5bb4506ac30a19a91b088aa35dd24.zip
Make sure to use AccessFactory to create Access instances and use DI
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r--apps/user_ldap/ajax/wizard.php23
-rw-r--r--apps/user_ldap/lib/AccessFactory.php20
-rw-r--r--apps/user_ldap/lib/Command/TestConfig.php30
-rw-r--r--apps/user_ldap/lib/Group_Proxy.php9
-rw-r--r--apps/user_ldap/lib/Proxy.php46
-rw-r--r--apps/user_ldap/lib/User_Proxy.php6
6 files changed, 53 insertions, 81 deletions
diff --git a/apps/user_ldap/ajax/wizard.php b/apps/user_ldap/ajax/wizard.php
index 814477d5db0..8cae22daf19 100644
--- a/apps/user_ldap/ajax/wizard.php
+++ b/apps/user_ldap/ajax/wizard.php
@@ -38,7 +38,6 @@ if (!isset($_POST['action'])) {
}
$action = (string)$_POST['action'];
-
if (!isset($_POST['ldap_serverconfig_chooser'])) {
\OC_JSON::error(['message' => $l->t('No configuration specified')]);
}
@@ -52,26 +51,8 @@ $con->setConfiguration($configuration->getConfiguration());
$con->ldapConfigurationActive = true;
$con->setIgnoreValidation(true);
-$userManager = new \OCA\User_LDAP\User\Manager(
- \OC::$server->getConfig(),
- new \OCA\User_LDAP\FilesystemHelper(),
- \OC::$server->get(\Psr\Log\LoggerInterface::class),
- \OC::$server->getAvatarManager(),
- new \OCP\Image(),
- \OC::$server->getUserManager(),
- \OC::$server->getNotificationManager(),
- \OC::$server->get(\OCP\Share\IManager::class)
-);
-
-$access = new \OCA\User_LDAP\Access(
- $con,
- $ldapWrapper,
- $userManager,
- new \OCA\User_LDAP\Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
- \OC::$server->getConfig(),
- \OC::$server->getUserManager(),
- \OC::$server->get(\Psr\Log\LoggerInterface::class)
-);
+$factory = \OC::$server->get(\OCA\User_LDAP\AccessFactory::class);
+$access = $factory->get($con);
$wizard = new \OCA\User_LDAP\Wizard($configuration, $ldapWrapper, $access);
diff --git a/apps/user_ldap/lib/AccessFactory.php b/apps/user_ldap/lib/AccessFactory.php
index 71867bbb9a4..f0820f1444f 100644
--- a/apps/user_ldap/lib/AccessFactory.php
+++ b/apps/user_ldap/lib/AccessFactory.php
@@ -29,18 +29,12 @@ use OCP\IUserManager;
use Psr\Log\LoggerInterface;
class AccessFactory {
- /** @var ILDAPWrapper */
- protected $ldap;
- /** @var Manager */
- protected $userManager;
- /** @var Helper */
- protected $helper;
- /** @var IConfig */
- protected $config;
- /** @var IUserManager */
- private $ncUserManager;
- /** @var LoggerInterface */
- private $logger;
+ private ILDAPWrapper $ldap;
+ private Manager $userManager;
+ private Helper $helper;
+ private IConfig $config;
+ private IUserManager $ncUserManager;
+ private LoggerInterface $logger;
public function __construct(
ILDAPWrapper $ldap,
@@ -57,7 +51,7 @@ class AccessFactory {
$this->logger = $logger;
}
- public function get(Connection $connection) {
+ public function get(Connection $connection): Access {
return new Access(
$connection,
$this->ldap,
diff --git a/apps/user_ldap/lib/Command/TestConfig.php b/apps/user_ldap/lib/Command/TestConfig.php
index a1a4f14a232..c081b0cb726 100644
--- a/apps/user_ldap/lib/Command/TestConfig.php
+++ b/apps/user_ldap/lib/Command/TestConfig.php
@@ -29,6 +29,7 @@ namespace OCA\User_LDAP\Command;
use OCA\User_LDAP\AccessFactory;
use OCA\User_LDAP\Connection;
use OCA\User_LDAP\Helper;
+use OCA\User_LDAP\ILDAPWrapper;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@@ -40,29 +41,35 @@ class TestConfig extends Command {
protected const BINDFAILURE = 2;
protected const SEARCHFAILURE = 3;
- /** @var AccessFactory */
- protected $accessFactory;
+ protected AccessFactory $accessFactory;
+ protected Helper $helper;
+ protected ILDAPWrapper $ldap;
- public function __construct(AccessFactory $accessFactory) {
+ public function __construct(
+ AccessFactory $accessFactory,
+ Helper $helper,
+ ILDAPWrapper $ldap
+ ) {
$this->accessFactory = $accessFactory;
+ $this->helper = $helper;
+ $this->ldap = $ldap;
parent::__construct();
}
- protected function configure() {
+ protected function configure(): void {
$this
->setName('ldap:test-config')
->setDescription('tests an LDAP configuration')
->addArgument(
- 'configID',
- InputArgument::REQUIRED,
- 'the configuration ID'
- )
+ 'configID',
+ InputArgument::REQUIRED,
+ 'the configuration ID'
+ )
;
}
protected function execute(InputInterface $input, OutputInterface $output): int {
- $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
- $availableConfigs = $helper->getServerConfigurationPrefixes();
+ $availableConfigs = $this->helper->getServerConfigurationPrefixes();
$configID = $input->getArgument('configID');
if (!in_array($configID, $availableConfigs)) {
$output->writeln('Invalid configID');
@@ -94,8 +101,7 @@ class TestConfig extends Command {
* Tests the specified connection
*/
protected function testConfig(string $configID): int {
- $lw = new \OCA\User_LDAP\LDAP();
- $connection = new Connection($lw, $configID);
+ $connection = new Connection($this->ldap, $configID);
// Ensure validation is run before we attempt the bind
$connection->getConfiguration();
diff --git a/apps/user_ldap/lib/Group_Proxy.php b/apps/user_ldap/lib/Group_Proxy.php
index f8bdae67b72..c8c986318ec 100644
--- a/apps/user_ldap/lib/Group_Proxy.php
+++ b/apps/user_ldap/lib/Group_Proxy.php
@@ -39,8 +39,13 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
private GroupPluginManager $groupPluginManager;
private bool $isSetUp = false;
- public function __construct(Helper $helper, ILDAPWrapper $ldap, GroupPluginManager $groupPluginManager) {
- parent::__construct($ldap);
+ public function __construct(
+ Helper $helper,
+ ILDAPWrapper $ldap,
+ AccessFactory $accessFactory,
+ GroupPluginManager $groupPluginManager
+ ) {
+ parent::__construct($ldap, $accessFactory);
$this->helper = $helper;
$this->groupPluginManager = $groupPluginManager;
}
diff --git a/apps/user_ldap/lib/Proxy.php b/apps/user_ldap/lib/Proxy.php
index 4df6c2683a6..8cdb1b1da6a 100644
--- a/apps/user_ldap/lib/Proxy.php
+++ b/apps/user_ldap/lib/Proxy.php
@@ -34,57 +34,41 @@ namespace OCA\User_LDAP;
use OCA\User_LDAP\Mapping\GroupMapping;
use OCA\User_LDAP\Mapping\UserMapping;
-use OCA\User_LDAP\User\Manager;
-use OCP\IConfig;
-use OCP\IUserManager;
+use OCP\ICache;
use OCP\Server;
-use Psr\Log\LoggerInterface;
abstract class Proxy {
- private static $accesses = [];
- private $ldap = null;
- /** @var bool */
- private $isSingleBackend;
-
- /** @var \OCP\ICache|null */
- private $cache;
-
- /**
- * @param ILDAPWrapper $ldap
- */
- public function __construct(ILDAPWrapper $ldap) {
+ /** @var array<string,Access> */
+ private static array $accesses = [];
+ private ILDAPWrapper $ldap;
+ private ?bool $isSingleBackend = null;
+ private ?ICache $cache = null;
+ private AccessFactory $accessFactory;
+
+ public function __construct(
+ ILDAPWrapper $ldap,
+ AccessFactory $accessFactory
+ ) {
$this->ldap = $ldap;
+ $this->accessFactory = $accessFactory;
$memcache = \OC::$server->getMemCacheFactory();
if ($memcache->isAvailable()) {
$this->cache = $memcache->createDistributed();
}
}
- /**
- * @param string $configPrefix
- */
private function addAccess(string $configPrefix): void {
- $ocConfig = Server::get(IConfig::class);
$userMap = Server::get(UserMapping::class);
$groupMap = Server::get(GroupMapping::class);
- $coreUserManager = Server::get(IUserManager::class);
- $logger = Server::get(LoggerInterface::class);
- $helper = Server::get(Helper::class);
-
- $userManager = Server::get(Manager::class);
$connector = new Connection($this->ldap, $configPrefix);
- $access = new Access($connector, $this->ldap, $userManager, $helper, $ocConfig, $coreUserManager, $logger);
+ $access = $this->accessFactory->get($connector);
$access->setUserMapper($userMap);
$access->setGroupMapper($groupMap);
self::$accesses[$configPrefix] = $access;
}
- /**
- * @param string $configPrefix
- * @return mixed
- */
- protected function getAccess($configPrefix) {
+ protected function getAccess(string $configPrefix): Access {
if (!isset(self::$accesses[$configPrefix])) {
$this->addAccess($configPrefix);
}
diff --git a/apps/user_ldap/lib/User_Proxy.php b/apps/user_ldap/lib/User_Proxy.php
index 93420bbb470..3e2d196e800 100644
--- a/apps/user_ldap/lib/User_Proxy.php
+++ b/apps/user_ldap/lib/User_Proxy.php
@@ -38,8 +38,9 @@ use OCP\Notification\IManager as INotificationManager;
use OCP\User\Backend\ICountUsersBackend;
class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, IUserLDAP, ICountUsersBackend {
+ /** @var array<string,User_LDAP> */
private $backends = [];
- /** @var User_LDAP */
+ /** @var ?User_LDAP */
private $refBackend = null;
private bool $isSetUp = false;
@@ -52,12 +53,13 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
public function __construct(
Helper $helper,
ILDAPWrapper $ldap,
+ AccessFactory $accessFactory,
IConfig $ocConfig,
INotificationManager $notificationManager,
IUserSession $userSession,
UserPluginManager $userPluginManager
) {
- parent::__construct($ldap);
+ parent::__construct($ldap, $accessFactory);
$this->helper = $helper;
$this->ocConfig = $ocConfig;
$this->notificationManager = $notificationManager;