2017-03-31 10:16:22 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2017 Roger Szabo <roger.szabo@web.de>
|
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2020-04-29 12:57:22 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2017-03-31 10:16:22 +03:00
|
|
|
* @author Roger Szabo <roger.szabo@web.de>
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-03-31 10:16:22 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\User_LDAP\AppInfo;
|
|
|
|
|
2020-07-16 18:08:03 +03:00
|
|
|
use Closure;
|
2019-02-13 02:14:56 +03:00
|
|
|
use OCA\Files_External\Service\BackendService;
|
2017-03-31 10:16:22 +03:00
|
|
|
use OCA\User_LDAP\Controller\RenewPasswordController;
|
2020-08-12 16:07:55 +03:00
|
|
|
use OCA\User_LDAP\Events\GroupBackendRegistered;
|
|
|
|
use OCA\User_LDAP\Events\UserBackendRegistered;
|
2020-07-14 05:47:54 +03:00
|
|
|
use OCA\User_LDAP\Group_Proxy;
|
|
|
|
use OCA\User_LDAP\GroupPluginManager;
|
2019-02-13 02:14:56 +03:00
|
|
|
use OCA\User_LDAP\Handler\ExtStorageConfigHandler;
|
2020-07-14 05:47:54 +03:00
|
|
|
use OCA\User_LDAP\Helper;
|
2018-12-17 02:31:27 +03:00
|
|
|
use OCA\User_LDAP\ILDAPWrapper;
|
|
|
|
use OCA\User_LDAP\LDAP;
|
2020-07-14 05:47:54 +03:00
|
|
|
use OCA\User_LDAP\Notification\Notifier;
|
|
|
|
use OCA\User_LDAP\User_Proxy;
|
|
|
|
use OCA\User_LDAP\UserPluginManager;
|
2017-03-31 10:16:22 +03:00
|
|
|
use OCP\AppFramework\App;
|
2020-07-14 05:47:54 +03:00
|
|
|
use OCP\AppFramework\Bootstrap\IBootContext;
|
|
|
|
use OCP\AppFramework\Bootstrap\IBootstrap;
|
|
|
|
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
2020-07-21 15:36:40 +03:00
|
|
|
use OCP\AppFramework\IAppContainer;
|
2020-08-12 16:07:55 +03:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2020-07-16 18:08:03 +03:00
|
|
|
use OCP\IGroupManager;
|
2018-01-26 01:16:13 +03:00
|
|
|
use OCP\IL10N;
|
2020-07-16 11:37:45 +03:00
|
|
|
use OCP\IServerContainer;
|
2020-07-16 18:08:03 +03:00
|
|
|
use OCP\Notification\IManager as INotificationManager;
|
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
2017-03-31 10:16:22 +03:00
|
|
|
|
2020-07-14 05:47:54 +03:00
|
|
|
class Application extends App implements IBootstrap {
|
2020-04-09 14:53:40 +03:00
|
|
|
public function __construct() {
|
2017-03-31 10:16:22 +03:00
|
|
|
parent::__construct('user_ldap');
|
|
|
|
$container = $this->getContainer();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Controller
|
|
|
|
*/
|
2020-07-21 15:36:40 +03:00
|
|
|
$container->registerService('RenewPasswordController', function (IAppContainer $appContainer) {
|
2020-07-16 11:37:45 +03:00
|
|
|
/** @var IServerContainer $server */
|
2020-07-21 15:36:40 +03:00
|
|
|
$server = $appContainer->get(IServerContainer::class);
|
2017-03-31 10:16:22 +03:00
|
|
|
|
|
|
|
return new RenewPasswordController(
|
2020-07-21 15:36:40 +03:00
|
|
|
$appContainer->get('AppName'),
|
2017-03-31 10:16:22 +03:00
|
|
|
$server->getRequest(),
|
2020-07-21 15:36:40 +03:00
|
|
|
$appContainer->get('UserManager'),
|
2017-03-31 10:16:22 +03:00
|
|
|
$server->getConfig(),
|
2020-07-21 15:36:40 +03:00
|
|
|
$appContainer->get(IL10N::class),
|
|
|
|
$appContainer->get('Session'),
|
2017-03-31 10:16:22 +03:00
|
|
|
$server->getURLGenerator()
|
|
|
|
);
|
|
|
|
});
|
2018-12-17 02:31:27 +03:00
|
|
|
|
|
|
|
$container->registerService(ILDAPWrapper::class, function () {
|
|
|
|
return new LDAP();
|
|
|
|
});
|
2017-03-31 10:16:22 +03:00
|
|
|
}
|
2019-02-13 02:14:56 +03:00
|
|
|
|
2020-07-14 05:47:54 +03:00
|
|
|
public function register(IRegistrationContext $context): void {
|
2021-04-16 13:39:08 +03:00
|
|
|
$context->registerNotifierService(Notifier::class);
|
2020-07-14 05:47:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function boot(IBootContext $context): void {
|
2020-10-22 12:25:33 +03:00
|
|
|
$context->injectFn(function (
|
|
|
|
INotificationManager $notificationManager,
|
|
|
|
IAppContainer $appContainer,
|
|
|
|
EventDispatcherInterface $legacyDispatcher,
|
|
|
|
IEventDispatcher $dispatcher,
|
|
|
|
IGroupManager $groupManager,
|
|
|
|
User_Proxy $userBackend,
|
|
|
|
Group_Proxy $groupBackend,
|
|
|
|
Helper $helper
|
|
|
|
) {
|
2020-07-16 18:08:03 +03:00
|
|
|
$configPrefixes = $helper->getServerConfigurationPrefixes(true);
|
|
|
|
if (count($configPrefixes) > 0) {
|
2020-07-21 15:36:40 +03:00
|
|
|
$userPluginManager = $appContainer->get(UserPluginManager::class);
|
|
|
|
$groupPluginManager = $appContainer->get(GroupPluginManager::class);
|
2020-07-16 18:08:03 +03:00
|
|
|
|
2020-08-12 16:07:55 +03:00
|
|
|
\OC_User::useBackend($userBackend);
|
2020-09-11 01:09:00 +03:00
|
|
|
$groupManager->addBackend($groupBackend);
|
|
|
|
|
2020-08-12 16:07:55 +03:00
|
|
|
$userBackendRegisteredEvent = new UserBackendRegistered($userBackend, $userPluginManager);
|
|
|
|
$legacyDispatcher->dispatch('OCA\\User_LDAP\\User\\User::postLDAPBackendAdded', $userBackendRegisteredEvent);
|
2020-09-11 01:09:00 +03:00
|
|
|
$dispatcher->dispatchTyped($userBackendRegisteredEvent);
|
2020-08-12 16:07:55 +03:00
|
|
|
$groupBackendRegisteredEvent = new GroupBackendRegistered($groupBackend, $groupPluginManager);
|
|
|
|
$dispatcher->dispatchTyped($groupBackendRegisteredEvent);
|
2020-07-16 18:08:03 +03:00
|
|
|
}
|
|
|
|
});
|
2020-07-14 05:47:54 +03:00
|
|
|
|
2020-07-16 18:08:03 +03:00
|
|
|
$context->injectFn(Closure::fromCallable([$this, 'registerBackendDependents']));
|
2020-07-14 05:47:54 +03:00
|
|
|
|
|
|
|
\OCP\Util::connectHook(
|
|
|
|
'\OCA\Files_Sharing\API\Server2Server',
|
|
|
|
'preLoginNameUsedAsUserName',
|
|
|
|
'\OCA\User_LDAP\Helper',
|
|
|
|
'loginName2UserName'
|
|
|
|
);
|
|
|
|
}
|
2019-02-13 02:14:56 +03:00
|
|
|
|
2020-07-21 15:36:40 +03:00
|
|
|
private function registerBackendDependents(IAppContainer $appContainer, EventDispatcherInterface $dispatcher) {
|
2020-07-16 18:08:03 +03:00
|
|
|
$dispatcher->addListener(
|
2019-02-13 02:14:56 +03:00
|
|
|
'OCA\\Files_External::loadAdditionalBackends',
|
2020-07-14 05:47:54 +03:00
|
|
|
function () use ($appContainer) {
|
2020-07-16 11:37:45 +03:00
|
|
|
$storagesBackendService = $appContainer->get(BackendService::class);
|
2020-07-14 05:47:54 +03:00
|
|
|
$storagesBackendService->registerConfigHandler('home', function () use ($appContainer) {
|
2020-07-16 11:37:45 +03:00
|
|
|
return $appContainer->get(ExtStorageConfigHandler::class);
|
2019-02-13 02:14:56 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2017-03-31 10:16:22 +03:00
|
|
|
}
|