Security.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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\Encryption\IManager;
  31. use OCP\IInitialStateService;
  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 IInitialStateService */
  42. private $initialState;
  43. public function __construct(IManager $manager,
  44. IUserManager $userManager,
  45. MandatoryTwoFactor $mandatoryTwoFactor,
  46. IInitialStateService $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() {
  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. 'settings',
  68. 'mandatory2FAState',
  69. $this->mandatoryTwoFactor->getState()
  70. );
  71. $parameters = [
  72. // Encryption API
  73. 'encryptionEnabled' => $this->manager->isEnabled(),
  74. 'encryptionReady' => $this->manager->isReady(),
  75. 'externalBackendsEnabled' => count($this->userManager->getBackends()) > 1,
  76. // Modules
  77. 'encryptionModules' => $encryptionModuleList,
  78. ];
  79. return new TemplateResponse('settings', 'settings/admin/security', $parameters, '');
  80. }
  81. /**
  82. * @return string the section ID, e.g. 'sharing'
  83. */
  84. public function getSection() {
  85. return 'security';
  86. }
  87. /**
  88. * @return int whether the form should be rather on the top or bottom of
  89. * the admin section. The forms are arranged in ascending order of the
  90. * priority values. It is required to return a value between 0 and 100.
  91. *
  92. * E.g.: 70
  93. */
  94. public function getPriority() {
  95. return 10;
  96. }
  97. }