Skip to content

Commit b717173

Browse files
committed
make ILDAPProviderFactory usable when there is no ldap setup
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 2f074d7 commit b717173

File tree

4 files changed

+64
-4
lines changed

4 files changed

+64
-4
lines changed

apps/user_ldap/lib/LDAPProviderFactory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,8 @@ public function __construct(IServerContainer $serverContainer) {
4141
public function getLDAPProvider(): ILDAPProvider {
4242
return $this->serverContainer->get(LDAPProvider::class);
4343
}
44+
45+
public function isAvailable(): bool {
46+
return true;
47+
}
4448
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
37+
public function isAvailable(): bool {
38+
return false;
39+
}
40+
}

lib/private/Server.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
use OC\IntegrityCheck\Helpers\AppLocator;
104104
use OC\IntegrityCheck\Helpers\EnvironmentHelper;
105105
use OC\IntegrityCheck\Helpers\FileAccessHelper;
106+
use OC\LDAP\NullLDAPProviderFactory;
106107
use OC\Lock\DBLockingProvider;
107108
use OC\Lock\MemcacheLockingProvider;
108109
use OC\Lock\NoopLockingProvider;
@@ -203,6 +204,8 @@
203204
use OCP\IUserManager;
204205
use OCP\IUserSession;
205206
use OCP\L10N\IFactory;
207+
use OCP\LDAP\ILDAPProvider;
208+
use OCP\LDAP\ILDAPProviderFactory;
206209
use OCP\Lock\ILockingProvider;
207210
use OCP\Log\ILogFactory;
208211
use OCP\Mail\IMailer;
@@ -996,14 +999,20 @@ public function __construct($webRoot, \OC\Config $config) {
996999
/** @deprecated 19.0.0 */
9971000
$this->registerDeprecatedAlias('Mailer', IMailer::class);
9981001

999-
$this->registerService('LDAPProvider', function (ContainerInterface $c) {
1002+
/** @deprecated 21.0.0 */
1003+
$this->registerDeprecatedAlias('LDAPProvider', ILDAPProvider::class);
1004+
1005+
$this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) {
10001006
$config = $c->get(\OCP\IConfig::class);
10011007
$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
10021008
if (is_null($factoryClass)) {
1003-
throw new \Exception('ldapProviderFactory not set');
1009+
return new NullLDAPProviderFactory($this);
10041010
}
10051011
/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
1006-
$factory = new $factoryClass($this);
1012+
return new $factoryClass($this);
1013+
});
1014+
$this->registerService(ILDAPProvider::class, function (ContainerInterface $c) {
1015+
$factory = $c->get(ILDAPProviderFactory::class);
10071016
return $factory->getLDAPProvider();
10081017
});
10091018
$this->registerService(ILockingProvider::class, function (ContainerInterface $c) {

lib/public/LDAP/ILDAPProviderFactory.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,19 @@ 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
*
5151
* @return ILDAPProvider
5252
* @since 11.0.0
5353
*/
5454
public function getLDAPProvider();
55+
56+
/**
57+
* Check if an ldap provider is available
58+
*
59+
* @return bool
60+
*/
61+
public function isAvailable(): bool;
5562
}

0 commit comments

Comments
 (0)