Application.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bjoern Schiessle <bjoern@schiessle.org>
  6. * @author Björn Schießle <bjoern@schiessle.org>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Clark Tomlinson <fallen013@gmail.com>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  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, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OCA\Encryption\AppInfo;
  28. use OCA\Encryption\Crypto\Crypt;
  29. use OCA\Encryption\Crypto\DecryptAll;
  30. use OCA\Encryption\Crypto\EncryptAll;
  31. use OCA\Encryption\Crypto\Encryption;
  32. use OCA\Encryption\HookManager;
  33. use OCA\Encryption\Hooks\UserHooks;
  34. use OCA\Encryption\KeyManager;
  35. use OCA\Encryption\Recovery;
  36. use OCA\Encryption\Session;
  37. use OCA\Encryption\Users\Setup;
  38. use OCA\Encryption\Util;
  39. use OCP\Encryption\IManager;
  40. use OCP\IConfig;
  41. use Psr\Log\LoggerInterface;
  42. class Application extends \OCP\AppFramework\App {
  43. /**
  44. * @param array $urlParams
  45. */
  46. public function __construct($urlParams = []) {
  47. parent::__construct('encryption', $urlParams);
  48. }
  49. public function setUp(IManager $encryptionManager) {
  50. if ($encryptionManager->isEnabled()) {
  51. /** @var Setup $setup */
  52. $setup = $this->getContainer()->query(Setup::class);
  53. $setup->setupSystem();
  54. }
  55. }
  56. /**
  57. * register hooks
  58. */
  59. public function registerHooks(IConfig $config) {
  60. if (!$config->getSystemValueBool('maintenance')) {
  61. $container = $this->getContainer();
  62. $server = $container->getServer();
  63. // Register our hooks and fire them.
  64. $hookManager = new HookManager();
  65. $hookManager->registerHook([
  66. new UserHooks($container->query(KeyManager::class),
  67. $server->getUserManager(),
  68. $server->get(LoggerInterface::class),
  69. $container->query(Setup::class),
  70. $server->getUserSession(),
  71. $container->query(Util::class),
  72. $container->query(Session::class),
  73. $container->query(Crypt::class),
  74. $container->query(Recovery::class))
  75. ]);
  76. $hookManager->fireHooks();
  77. } else {
  78. // Logout user if we are in maintenance to force re-login
  79. $this->getContainer()->getServer()->getUserSession()->logout();
  80. }
  81. }
  82. public function registerEncryptionModule(IManager $encryptionManager) {
  83. $container = $this->getContainer();
  84. $encryptionManager->registerEncryptionModule(
  85. Encryption::ID,
  86. Encryption::DISPLAY_NAME,
  87. function () use ($container) {
  88. return new Encryption(
  89. $container->query(Crypt::class),
  90. $container->query(KeyManager::class),
  91. $container->query(Util::class),
  92. $container->query(Session::class),
  93. $container->query(EncryptAll::class),
  94. $container->query(DecryptAll::class),
  95. $container->getServer()->get(LoggerInterface::class),
  96. $container->getServer()->getL10N($container->getAppName())
  97. );
  98. });
  99. }
  100. }