1
0

Security.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Settings\Settings\Admin;
  7. use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
  8. use OCP\AppFramework\Http\TemplateResponse;
  9. use OCP\AppFramework\Services\IInitialState;
  10. use OCP\Encryption\IManager;
  11. use OCP\IURLGenerator;
  12. use OCP\IUserManager;
  13. use OCP\Settings\ISettings;
  14. class Security implements ISettings {
  15. private IManager $manager;
  16. private IUserManager $userManager;
  17. private MandatoryTwoFactor $mandatoryTwoFactor;
  18. private IInitialState $initialState;
  19. private IURLGenerator $urlGenerator;
  20. public function __construct(IManager $manager,
  21. IUserManager $userManager,
  22. MandatoryTwoFactor $mandatoryTwoFactor,
  23. IInitialState $initialState,
  24. IURLGenerator $urlGenerator) {
  25. $this->manager = $manager;
  26. $this->userManager = $userManager;
  27. $this->mandatoryTwoFactor = $mandatoryTwoFactor;
  28. $this->initialState = $initialState;
  29. $this->urlGenerator = $urlGenerator;
  30. }
  31. /**
  32. * @return TemplateResponse
  33. */
  34. public function getForm(): TemplateResponse {
  35. $encryptionModules = $this->manager->getEncryptionModules();
  36. $defaultEncryptionModuleId = $this->manager->getDefaultEncryptionModuleId();
  37. $encryptionModuleList = [];
  38. foreach ($encryptionModules as $module) {
  39. $encryptionModuleList[$module['id']]['displayName'] = $module['displayName'];
  40. $encryptionModuleList[$module['id']]['default'] = false;
  41. if ($module['id'] === $defaultEncryptionModuleId) {
  42. $encryptionModuleList[$module['id']]['default'] = true;
  43. }
  44. }
  45. $this->initialState->provideInitialState('mandatory2FAState', $this->mandatoryTwoFactor->getState());
  46. $this->initialState->provideInitialState('two-factor-admin-doc', $this->urlGenerator->linkToDocs('admin-2fa'));
  47. $this->initialState->provideInitialState('encryption-enabled', $this->manager->isEnabled());
  48. $this->initialState->provideInitialState('encryption-ready', $this->manager->isReady());
  49. $this->initialState->provideInitialState('external-backends-enabled', count($this->userManager->getBackends()) > 1);
  50. $this->initialState->provideInitialState('encryption-modules', $encryptionModuleList);
  51. $this->initialState->provideInitialState('encryption-admin-doc', $this->urlGenerator->linkToDocs('admin-encryption'));
  52. return new TemplateResponse('settings', 'settings/admin/security', [], '');
  53. }
  54. /**
  55. * @return string the section ID, e.g. 'sharing'
  56. */
  57. public function getSection(): string {
  58. return 'security';
  59. }
  60. /**
  61. * @return int whether the form should be rather on the top or bottom of
  62. * the admin section. The forms are arranged in ascending order of the
  63. * priority values. It is required to return a value between 0 and 100.
  64. *
  65. * E.g.: 70
  66. */
  67. public function getPriority(): int {
  68. return 10;
  69. }
  70. }