1
0

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