Application.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Robin Appelman <robin@icewind.nl>
  10. * @author Robin McCorkell <robin@mccorkell.me.uk>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. * @author Ross Nicoll <jrn@jrn.me.uk>
  13. * @author Vincent Petry <vincent@nextcloud.com>
  14. *
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. namespace OCA\Files_External\AppInfo;
  31. use OCA\Files\Event\LoadAdditionalScriptsEvent;
  32. use OCA\Files_External\Config\ConfigAdapter;
  33. use OCA\Files_External\Config\UserPlaceholderHandler;
  34. use OCA\Files_External\Lib\Auth\AmazonS3\AccessKey;
  35. use OCA\Files_External\Lib\Auth\Builtin;
  36. use OCA\Files_External\Lib\Auth\NullMechanism;
  37. use OCA\Files_External\Lib\Auth\OAuth1\OAuth1;
  38. use OCA\Files_External\Lib\Auth\OAuth2\OAuth2;
  39. use OCA\Files_External\Lib\Auth\OpenStack\OpenStackV2;
  40. use OCA\Files_External\Lib\Auth\OpenStack\OpenStackV3;
  41. use OCA\Files_External\Lib\Auth\OpenStack\Rackspace;
  42. use OCA\Files_External\Lib\Auth\Password\GlobalAuth;
  43. use OCA\Files_External\Lib\Auth\Password\LoginCredentials;
  44. use OCA\Files_External\Lib\Auth\Password\Password;
  45. use OCA\Files_External\Lib\Auth\Password\SessionCredentials;
  46. use OCA\Files_External\Lib\Auth\Password\UserGlobalAuth;
  47. use OCA\Files_External\Lib\Auth\Password\UserProvided;
  48. use OCA\Files_External\Lib\Auth\PublicKey\RSA;
  49. use OCA\Files_External\Lib\Auth\PublicKey\RSAPrivateKey;
  50. use OCA\Files_External\Lib\Auth\SMB\KerberosApacheAuth;
  51. use OCA\Files_External\Lib\Auth\SMB\KerberosAuth;
  52. use OCA\Files_External\Lib\Backend\AmazonS3;
  53. use OCA\Files_External\Lib\Backend\DAV;
  54. use OCA\Files_External\Lib\Backend\FTP;
  55. use OCA\Files_External\Lib\Backend\Local;
  56. use OCA\Files_External\Lib\Backend\OwnCloud;
  57. use OCA\Files_External\Lib\Backend\SFTP;
  58. use OCA\Files_External\Lib\Backend\SFTP_Key;
  59. use OCA\Files_External\Lib\Backend\SMB;
  60. use OCA\Files_External\Lib\Backend\SMB_OC;
  61. use OCA\Files_External\Lib\Backend\Swift;
  62. use OCA\Files_External\Lib\Config\IAuthMechanismProvider;
  63. use OCA\Files_External\Lib\Config\IBackendProvider;
  64. use OCA\Files_External\Listener\GroupDeletedListener;
  65. use OCA\Files_External\Listener\LoadAdditionalListener;
  66. use OCA\Files_External\Listener\UserDeletedListener;
  67. use OCA\Files_External\Service\BackendService;
  68. use OCP\AppFramework\App;
  69. use OCP\AppFramework\Bootstrap\IBootContext;
  70. use OCP\AppFramework\Bootstrap\IBootstrap;
  71. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  72. use OCP\Files\Config\IMountProviderCollection;
  73. use OCP\Group\Events\GroupDeletedEvent;
  74. use OCP\User\Events\UserDeletedEvent;
  75. require_once __DIR__ . '/../../3rdparty/autoload.php';
  76. /**
  77. * @package OCA\Files_External\AppInfo
  78. */
  79. class Application extends App implements IBackendProvider, IAuthMechanismProvider, IBootstrap {
  80. public const APP_ID = 'files_external';
  81. /**
  82. * Application constructor.
  83. *
  84. * @throws \OCP\AppFramework\QueryException
  85. */
  86. public function __construct(array $urlParams = []) {
  87. parent::__construct(self::APP_ID, $urlParams);
  88. }
  89. public function register(IRegistrationContext $context): void {
  90. $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
  91. $context->registerEventListener(GroupDeletedEvent::class, GroupDeletedListener::class);
  92. $context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class);
  93. }
  94. public function boot(IBootContext $context): void {
  95. $context->injectFn(function (IMountProviderCollection $mountProviderCollection, ConfigAdapter $configAdapter) {
  96. $mountProviderCollection->registerProvider($configAdapter);
  97. });
  98. $context->injectFn(function (BackendService $backendService, UserPlaceholderHandler $userConfigHandler) {
  99. $backendService->registerBackendProvider($this);
  100. $backendService->registerAuthMechanismProvider($this);
  101. $backendService->registerConfigHandler('user', function () use ($userConfigHandler) {
  102. return $userConfigHandler;
  103. });
  104. });
  105. // force-load auth mechanisms since some will register hooks
  106. // TODO: obsolete these and use the TokenProvider to get the user's password from the session
  107. $this->getAuthMechanisms();
  108. }
  109. /**
  110. * @{inheritdoc}
  111. */
  112. public function getBackends() {
  113. $container = $this->getContainer();
  114. $backends = [
  115. $container->get(Local::class),
  116. $container->get(FTP::class),
  117. $container->get(DAV::class),
  118. $container->get(OwnCloud::class),
  119. $container->get(SFTP::class),
  120. $container->get(AmazonS3::class),
  121. $container->get(Swift::class),
  122. $container->get(SFTP_Key::class),
  123. $container->get(SMB::class),
  124. $container->get(SMB_OC::class),
  125. ];
  126. return $backends;
  127. }
  128. /**
  129. * @{inheritdoc}
  130. */
  131. public function getAuthMechanisms() {
  132. $container = $this->getContainer();
  133. return [
  134. // AuthMechanism::SCHEME_NULL mechanism
  135. $container->get(NullMechanism::class),
  136. // AuthMechanism::SCHEME_BUILTIN mechanism
  137. $container->get(Builtin::class),
  138. // AuthMechanism::SCHEME_PASSWORD mechanisms
  139. $container->get(Password::class),
  140. $container->get(SessionCredentials::class),
  141. $container->get(LoginCredentials::class),
  142. $container->get(UserProvided::class),
  143. $container->get(GlobalAuth::class),
  144. $container->get(UserGlobalAuth::class),
  145. // AuthMechanism::SCHEME_OAUTH1 mechanisms
  146. $container->get(OAuth1::class),
  147. // AuthMechanism::SCHEME_OAUTH2 mechanisms
  148. $container->get(OAuth2::class),
  149. // AuthMechanism::SCHEME_PUBLICKEY mechanisms
  150. $container->get(RSA::class),
  151. $container->get(RSAPrivateKey::class),
  152. // AuthMechanism::SCHEME_OPENSTACK mechanisms
  153. $container->get(OpenStackV2::class),
  154. $container->get(OpenStackV3::class),
  155. $container->get(Rackspace::class),
  156. // Specialized mechanisms
  157. $container->get(AccessKey::class),
  158. $container->get(KerberosAuth::class),
  159. $container->get(KerberosApacheAuth::class),
  160. ];
  161. }
  162. }