Application.php 6.7 KB

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