Application.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Encryption\AppInfo;
  8. use OCA\Encryption\Crypto\Crypt;
  9. use OCA\Encryption\Crypto\DecryptAll;
  10. use OCA\Encryption\Crypto\EncryptAll;
  11. use OCA\Encryption\Crypto\Encryption;
  12. use OCA\Encryption\HookManager;
  13. use OCA\Encryption\Hooks\UserHooks;
  14. use OCA\Encryption\KeyManager;
  15. use OCA\Encryption\Recovery;
  16. use OCA\Encryption\Session;
  17. use OCA\Encryption\Users\Setup;
  18. use OCA\Encryption\Util;
  19. use OCP\Encryption\IManager;
  20. use OCP\IConfig;
  21. use Psr\Log\LoggerInterface;
  22. class Application extends \OCP\AppFramework\App {
  23. /**
  24. * @param array $urlParams
  25. */
  26. public function __construct($urlParams = []) {
  27. parent::__construct('encryption', $urlParams);
  28. }
  29. public function setUp(IManager $encryptionManager) {
  30. if ($encryptionManager->isEnabled()) {
  31. /** @var Setup $setup */
  32. $setup = $this->getContainer()->query(Setup::class);
  33. $setup->setupSystem();
  34. }
  35. }
  36. /**
  37. * register hooks
  38. */
  39. public function registerHooks(IConfig $config) {
  40. if (!$config->getSystemValueBool('maintenance')) {
  41. $container = $this->getContainer();
  42. $server = $container->getServer();
  43. // Register our hooks and fire them.
  44. $hookManager = new HookManager();
  45. $hookManager->registerHook([
  46. new UserHooks($container->query(KeyManager::class),
  47. $server->getUserManager(),
  48. $server->get(LoggerInterface::class),
  49. $container->query(Setup::class),
  50. $server->getUserSession(),
  51. $container->query(Util::class),
  52. $container->query(Session::class),
  53. $container->query(Crypt::class),
  54. $container->query(Recovery::class))
  55. ]);
  56. $hookManager->fireHooks();
  57. } else {
  58. // Logout user if we are in maintenance to force re-login
  59. $this->getContainer()->getServer()->getUserSession()->logout();
  60. }
  61. }
  62. public function registerEncryptionModule(IManager $encryptionManager) {
  63. $container = $this->getContainer();
  64. $encryptionManager->registerEncryptionModule(
  65. Encryption::ID,
  66. Encryption::DISPLAY_NAME,
  67. function () use ($container) {
  68. return new Encryption(
  69. $container->query(Crypt::class),
  70. $container->query(KeyManager::class),
  71. $container->query(Util::class),
  72. $container->query(Session::class),
  73. $container->query(EncryptAll::class),
  74. $container->query(DecryptAll::class),
  75. $container->getServer()->get(LoggerInterface::class),
  76. $container->getServer()->getL10N($container->getAppName())
  77. );
  78. });
  79. }
  80. }