Skip to content

Commit 21e2be4

Browse files
authored
Merge pull request #26402 from nextcloud/ldap-factory-no-ldap-21
[21] make ILDAPProviderFactory usable when there is no ldap setup
2 parents 9010524 + 40507ca commit 21e2be4

5 files changed

Lines changed: 51 additions & 4 deletions

File tree

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,7 @@
11831183
'OC\\L10N\\LanguageIterator' => $baseDir . '/lib/private/L10N/LanguageIterator.php',
11841184
'OC\\L10N\\LanguageNotFoundException' => $baseDir . '/lib/private/L10N/LanguageNotFoundException.php',
11851185
'OC\\L10N\\LazyL10N' => $baseDir . '/lib/private/L10N/LazyL10N.php',
1186+
'OC\\LDAP\\NullLDAPProviderFactory' => $baseDir . '/lib/private/LDAP/NullLDAPProviderFactory.php',
11861187
'OC\\LargeFileHelper' => $baseDir . '/lib/private/LargeFileHelper.php',
11871188
'OC\\Lock\\AbstractLockingProvider' => $baseDir . '/lib/private/Lock/AbstractLockingProvider.php',
11881189
'OC\\Lock\\DBLockingProvider' => $baseDir . '/lib/private/Lock/DBLockingProvider.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
12121212
'OC\\L10N\\LanguageIterator' => __DIR__ . '/../../..' . '/lib/private/L10N/LanguageIterator.php',
12131213
'OC\\L10N\\LanguageNotFoundException' => __DIR__ . '/../../..' . '/lib/private/L10N/LanguageNotFoundException.php',
12141214
'OC\\L10N\\LazyL10N' => __DIR__ . '/../../..' . '/lib/private/L10N/LazyL10N.php',
1215+
'OC\\LDAP\\NullLDAPProviderFactory' => __DIR__ . '/../../..' . '/lib/private/LDAP/NullLDAPProviderFactory.php',
12151216
'OC\\LargeFileHelper' => __DIR__ . '/../../..' . '/lib/private/LargeFileHelper.php',
12161217
'OC\\Lock\\AbstractLockingProvider' => __DIR__ . '/../../..' . '/lib/private/Lock/AbstractLockingProvider.php',
12171218
'OC\\Lock\\DBLockingProvider' => __DIR__ . '/../../..' . '/lib/private/Lock/DBLockingProvider.php',
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2021 Robin Appelman <robin@icewind.nl>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
namespace OC\LDAP;
25+
26+
use OCP\IServerContainer;
27+
use OCP\LDAP\ILDAPProviderFactory;
28+
29+
class NullLDAPProviderFactory implements ILDAPProviderFactory {
30+
public function __construct(IServerContainer $serverContainer) {
31+
}
32+
33+
public function getLDAPProvider() {
34+
throw new \Exception("No LDAP provider is available");
35+
}
36+
}

lib/private/Server.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
use OC\IntegrityCheck\Helpers\AppLocator;
105105
use OC\IntegrityCheck\Helpers\EnvironmentHelper;
106106
use OC\IntegrityCheck\Helpers\FileAccessHelper;
107+
use OC\LDAP\NullLDAPProviderFactory;
107108
use OC\KnownUser\KnownUserService;
108109
use OC\Lock\DBLockingProvider;
109110
use OC\Lock\MemcacheLockingProvider;
@@ -206,6 +207,8 @@
206207
use OCP\IUserManager;
207208
use OCP\IUserSession;
208209
use OCP\L10N\IFactory;
210+
use OCP\LDAP\ILDAPProvider;
211+
use OCP\LDAP\ILDAPProviderFactory;
209212
use OCP\Lock\ILockingProvider;
210213
use OCP\Log\ILogFactory;
211214
use OCP\Mail\IMailer;
@@ -1003,14 +1006,20 @@ public function __construct($webRoot, \OC\Config $config) {
10031006
/** @deprecated 19.0.0 */
10041007
$this->registerDeprecatedAlias('Mailer', IMailer::class);
10051008

1006-
$this->registerService('LDAPProvider', function (ContainerInterface $c) {
1009+
/** @deprecated 21.0.0 */
1010+
$this->registerDeprecatedAlias('LDAPProvider', ILDAPProvider::class);
1011+
1012+
$this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) {
10071013
$config = $c->get(\OCP\IConfig::class);
10081014
$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
10091015
if (is_null($factoryClass)) {
1010-
throw new \Exception('ldapProviderFactory not set');
1016+
return new NullLDAPProviderFactory($this);
10111017
}
10121018
/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
1013-
$factory = new $factoryClass($this);
1019+
return new $factoryClass($this);
1020+
});
1021+
$this->registerService(ILDAPProvider::class, function (ContainerInterface $c) {
1022+
$factory = $c->get(ILDAPProviderFactory::class);
10141023
return $factory->getLDAPProvider();
10151024
});
10161025
$this->registerService(ILockingProvider::class, function (ContainerInterface $c) {

lib/public/LDAP/ILDAPProviderFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ interface ILDAPProviderFactory {
4444
* @since 11.0.0
4545
*/
4646
public function __construct(IServerContainer $serverContainer);
47-
47+
4848
/**
4949
* creates and returns an instance of the ILDAPProvider
5050
*

0 commit comments

Comments
 (0)