Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 4 additions & 29 deletions apps/user_ldap/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand All @@ -8,7 +10,6 @@

use Closure;
use OCA\Files_External\Service\BackendService;
use OCA\User_LDAP\Controller\RenewPasswordController;
use OCA\User_LDAP\Events\GroupBackendRegistered;
use OCA\User_LDAP\Events\UserBackendRegistered;
use OCA\User_LDAP\Group_Proxy;
Expand All @@ -30,16 +31,12 @@
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\IAppContainer;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Services\IInitialState;
use OCP\Config\IUserConfig;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\Image;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\Notification\IManager as INotificationManager;
use OCP\Share\IManager as IShareManager;
Expand All @@ -53,33 +50,11 @@ class Application extends App implements IBootstrap {

public function __construct() {
parent::__construct(self::APP_ID);
$container = $this->getContainer();

/**
* Controller
*/
$container->registerService('RenewPasswordController', function (ContainerInterface $appContainer) {
return new RenewPasswordController(
$appContainer->get('AppName'),
$appContainer->get(IRequest::class),
$appContainer->get(IUserManager::class),
$appContainer->get(IConfig::class),
$appContainer->get(IUserConfig::class),
$appContainer->get(IL10N::class),
$appContainer->get('Session'),
$appContainer->get(IURLGenerator::class),
$appContainer->get(IInitialState::class),
);
});

$container->registerService(ILDAPWrapper::class, function (ContainerInterface $appContainer) {
return new LDAP(
$appContainer->get(IConfig::class)->getSystemValueString('ldap_log_file')
);
});
}

public function register(IRegistrationContext $context): void {
$context->registerServiceAlias(ILDAPWrapper::class, LDAP::class);

$context->registerNotifierService(Notifier::class);

$context->registerService(
Expand Down
7 changes: 0 additions & 7 deletions apps/user_ldap/lib/Command/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
namespace OCA\User_LDAP\Command;

use OCA\User_LDAP\Group_Proxy;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\User_Proxy;
use OCP\IConfig;
use OCP\Server;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -82,10 +79,6 @@ protected function validateOffsetAndLimit(int $offset, int $limit): void {
}

protected function execute(InputInterface $input, OutputInterface $output): int {
$helper = Server::get(Helper::class);
$configPrefixes = $helper->getServerConfigurationPrefixes(true);
$ldapWrapper = new LDAP();

$offset = (int)$input->getOption('offset');
$limit = (int)$input->getOption('limit');
$this->validateOffsetAndLimit($offset, $limit);
Expand Down
15 changes: 9 additions & 6 deletions apps/user_ldap/lib/Command/SetConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@
use OCA\User_LDAP\Configuration;
use OCA\User_LDAP\ConnectionFactory;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\LDAP;
use OCP\Server;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class SetConfig extends Command {
public function __construct(
private readonly Helper $helper,
private readonly ConnectionFactory $connectionFactory,
) {
parent::__construct();
}

protected function configure(): void {
$this
->setName('ldap:set-config')
Expand All @@ -41,8 +46,7 @@ protected function configure(): void {
}

protected function execute(InputInterface $input, OutputInterface $output): int {
$helper = Server::get(Helper::class);
$availableConfigs = $helper->getServerConfigurationPrefixes();
$availableConfigs = $this->helper->getServerConfigurationPrefixes();
$configID = $input->getArgument('configID');
if (!in_array($configID, $availableConfigs)) {
$output->writeln('Invalid configID');
Expand All @@ -65,7 +69,6 @@ protected function setValue(string $configID, string $key, string $value): void
$configHolder->$key = $value;
$configHolder->saveConfiguration();

$connectionFactory = new ConnectionFactory(new LDAP());
$connectionFactory->get($configID)->clearCache();
$this->connectionFactory->get($configID)->clearCache();
}
}
10 changes: 0 additions & 10 deletions apps/user_ldap/lib/Jobs/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class Sync extends TimedJob {
public const MAX_INTERVAL = 12 * 60 * 60; // 12h
public const MIN_INTERVAL = 30 * 60; // 30min

protected LDAP $ldap;

public function __construct(
ITimeFactory $timeFactory,
private IConfig $config,
Expand All @@ -42,7 +40,6 @@ public function __construct(
self::MIN_INTERVAL
)
);
$this->ldap = new LDAP($this->config->getSystemValueString('ldap_log_file'));
}

/**
Expand Down Expand Up @@ -253,11 +250,4 @@ protected function getNextPrefix(?string $lastPrefix): ?string {
}
return $prefixes[$i];
}

/**
* Only used in tests
*/
public function overwritePropertiesForTest(LDAP $ldapWrapper): void {
$this->ldap = $ldapWrapper;
}
}
14 changes: 6 additions & 8 deletions apps/user_ldap/lib/LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,21 @@

class LDAP implements ILDAPWrapper {
protected array $curArgs = [];
protected LoggerInterface $logger;
protected IConfig $config;

private ?LdapDataCollector $dataCollector = null;

protected string $logFile = '';

public function __construct(
protected string $logFile = '',
IProfiler $profiler,
protected IConfig $config,
protected LoggerInterface $logger,
) {
/** @var IProfiler $profiler */
$profiler = Server::get(IProfiler::class);
if ($profiler->isEnabled()) {
$this->dataCollector = new LdapDataCollector();
$profiler->add($this->dataCollector);
}

$this->logger = Server::get(LoggerInterface::class);
$this->config = Server::get(IConfig::class);
$this->logFile = $this->config->getSystemValueString('ldap_log_file');
}

/**
Expand Down
24 changes: 12 additions & 12 deletions apps/user_ldap/lib/LDAPProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,46 @@
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\User_LDAP;

use OCA\User_LDAP\User\DeletedUsersIndex;
use OCP\IServerContainer;
use OCP\GroupInterface;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\LDAP\IDeletionFlagSupport;
use OCP\LDAP\ILDAPProvider;
use OCP\UserInterface;
use Psr\Log\LoggerInterface;

/**
* LDAP provider for public access to the LDAP backend.
*/
class LDAPProvider implements ILDAPProvider, IDeletionFlagSupport {
private $userBackend;
private $groupBackend;
private $logger;
private IUserLDAP&UserInterface $userBackend;
private IGroupLDAP&GroupInterface $groupBackend;

/**
* Create new LDAPProvider
* @param IServerContainer $serverContainer
* @param Helper $helper
* @param DeletedUsersIndex $deletedUsersIndex
* @throws \Exception if user_ldap app was not enabled
*/
public function __construct(
IServerContainer $serverContainer,
IUserManager $userManager,
IGroupManager $groupManager,
private Helper $helper,
private DeletedUsersIndex $deletedUsersIndex,
private LoggerInterface $logger,
) {
$this->logger = $serverContainer->get(LoggerInterface::class);
$userBackendFound = false;
$groupBackendFound = false;
foreach ($serverContainer->getUserManager()->getBackends() as $backend) {
foreach ($userManager->getBackends() as $backend) {
$this->logger->debug('instance ' . get_class($backend) . ' user backend.', ['app' => 'user_ldap']);
if ($backend instanceof IUserLDAP) {
$this->userBackend = $backend;
$userBackendFound = true;
break;
}
}
foreach ($serverContainer->getGroupManager()->getBackends() as $backend) {
foreach ($groupManager->getBackends() as $backend) {
$this->logger->debug('instance ' . get_class($backend) . ' group backend.', ['app' => 'user_ldap']);
if ($backend instanceof IGroupLDAP) {
$this->groupBackend = $backend;
Expand Down
8 changes: 5 additions & 3 deletions apps/user_ldap/lib/LDAPProviderFactory.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\User_LDAP;

use OCP\IServerContainer;
use OCP\LDAP\ILDAPProvider;
use OCP\LDAP\ILDAPProviderFactory;
use Psr\Container\ContainerInterface;

class LDAPProviderFactory implements ILDAPProviderFactory {
public function __construct(
/** * @var IServerContainer */
private IServerContainer $serverContainer,
private ContainerInterface $serverContainer,
) {
}

Expand Down
7 changes: 6 additions & 1 deletion apps/user_ldap/tests/AccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCP\Image;
use OCP\IUserManager;
use OCP\Notification\IManager as INotificationManager;
use OCP\Profiler\IProfiler;
use OCP\Server;
use OCP\Share\IManager;
use PHPUnit\Framework\MockObject\MockObject;
Expand Down Expand Up @@ -242,7 +243,11 @@ public function testStringResemblesDN(string $input, array|bool $interResult, bo
#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dnInputDataProvider')]
public function testStringResemblesDNLDAPmod(string $input, array|bool $interResult, bool $expectedResult): void {
[, $con, $um, $helper] = $this->getConnectorAndLdapMock();
$lw = new LDAP();
$lw = new LDAP(
$this->createMock(IProfiler::class),
$this->createMock(IConfig::class),
$this->createMock(LoggerInterface::class),
);
$access = new Access($lw, $con, $um, $helper, $this->ncUserManager, $this->logger, $this->appConfig, $this->dispatcher);

if (!function_exists('ldap_explode_dn')) {
Expand Down
2 changes: 0 additions & 2 deletions apps/user_ldap/tests/Jobs/SyncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ protected function setUp(): void {
$this->connectionFactory,
$this->accessFactory,
);

$this->sync->overwritePropertiesForTest($this->ldapWrapper);
}

public static function intervalDataProvider(): array {
Expand Down
Loading
Loading