You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Application.php 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Roger Szabo <roger.szabo@web.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author Roger Szabo <roger.szabo@web.de>
  10. *
  11. * @license GNU AGPL version 3 or any later version
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License as
  15. * published by the Free Software Foundation, either version 3 of the
  16. * License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. *
  26. */
  27. namespace OCA\User_LDAP\AppInfo;
  28. use Closure;
  29. use OCA\Files_External\Service\BackendService;
  30. use OCA\User_LDAP\Controller\RenewPasswordController;
  31. use OCA\User_LDAP\Events\GroupBackendRegistered;
  32. use OCA\User_LDAP\Events\UserBackendRegistered;
  33. use OCA\User_LDAP\Group_Proxy;
  34. use OCA\User_LDAP\GroupPluginManager;
  35. use OCA\User_LDAP\Handler\ExtStorageConfigHandler;
  36. use OCA\User_LDAP\Helper;
  37. use OCA\User_LDAP\ILDAPWrapper;
  38. use OCA\User_LDAP\LDAP;
  39. use OCA\User_LDAP\Notification\Notifier;
  40. use OCA\User_LDAP\User_Proxy;
  41. use OCA\User_LDAP\UserPluginManager;
  42. use OCP\AppFramework\App;
  43. use OCP\AppFramework\Bootstrap\IBootContext;
  44. use OCP\AppFramework\Bootstrap\IBootstrap;
  45. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  46. use OCP\AppFramework\IAppContainer;
  47. use OCP\EventDispatcher\IEventDispatcher;
  48. use OCP\IGroupManager;
  49. use OCP\IL10N;
  50. use OCP\IServerContainer;
  51. use OCP\Notification\IManager as INotificationManager;
  52. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  53. class Application extends App implements IBootstrap {
  54. public function __construct() {
  55. parent::__construct('user_ldap');
  56. $container = $this->getContainer();
  57. /**
  58. * Controller
  59. */
  60. $container->registerService('RenewPasswordController', function (IAppContainer $appContainer) {
  61. /** @var IServerContainer $server */
  62. $server = $appContainer->get(IServerContainer::class);
  63. return new RenewPasswordController(
  64. $appContainer->get('AppName'),
  65. $server->getRequest(),
  66. $appContainer->get('UserManager'),
  67. $server->getConfig(),
  68. $appContainer->get(IL10N::class),
  69. $appContainer->get('Session'),
  70. $server->getURLGenerator()
  71. );
  72. });
  73. $container->registerService(ILDAPWrapper::class, function (IAppContainer $appContainer) {
  74. /** @var IServerContainer $server */
  75. $server = $appContainer->get(IServerContainer::class);
  76. return new LDAP(
  77. $server->getConfig()->getSystemValueString('ldap_log_file')
  78. );
  79. });
  80. }
  81. public function register(IRegistrationContext $context): void {
  82. $context->registerNotifierService(Notifier::class);
  83. }
  84. public function boot(IBootContext $context): void {
  85. $context->injectFn(function (
  86. INotificationManager $notificationManager,
  87. IAppContainer $appContainer,
  88. EventDispatcherInterface $legacyDispatcher,
  89. IEventDispatcher $dispatcher,
  90. IGroupManager $groupManager,
  91. User_Proxy $userBackend,
  92. Group_Proxy $groupBackend,
  93. Helper $helper
  94. ) {
  95. $configPrefixes = $helper->getServerConfigurationPrefixes(true);
  96. if (count($configPrefixes) > 0) {
  97. $userPluginManager = $appContainer->get(UserPluginManager::class);
  98. $groupPluginManager = $appContainer->get(GroupPluginManager::class);
  99. \OC_User::useBackend($userBackend);
  100. $groupManager->addBackend($groupBackend);
  101. $userBackendRegisteredEvent = new UserBackendRegistered($userBackend, $userPluginManager);
  102. $legacyDispatcher->dispatch('OCA\\User_LDAP\\User\\User::postLDAPBackendAdded', $userBackendRegisteredEvent);
  103. $dispatcher->dispatchTyped($userBackendRegisteredEvent);
  104. $groupBackendRegisteredEvent = new GroupBackendRegistered($groupBackend, $groupPluginManager);
  105. $dispatcher->dispatchTyped($groupBackendRegisteredEvent);
  106. }
  107. });
  108. $context->injectFn(Closure::fromCallable([$this, 'registerBackendDependents']));
  109. \OCP\Util::connectHook(
  110. '\OCA\Files_Sharing\API\Server2Server',
  111. 'preLoginNameUsedAsUserName',
  112. '\OCA\User_LDAP\Helper',
  113. 'loginName2UserName'
  114. );
  115. }
  116. private function registerBackendDependents(IAppContainer $appContainer, EventDispatcherInterface $dispatcher) {
  117. $dispatcher->addListener(
  118. 'OCA\\Files_External::loadAdditionalBackends',
  119. function () use ($appContainer) {
  120. $storagesBackendService = $appContainer->get(BackendService::class);
  121. $storagesBackendService->registerConfigHandler('home', function () use ($appContainer) {
  122. return $appContainer->get(ExtStorageConfigHandler::class);
  123. });
  124. }
  125. );
  126. }
  127. }