1
0

Application.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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\Files_External\AppInfo;
  8. use OCA\Files\Event\LoadAdditionalScriptsEvent;
  9. use OCA\Files_External\Config\ConfigAdapter;
  10. use OCA\Files_External\Config\UserPlaceholderHandler;
  11. use OCA\Files_External\Lib\Auth\AmazonS3\AccessKey;
  12. use OCA\Files_External\Lib\Auth\Builtin;
  13. use OCA\Files_External\Lib\Auth\NullMechanism;
  14. use OCA\Files_External\Lib\Auth\OAuth1\OAuth1;
  15. use OCA\Files_External\Lib\Auth\OAuth2\OAuth2;
  16. use OCA\Files_External\Lib\Auth\OpenStack\OpenStackV2;
  17. use OCA\Files_External\Lib\Auth\OpenStack\OpenStackV3;
  18. use OCA\Files_External\Lib\Auth\OpenStack\Rackspace;
  19. use OCA\Files_External\Lib\Auth\Password\GlobalAuth;
  20. use OCA\Files_External\Lib\Auth\Password\LoginCredentials;
  21. use OCA\Files_External\Lib\Auth\Password\Password;
  22. use OCA\Files_External\Lib\Auth\Password\SessionCredentials;
  23. use OCA\Files_External\Lib\Auth\Password\UserGlobalAuth;
  24. use OCA\Files_External\Lib\Auth\Password\UserProvided;
  25. use OCA\Files_External\Lib\Auth\PublicKey\RSA;
  26. use OCA\Files_External\Lib\Auth\PublicKey\RSAPrivateKey;
  27. use OCA\Files_External\Lib\Auth\SMB\KerberosApacheAuth;
  28. use OCA\Files_External\Lib\Auth\SMB\KerberosAuth;
  29. use OCA\Files_External\Lib\Backend\AmazonS3;
  30. use OCA\Files_External\Lib\Backend\DAV;
  31. use OCA\Files_External\Lib\Backend\FTP;
  32. use OCA\Files_External\Lib\Backend\Local;
  33. use OCA\Files_External\Lib\Backend\OwnCloud;
  34. use OCA\Files_External\Lib\Backend\SFTP;
  35. use OCA\Files_External\Lib\Backend\SFTP_Key;
  36. use OCA\Files_External\Lib\Backend\SMB;
  37. use OCA\Files_External\Lib\Backend\SMB_OC;
  38. use OCA\Files_External\Lib\Backend\Swift;
  39. use OCA\Files_External\Lib\Config\IAuthMechanismProvider;
  40. use OCA\Files_External\Lib\Config\IBackendProvider;
  41. use OCA\Files_External\Listener\GroupDeletedListener;
  42. use OCA\Files_External\Listener\LoadAdditionalListener;
  43. use OCA\Files_External\Listener\UserDeletedListener;
  44. use OCA\Files_External\Service\BackendService;
  45. use OCP\AppFramework\App;
  46. use OCP\AppFramework\Bootstrap\IBootContext;
  47. use OCP\AppFramework\Bootstrap\IBootstrap;
  48. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  49. use OCP\Files\Config\IMountProviderCollection;
  50. use OCP\Group\Events\GroupDeletedEvent;
  51. use OCP\User\Events\UserDeletedEvent;
  52. require_once __DIR__ . '/../../3rdparty/autoload.php';
  53. /**
  54. * @package OCA\Files_External\AppInfo
  55. */
  56. class Application extends App implements IBackendProvider, IAuthMechanismProvider, IBootstrap {
  57. public const APP_ID = 'files_external';
  58. /**
  59. * Application constructor.
  60. *
  61. * @throws \OCP\AppFramework\QueryException
  62. */
  63. public function __construct(array $urlParams = []) {
  64. parent::__construct(self::APP_ID, $urlParams);
  65. }
  66. public function register(IRegistrationContext $context): void {
  67. $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
  68. $context->registerEventListener(GroupDeletedEvent::class, GroupDeletedListener::class);
  69. $context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class);
  70. }
  71. public function boot(IBootContext $context): void {
  72. $context->injectFn(function (IMountProviderCollection $mountProviderCollection, ConfigAdapter $configAdapter) {
  73. $mountProviderCollection->registerProvider($configAdapter);
  74. });
  75. $context->injectFn(function (BackendService $backendService, UserPlaceholderHandler $userConfigHandler) {
  76. $backendService->registerBackendProvider($this);
  77. $backendService->registerAuthMechanismProvider($this);
  78. $backendService->registerConfigHandler('user', function () use ($userConfigHandler) {
  79. return $userConfigHandler;
  80. });
  81. });
  82. // force-load auth mechanisms since some will register hooks
  83. // TODO: obsolete these and use the TokenProvider to get the user's password from the session
  84. $this->getAuthMechanisms();
  85. }
  86. /**
  87. * @{inheritdoc}
  88. */
  89. public function getBackends() {
  90. $container = $this->getContainer();
  91. $backends = [
  92. $container->get(Local::class),
  93. $container->get(FTP::class),
  94. $container->get(DAV::class),
  95. $container->get(OwnCloud::class),
  96. $container->get(SFTP::class),
  97. $container->get(AmazonS3::class),
  98. $container->get(Swift::class),
  99. $container->get(SFTP_Key::class),
  100. $container->get(SMB::class),
  101. $container->get(SMB_OC::class),
  102. ];
  103. return $backends;
  104. }
  105. /**
  106. * @{inheritdoc}
  107. */
  108. public function getAuthMechanisms() {
  109. $container = $this->getContainer();
  110. return [
  111. // AuthMechanism::SCHEME_NULL mechanism
  112. $container->get(NullMechanism::class),
  113. // AuthMechanism::SCHEME_BUILTIN mechanism
  114. $container->get(Builtin::class),
  115. // AuthMechanism::SCHEME_PASSWORD mechanisms
  116. $container->get(Password::class),
  117. $container->get(SessionCredentials::class),
  118. $container->get(LoginCredentials::class),
  119. $container->get(UserProvided::class),
  120. $container->get(GlobalAuth::class),
  121. $container->get(UserGlobalAuth::class),
  122. // AuthMechanism::SCHEME_OAUTH1 mechanisms
  123. $container->get(OAuth1::class),
  124. // AuthMechanism::SCHEME_OAUTH2 mechanisms
  125. $container->get(OAuth2::class),
  126. // AuthMechanism::SCHEME_PUBLICKEY mechanisms
  127. $container->get(RSA::class),
  128. $container->get(RSAPrivateKey::class),
  129. // AuthMechanism::SCHEME_OPENSTACK mechanisms
  130. $container->get(OpenStackV2::class),
  131. $container->get(OpenStackV3::class),
  132. $container->get(Rackspace::class),
  133. // Specialized mechanisms
  134. $container->get(AccessKey::class),
  135. $container->get(KerberosAuth::class),
  136. $container->get(KerberosApacheAuth::class),
  137. ];
  138. }
  139. }