Security.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Julius Härtl <jus@bitgrid.net>
  8. * @author Robin Appelman <robin@icewind.nl>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  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\Settings\Settings\Admin;
  28. use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
  29. use OCP\AppFramework\Http\TemplateResponse;
  30. use OCP\AppFramework\Services\IInitialState;
  31. use OCP\Encryption\IManager;
  32. use OCP\IUserManager;
  33. use OCP\Settings\ISettings;
  34. class Security implements ISettings {
  35. /** @var IManager */
  36. private $manager;
  37. /** @var IUserManager */
  38. private $userManager;
  39. /** @var MandatoryTwoFactor */
  40. private $mandatoryTwoFactor;
  41. /** @var IInitialState */
  42. private $initialState;
  43. public function __construct(IManager $manager,
  44. IUserManager $userManager,
  45. MandatoryTwoFactor $mandatoryTwoFactor,
  46. IInitialState $initialState) {
  47. $this->manager = $manager;
  48. $this->userManager = $userManager;
  49. $this->mandatoryTwoFactor = $mandatoryTwoFactor;
  50. $this->initialState = $initialState;
  51. }
  52. /**
  53. * @return TemplateResponse
  54. */
  55. public function getForm(): TemplateResponse {
  56. $encryptionModules = $this->manager->getEncryptionModules();
  57. $defaultEncryptionModuleId = $this->manager->getDefaultEncryptionModuleId();
  58. $encryptionModuleList = [];
  59. foreach ($encryptionModules as $module) {
  60. $encryptionModuleList[$module['id']]['displayName'] = $module['displayName'];
  61. $encryptionModuleList[$module['id']]['default'] = false;
  62. if ($module['id'] === $defaultEncryptionModuleId) {
  63. $encryptionModuleList[$module['id']]['default'] = true;
  64. }
  65. }
  66. $this->initialState->provideInitialState(
  67. 'mandatory2FAState',
  68. $this->mandatoryTwoFactor->getState()
  69. );
  70. $parameters = [
  71. // Encryption API
  72. 'encryptionEnabled' => $this->manager->isEnabled(),
  73. 'encryptionReady' => $this->manager->isReady(),
  74. 'externalBackendsEnabled' => count($this->userManager->getBackends()) > 1,
  75. // Modules
  76. 'encryptionModules' => $encryptionModuleList,
  77. ];
  78. return new TemplateResponse('settings', 'settings/admin/security', $parameters, '');
  79. }
  80. /**
  81. * @return string the section ID, e.g. 'sharing'
  82. */
  83. public function getSection(): string {
  84. return 'security';
  85. }
  86. /**
  87. * @return int whether the form should be rather on the top or bottom of
  88. * the admin section. The forms are arranged in ascending order of the
  89. * priority values. It is required to return a value between 0 and 100.
  90. *
  91. * E.g.: 70
  92. */
  93. public function getPriority(): int {
  94. return 10;
  95. }
  96. }