Application.php 5.5 KB

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