Application.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Robin Appelman <robin@icewind.nl>
  9. * @author Robin McCorkell <robin@mccorkell.me.uk>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. * @author Ross Nicoll <jrn@jrn.me.uk>
  12. * @author Vincent Petry <pvince81@owncloud.com>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. namespace OCA\Files_External\AppInfo;
  30. use \OCP\AppFramework\App;
  31. use OCP\AppFramework\IAppContainer;
  32. use \OCP\IContainer;
  33. use \OCA\Files_External\Service\BackendService;
  34. use \OCA\Files_External\Lib\Config\IBackendProvider;
  35. use \OCA\Files_External\Lib\Config\IAuthMechanismProvider;
  36. /**
  37. * @package OCA\Files_External\AppInfo
  38. */
  39. class Application extends App implements IBackendProvider, IAuthMechanismProvider {
  40. public function __construct(array $urlParams = array()) {
  41. parent::__construct('files_external', $urlParams);
  42. $container = $this->getContainer();
  43. $container->registerService('OCP\Files\Config\IUserMountCache', function (IAppContainer $c) {
  44. return $c->getServer()->query('UserMountCache');
  45. });
  46. $backendService = $container->query('OCA\\Files_External\\Service\\BackendService');
  47. $backendService->registerBackendProvider($this);
  48. $backendService->registerAuthMechanismProvider($this);
  49. // force-load auth mechanisms since some will register hooks
  50. // TODO: obsolete these and use the TokenProvider to get the user's password from the session
  51. $this->getAuthMechanisms();
  52. // app developers: do NOT depend on this! it will disappear with oC 9.0!
  53. \OC::$server->getEventDispatcher()->dispatch(
  54. 'OCA\\Files_External::loadAdditionalBackends'
  55. );
  56. }
  57. /**
  58. * Register settings templates
  59. */
  60. public function registerSettings() {
  61. $container = $this->getContainer();
  62. $userSession = $container->getServer()->getUserSession();
  63. if (!$userSession->isLoggedIn()) {
  64. return;
  65. }
  66. $backendService = $container->query('OCA\\Files_External\\Service\\BackendService');
  67. /** @var \OCA\Files_External\Service\UserGlobalStoragesService $userGlobalStoragesService */
  68. $userGlobalStoragesService = $container->query('OCA\Files_External\Service\UserGlobalStoragesService');
  69. if (count($userGlobalStoragesService->getStorages()) > 0 || $backendService->isUserMountingAllowed()) {
  70. \OCP\App::registerPersonal('files_external', 'personal');
  71. }
  72. }
  73. /**
  74. * @{inheritdoc}
  75. */
  76. public function getBackends() {
  77. $container = $this->getContainer();
  78. $backends = [
  79. $container->query('OCA\Files_External\Lib\Backend\Local'),
  80. $container->query('OCA\Files_External\Lib\Backend\FTP'),
  81. $container->query('OCA\Files_External\Lib\Backend\DAV'),
  82. $container->query('OCA\Files_External\Lib\Backend\OwnCloud'),
  83. $container->query('OCA\Files_External\Lib\Backend\SFTP'),
  84. $container->query('OCA\Files_External\Lib\Backend\AmazonS3'),
  85. $container->query('OCA\Files_External\Lib\Backend\Dropbox'),
  86. $container->query('OCA\Files_External\Lib\Backend\Google'),
  87. $container->query('OCA\Files_External\Lib\Backend\Swift'),
  88. $container->query('OCA\Files_External\Lib\Backend\SFTP_Key'),
  89. $container->query('OCA\Files_External\Lib\Backend\SMB'),
  90. $container->query('OCA\Files_External\Lib\Backend\SMB_OC'),
  91. ];
  92. return $backends;
  93. }
  94. /**
  95. * @{inheritdoc}
  96. */
  97. public function getAuthMechanisms() {
  98. $container = $this->getContainer();
  99. return [
  100. // AuthMechanism::SCHEME_NULL mechanism
  101. $container->query('OCA\Files_External\Lib\Auth\NullMechanism'),
  102. // AuthMechanism::SCHEME_BUILTIN mechanism
  103. $container->query('OCA\Files_External\Lib\Auth\Builtin'),
  104. // AuthMechanism::SCHEME_PASSWORD mechanisms
  105. $container->query('OCA\Files_External\Lib\Auth\Password\Password'),
  106. $container->query('OCA\Files_External\Lib\Auth\Password\SessionCredentials'),
  107. $container->query('OCA\Files_External\Lib\Auth\Password\LoginCredentials'),
  108. $container->query('OCA\Files_External\Lib\Auth\Password\UserProvided'),
  109. $container->query('OCA\Files_External\Lib\Auth\Password\GlobalAuth'),
  110. // AuthMechanism::SCHEME_OAUTH1 mechanisms
  111. $container->query('OCA\Files_External\Lib\Auth\OAuth1\OAuth1'),
  112. // AuthMechanism::SCHEME_OAUTH2 mechanisms
  113. $container->query('OCA\Files_External\Lib\Auth\OAuth2\OAuth2'),
  114. // AuthMechanism::SCHEME_PUBLICKEY mechanisms
  115. $container->query('OCA\Files_External\Lib\Auth\PublicKey\RSA'),
  116. // AuthMechanism::SCHEME_OPENSTACK mechanisms
  117. $container->query('OCA\Files_External\Lib\Auth\OpenStack\OpenStack'),
  118. $container->query('OCA\Files_External\Lib\Auth\OpenStack\Rackspace'),
  119. // Specialized mechanisms
  120. $container->query('OCA\Files_External\Lib\Auth\AmazonS3\AccessKey'),
  121. ];
  122. }
  123. }