Server.php 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. * @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
  5. *
  6. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  7. * @author Bart Visscher <bartv@thisnet.nl>
  8. * @author Bernhard Posselt <dev@bernhard-posselt.com>
  9. * @author Bernhard Reiter <ockham@raz.or.at>
  10. * @author Bjoern Schiessle <bjoern@schiessle.org>
  11. * @author Björn Schießle <bjoern@schiessle.org>
  12. * @author Christopher Schäpers <kondou@ts.unde.re>
  13. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  14. * @author Damjan Georgievski <gdamjan@gmail.com>
  15. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  16. * @author Georg Ehrke <oc.list@georgehrke.com>
  17. * @author Joas Schilling <coding@schilljs.com>
  18. * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  19. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  20. * @author Julius Haertl <jus@bitgrid.net>
  21. * @author Julius Härtl <jus@bitgrid.net>
  22. * @author Lukas Reschke <lukas@statuscode.ch>
  23. * @author Maxence Lange <maxence@artificial-owl.com>
  24. * @author Michael Weimann <mail@michael-weimann.eu>
  25. * @author Morris Jobke <hey@morrisjobke.de>
  26. * @author Piotr Mrówczyński <mrow4a@yahoo.com>
  27. * @author Robin Appelman <robin@icewind.nl>
  28. * @author Robin McCorkell <robin@mccorkell.me.uk>
  29. * @author Roeland Jago Douma <roeland@famdouma.nl>
  30. * @author root <root@localhost.localdomain>
  31. * @author Sander <brantje@gmail.com>
  32. * @author Thomas Müller <thomas.mueller@tmit.eu>
  33. * @author Thomas Tanghus <thomas@tanghus.net>
  34. * @author Tobia De Koninck <tobia@ledfan.be>
  35. * @author Vincent Petry <pvince81@owncloud.com>
  36. * @author Xheni Myrtaj <myrtajxheni@gmail.com>
  37. *
  38. * @license AGPL-3.0
  39. *
  40. * This code is free software: you can redistribute it and/or modify
  41. * it under the terms of the GNU Affero General Public License, version 3,
  42. * as published by the Free Software Foundation.
  43. *
  44. * This program is distributed in the hope that it will be useful,
  45. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  46. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  47. * GNU Affero General Public License for more details.
  48. *
  49. * You should have received a copy of the GNU Affero General Public License, version 3,
  50. * along with this program. If not, see <http://www.gnu.org/licenses/>
  51. *
  52. */
  53. namespace OC;
  54. use bantu\IniGetWrapper\IniGetWrapper;
  55. use OC\Accounts\AccountManager;
  56. use OC\App\AppManager;
  57. use OC\App\AppStore\Bundles\BundleFetcher;
  58. use OC\App\AppStore\Fetcher\AppFetcher;
  59. use OC\App\AppStore\Fetcher\CategoryFetcher;
  60. use OC\AppFramework\Http\Request;
  61. use OC\AppFramework\Utility\SimpleContainer;
  62. use OC\AppFramework\Utility\TimeFactory;
  63. use OC\Authentication\LoginCredentials\Store;
  64. use OC\Authentication\Token\IProvider;
  65. use OC\Avatar\AvatarManager;
  66. use OC\Collaboration\Collaborators\GroupPlugin;
  67. use OC\Collaboration\Collaborators\MailPlugin;
  68. use OC\Collaboration\Collaborators\RemoteGroupPlugin;
  69. use OC\Collaboration\Collaborators\RemotePlugin;
  70. use OC\Collaboration\Collaborators\UserPlugin;
  71. use OC\Command\CronBus;
  72. use OC\Comments\ManagerFactory as CommentsManagerFactory;
  73. use OC\Contacts\ContactsMenu\ActionFactory;
  74. use OC\Contacts\ContactsMenu\ContactsStore;
  75. use OC\Dashboard\DashboardManager;
  76. use OC\Diagnostics\EventLogger;
  77. use OC\Diagnostics\QueryLogger;
  78. use OC\Federation\CloudFederationFactory;
  79. use OC\Federation\CloudFederationProviderManager;
  80. use OC\Federation\CloudIdManager;
  81. use OC\Files\Config\UserMountCache;
  82. use OC\Files\Config\UserMountCacheListener;
  83. use OC\Files\Mount\CacheMountProvider;
  84. use OC\Files\Mount\LocalHomeMountProvider;
  85. use OC\Files\Mount\ObjectHomeMountProvider;
  86. use OC\Files\Node\HookConnector;
  87. use OC\Files\Node\LazyRoot;
  88. use OC\Files\Node\Root;
  89. use OC\Files\Storage\StorageFactory;
  90. use OC\Files\View;
  91. use OC\FullTextSearch\FullTextSearchManager;
  92. use OC\Http\Client\ClientService;
  93. use OC\IntegrityCheck\Checker;
  94. use OC\IntegrityCheck\Helpers\AppLocator;
  95. use OC\IntegrityCheck\Helpers\EnvironmentHelper;
  96. use OC\IntegrityCheck\Helpers\FileAccessHelper;
  97. use OC\Lock\DBLockingProvider;
  98. use OC\Lock\MemcacheLockingProvider;
  99. use OC\Lock\NoopLockingProvider;
  100. use OC\Lockdown\LockdownManager;
  101. use OC\Log\LogFactory;
  102. use OC\Mail\Mailer;
  103. use OC\Memcache\ArrayCache;
  104. use OC\Memcache\Factory;
  105. use OC\Notification\Manager;
  106. use OC\OCS\DiscoveryService;
  107. use OC\Preview\GeneratorHelper;
  108. use OC\Remote\Api\ApiFactory;
  109. use OC\Remote\InstanceFactory;
  110. use OC\RichObjectStrings\Validator;
  111. use OC\Security\Bruteforce\Throttler;
  112. use OC\Security\CertificateManager;
  113. use OC\Security\CredentialsManager;
  114. use OC\Security\Crypto;
  115. use OC\Security\CSP\ContentSecurityPolicyNonceManager;
  116. use OC\Security\CSRF\CsrfTokenGenerator;
  117. use OC\Security\CSRF\CsrfTokenManager;
  118. use OC\Security\CSRF\TokenStorage\SessionStorage;
  119. use OC\Security\Hasher;
  120. use OC\Security\SecureRandom;
  121. use OC\Security\TrustedDomainHelper;
  122. use OC\Session\CryptoWrapper;
  123. use OC\Share20\ProviderFactory;
  124. use OC\Share20\ShareHelper;
  125. use OC\SystemTag\ManagerFactory as SystemTagManagerFactory;
  126. use OC\Tagging\TagMapper;
  127. use OC\Template\IconsCacher;
  128. use OC\Template\JSCombiner;
  129. use OC\Template\SCSSCacher;
  130. use OCA\Theming\ImageManager;
  131. use OCA\Theming\ThemingDefaults;
  132. use OCA\Theming\Util;
  133. use OCP\Accounts\IAccountManager;
  134. use OCP\App\IAppManager;
  135. use OCP\Authentication\LoginCredentials\IStore;
  136. use OCP\Collaboration\AutoComplete\IManager;
  137. use OCP\Contacts\ContactsMenu\IActionFactory;
  138. use OCP\Contacts\ContactsMenu\IContactsStore;
  139. use OCP\Dashboard\IDashboardManager;
  140. use OCP\Defaults;
  141. use OCP\EventDispatcher\IEventDispatcher;
  142. use OCP\Federation\ICloudFederationFactory;
  143. use OCP\Federation\ICloudFederationProviderManager;
  144. use OCP\Federation\ICloudIdManager;
  145. use OCP\Files\NotFoundException;
  146. use OCP\Files\Storage\IStorageFactory;
  147. use OCP\FullTextSearch\IFullTextSearchManager;
  148. use OCP\GlobalScale\IConfig;
  149. use OCP\Group\Events\BeforeGroupCreatedEvent;
  150. use OCP\Group\Events\BeforeGroupDeletedEvent;
  151. use OCP\Group\Events\BeforeUserAddedEvent;
  152. use OCP\Group\Events\BeforeUserRemovedEvent;
  153. use OCP\Group\Events\GroupCreatedEvent;
  154. use OCP\Group\Events\GroupDeletedEvent;
  155. use OCP\Group\Events\UserAddedEvent;
  156. use OCP\Group\Events\UserRemovedEvent;
  157. use OCP\Group\ISubAdmin;
  158. use OCP\ICacheFactory;
  159. use OCP\IDBConnection;
  160. use OCP\IInitialStateService;
  161. use OCP\IL10N;
  162. use OCP\IServerContainer;
  163. use OCP\ITempManager;
  164. use OCP\IUser;
  165. use OCP\Lock\ILockingProvider;
  166. use OCP\Log\ILogFactory;
  167. use OCP\Remote\Api\IApiFactory;
  168. use OCP\Remote\IInstanceFactory;
  169. use OCP\RichObjectStrings\IValidator;
  170. use OCP\Security\IContentSecurityPolicyManager;
  171. use OCP\Share\IShareHelper;
  172. use OCP\User\Events\BeforePasswordUpdatedEvent;
  173. use OCP\User\Events\BeforeUserCreatedEvent;
  174. use OCP\User\Events\BeforeUserDeletedEvent;
  175. use OCP\User\Events\BeforeUserLoggedInEvent;
  176. use OCP\User\Events\BeforeUserLoggedInWithCookieEvent;
  177. use OCP\User\Events\BeforeUserLoggedOutEvent;
  178. use OCP\User\Events\PasswordUpdatedEvent;
  179. use OCP\User\Events\UserChangedEvent;
  180. use OCP\User\Events\UserCreatedEvent;
  181. use OCP\User\Events\UserDeletedEvent;
  182. use OCP\User\Events\UserLoggedInEvent;
  183. use OCP\User\Events\UserLoggedInWithCookieEvent;
  184. use OCP\User\Events\UserLoggedOutEvent;
  185. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  186. use Symfony\Component\EventDispatcher\GenericEvent;
  187. /**
  188. * Class Server
  189. *
  190. * @package OC
  191. *
  192. * TODO: hookup all manager classes
  193. */
  194. class Server extends ServerContainer implements IServerContainer {
  195. /** @var string */
  196. private $webRoot;
  197. /**
  198. * @param string $webRoot
  199. * @param \OC\Config $config
  200. */
  201. public function __construct($webRoot, \OC\Config $config) {
  202. parent::__construct();
  203. $this->webRoot = $webRoot;
  204. // To find out if we are running from CLI or not
  205. $this->registerParameter('isCLI', \OC::$CLI);
  206. $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) {
  207. return $c;
  208. });
  209. $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
  210. $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class);
  211. $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
  212. $this->registerAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class);
  213. $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
  214. $this->registerAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class);
  215. $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
  216. $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
  217. $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class);
  218. $this->registerAlias(IActionFactory::class, ActionFactory::class);
  219. $this->registerService(\OCP\IPreview::class, function (Server $c) {
  220. return new PreviewManager(
  221. $c->getConfig(),
  222. $c->getRootFolder(),
  223. $c->getAppDataDir('preview'),
  224. $c->getEventDispatcher(),
  225. $c->getGeneratorHelper(),
  226. $c->getSession()->get('user_id')
  227. );
  228. });
  229. $this->registerAlias('PreviewManager', \OCP\IPreview::class);
  230. $this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
  231. return new \OC\Preview\Watcher(
  232. $c->getAppDataDir('preview')
  233. );
  234. });
  235. $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) {
  236. $view = new View();
  237. $util = new Encryption\Util(
  238. $view,
  239. $c->getUserManager(),
  240. $c->getGroupManager(),
  241. $c->getConfig()
  242. );
  243. return new Encryption\Manager(
  244. $c->getConfig(),
  245. $c->getLogger(),
  246. $c->getL10N('core'),
  247. new View(),
  248. $util,
  249. new ArrayCache()
  250. );
  251. });
  252. $this->registerAlias('EncryptionManager', \OCP\Encryption\IManager::class);
  253. $this->registerService('EncryptionFileHelper', function (Server $c) {
  254. $util = new Encryption\Util(
  255. new View(),
  256. $c->getUserManager(),
  257. $c->getGroupManager(),
  258. $c->getConfig()
  259. );
  260. return new Encryption\File(
  261. $util,
  262. $c->getRootFolder(),
  263. $c->getShareManager()
  264. );
  265. });
  266. $this->registerService('EncryptionKeyStorage', function (Server $c) {
  267. $view = new View();
  268. $util = new Encryption\Util(
  269. $view,
  270. $c->getUserManager(),
  271. $c->getGroupManager(),
  272. $c->getConfig()
  273. );
  274. return new Encryption\Keys\Storage($view, $util);
  275. });
  276. $this->registerService('TagMapper', function (Server $c) {
  277. return new TagMapper($c->getDatabaseConnection());
  278. });
  279. $this->registerService(\OCP\ITagManager::class, function (Server $c) {
  280. $tagMapper = $c->query('TagMapper');
  281. return new TagManager($tagMapper, $c->getUserSession());
  282. });
  283. $this->registerAlias('TagManager', \OCP\ITagManager::class);
  284. $this->registerService('SystemTagManagerFactory', function (Server $c) {
  285. $config = $c->getConfig();
  286. $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
  287. return new $factoryClass($this);
  288. });
  289. $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
  290. return $c->query('SystemTagManagerFactory')->getManager();
  291. });
  292. $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
  293. $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
  294. return $c->query('SystemTagManagerFactory')->getObjectMapper();
  295. });
  296. $this->registerService('RootFolder', function (Server $c) {
  297. $manager = \OC\Files\Filesystem::getMountManager(null);
  298. $view = new View();
  299. $root = new Root(
  300. $manager,
  301. $view,
  302. null,
  303. $c->getUserMountCache(),
  304. $this->getLogger(),
  305. $this->getUserManager()
  306. );
  307. $connector = new HookConnector($root, $view, $c->getEventDispatcher());
  308. $connector->viewToNode();
  309. $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
  310. $previewConnector->connectWatcher();
  311. return $root;
  312. });
  313. $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
  314. $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) {
  315. return new LazyRoot(function () use ($c) {
  316. return $c->query('RootFolder');
  317. });
  318. });
  319. $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
  320. $this->registerAlias('UserManager', \OC\User\Manager::class);
  321. $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
  322. $this->registerService(\OCP\IGroupManager::class, function (Server $c) {
  323. $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger());
  324. $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
  325. \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
  326. /** @var IEventDispatcher $dispatcher */
  327. $dispatcher = $this->query(IEventDispatcher::class);
  328. $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid));
  329. });
  330. $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) {
  331. \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $group->getGID()));
  332. /** @var IEventDispatcher $dispatcher */
  333. $dispatcher = $this->query(IEventDispatcher::class);
  334. $dispatcher->dispatchTyped(new GroupCreatedEvent($group));
  335. });
  336. $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
  337. \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
  338. /** @var IEventDispatcher $dispatcher */
  339. $dispatcher = $this->query(IEventDispatcher::class);
  340. $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group));
  341. });
  342. $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
  343. \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
  344. /** @var IEventDispatcher $dispatcher */
  345. $dispatcher = $this->query(IEventDispatcher::class);
  346. $dispatcher->dispatchTyped(new GroupDeletedEvent($group));
  347. });
  348. $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  349. \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
  350. /** @var IEventDispatcher $dispatcher */
  351. $dispatcher = $this->query(IEventDispatcher::class);
  352. $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user));
  353. });
  354. $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  355. \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
  356. //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
  357. \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
  358. /** @var IEventDispatcher $dispatcher */
  359. $dispatcher = $this->query(IEventDispatcher::class);
  360. $dispatcher->dispatchTyped(new UserAddedEvent($group, $user));
  361. });
  362. $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  363. /** @var IEventDispatcher $dispatcher */
  364. $dispatcher = $this->query(IEventDispatcher::class);
  365. $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user));
  366. });
  367. $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  368. /** @var IEventDispatcher $dispatcher */
  369. $dispatcher = $this->query(IEventDispatcher::class);
  370. $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user));
  371. });
  372. return $groupManager;
  373. });
  374. $this->registerAlias('GroupManager', \OCP\IGroupManager::class);
  375. $this->registerService(Store::class, function (Server $c) {
  376. $session = $c->getSession();
  377. if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
  378. $tokenProvider = $c->query(IProvider::class);
  379. } else {
  380. $tokenProvider = null;
  381. }
  382. $logger = $c->getLogger();
  383. return new Store($session, $logger, $tokenProvider);
  384. });
  385. $this->registerAlias(IStore::class, Store::class);
  386. $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) {
  387. $dbConnection = $c->getDatabaseConnection();
  388. return new Authentication\Token\DefaultTokenMapper($dbConnection);
  389. });
  390. $this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
  391. $this->registerService(\OC\User\Session::class, function (Server $c) {
  392. $manager = $c->getUserManager();
  393. $session = new \OC\Session\Memory('');
  394. $timeFactory = new TimeFactory();
  395. // Token providers might require a working database. This code
  396. // might however be called when ownCloud is not yet setup.
  397. if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
  398. $defaultTokenProvider = $c->query(IProvider::class);
  399. } else {
  400. $defaultTokenProvider = null;
  401. }
  402. $legacyDispatcher = $c->getEventDispatcher();
  403. $userSession = new \OC\User\Session(
  404. $manager,
  405. $session,
  406. $timeFactory,
  407. $defaultTokenProvider,
  408. $c->getConfig(),
  409. $c->getSecureRandom(),
  410. $c->getLockdownManager(),
  411. $c->getLogger(),
  412. $c->query(IEventDispatcher::class)
  413. );
  414. $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
  415. \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
  416. /** @var IEventDispatcher $dispatcher */
  417. $dispatcher = $this->query(IEventDispatcher::class);
  418. $dispatcher->dispatchTyped(new BeforeUserCreatedEvent($uid, $password));
  419. });
  420. $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
  421. /** @var $user \OC\User\User */
  422. \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
  423. /** @var IEventDispatcher $dispatcher */
  424. $dispatcher = $this->query(IEventDispatcher::class);
  425. $dispatcher->dispatchTyped(new UserCreatedEvent($user, $password));
  426. });
  427. $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) {
  428. /** @var $user \OC\User\User */
  429. \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
  430. $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
  431. /** @var IEventDispatcher $dispatcher */
  432. $dispatcher = $this->query(IEventDispatcher::class);
  433. $dispatcher->dispatchTyped(new BeforeUserDeletedEvent($user));
  434. });
  435. $userSession->listen('\OC\User', 'postDelete', function ($user) {
  436. /** @var $user \OC\User\User */
  437. \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
  438. /** @var IEventDispatcher $dispatcher */
  439. $dispatcher = $this->query(IEventDispatcher::class);
  440. $dispatcher->dispatchTyped(new UserDeletedEvent($user));
  441. });
  442. $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
  443. /** @var $user \OC\User\User */
  444. \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
  445. /** @var IEventDispatcher $dispatcher */
  446. $dispatcher = $this->query(IEventDispatcher::class);
  447. $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword));
  448. });
  449. $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
  450. /** @var $user \OC\User\User */
  451. \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
  452. /** @var IEventDispatcher $dispatcher */
  453. $dispatcher = $this->query(IEventDispatcher::class);
  454. $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword));
  455. });
  456. $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
  457. \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
  458. /** @var IEventDispatcher $dispatcher */
  459. $dispatcher = $this->query(IEventDispatcher::class);
  460. $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password));
  461. });
  462. $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) {
  463. /** @var $user \OC\User\User */
  464. \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin));
  465. /** @var IEventDispatcher $dispatcher */
  466. $dispatcher = $this->query(IEventDispatcher::class);
  467. $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $password, $isTokenLogin));
  468. });
  469. $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) {
  470. /** @var IEventDispatcher $dispatcher */
  471. $dispatcher = $this->query(IEventDispatcher::class);
  472. $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid));
  473. });
  474. $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
  475. /** @var $user \OC\User\User */
  476. \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
  477. /** @var IEventDispatcher $dispatcher */
  478. $dispatcher = $this->query(IEventDispatcher::class);
  479. $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password));
  480. });
  481. $userSession->listen('\OC\User', 'logout', function ($user) {
  482. \OC_Hook::emit('OC_User', 'logout', array());
  483. /** @var IEventDispatcher $dispatcher */
  484. $dispatcher = $this->query(IEventDispatcher::class);
  485. $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user));
  486. });
  487. $userSession->listen('\OC\User', 'postLogout', function ($user) {
  488. /** @var IEventDispatcher $dispatcher */
  489. $dispatcher = $this->query(IEventDispatcher::class);
  490. $dispatcher->dispatchTyped(new UserLoggedOutEvent($user));
  491. });
  492. $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
  493. /** @var $user \OC\User\User */
  494. \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
  495. /** @var IEventDispatcher $dispatcher */
  496. $dispatcher = $this->query(IEventDispatcher::class);
  497. $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue));
  498. });
  499. return $userSession;
  500. });
  501. $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
  502. $this->registerAlias('UserSession', \OC\User\Session::class);
  503. $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
  504. $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
  505. $this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
  506. $this->registerService(\OC\AllConfig::class, function (Server $c) {
  507. return new \OC\AllConfig(
  508. $c->getSystemConfig()
  509. );
  510. });
  511. $this->registerAlias('AllConfig', \OC\AllConfig::class);
  512. $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
  513. $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) {
  514. return new \OC\SystemConfig($config);
  515. });
  516. $this->registerAlias('SystemConfig', \OC\SystemConfig::class);
  517. $this->registerService(\OC\AppConfig::class, function (Server $c) {
  518. return new \OC\AppConfig($c->getDatabaseConnection());
  519. });
  520. $this->registerAlias('AppConfig', \OC\AppConfig::class);
  521. $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
  522. $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
  523. return new \OC\L10N\Factory(
  524. $c->getConfig(),
  525. $c->getRequest(),
  526. $c->getUserSession(),
  527. \OC::$SERVERROOT
  528. );
  529. });
  530. $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
  531. $this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
  532. $config = $c->getConfig();
  533. $cacheFactory = $c->getMemCacheFactory();
  534. $request = $c->getRequest();
  535. return new \OC\URLGenerator(
  536. $config,
  537. $cacheFactory,
  538. $request
  539. );
  540. });
  541. $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
  542. $this->registerAlias('AppFetcher', AppFetcher::class);
  543. $this->registerAlias('CategoryFetcher', CategoryFetcher::class);
  544. $this->registerService(\OCP\ICache::class, function ($c) {
  545. return new Cache\File();
  546. });
  547. $this->registerAlias('UserCache', \OCP\ICache::class);
  548. $this->registerService(Factory::class, function (Server $c) {
  549. $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
  550. ArrayCache::class,
  551. ArrayCache::class,
  552. ArrayCache::class
  553. );
  554. $config = $c->getConfig();
  555. if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
  556. $v = \OC_App::getAppVersions();
  557. $v['core'] = implode(',', \OC_Util::getVersion());
  558. $version = implode(',', $v);
  559. $instanceId = \OC_Util::getInstanceId();
  560. $path = \OC::$SERVERROOT;
  561. $prefix = md5($instanceId . '-' . $version . '-' . $path);
  562. return new \OC\Memcache\Factory($prefix, $c->getLogger(),
  563. $config->getSystemValue('memcache.local', null),
  564. $config->getSystemValue('memcache.distributed', null),
  565. $config->getSystemValue('memcache.locking', null)
  566. );
  567. }
  568. return $arrayCacheFactory;
  569. });
  570. $this->registerAlias('MemCacheFactory', Factory::class);
  571. $this->registerAlias(ICacheFactory::class, Factory::class);
  572. $this->registerService('RedisFactory', function (Server $c) {
  573. $systemConfig = $c->getSystemConfig();
  574. return new RedisFactory($systemConfig);
  575. });
  576. $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
  577. return new \OC\Activity\Manager(
  578. $c->getRequest(),
  579. $c->getUserSession(),
  580. $c->getConfig(),
  581. $c->query(IValidator::class)
  582. );
  583. });
  584. $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
  585. $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
  586. return new \OC\Activity\EventMerger(
  587. $c->getL10N('lib')
  588. );
  589. });
  590. $this->registerAlias(IValidator::class, Validator::class);
  591. $this->registerService(AvatarManager::class, function(Server $c) {
  592. return new AvatarManager(
  593. $c->query(\OC\User\Manager::class),
  594. $c->getAppDataDir('avatar'),
  595. $c->getL10N('lib'),
  596. $c->getLogger(),
  597. $c->getConfig()
  598. );
  599. });
  600. $this->registerAlias(\OCP\IAvatarManager::class, AvatarManager::class);
  601. $this->registerAlias('AvatarManager', AvatarManager::class);
  602. $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
  603. $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class);
  604. $this->registerService(\OC\Log::class, function (Server $c) {
  605. $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
  606. $factory = new LogFactory($c, $this->getSystemConfig());
  607. $logger = $factory->get($logType);
  608. $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class);
  609. return new Log($logger, $this->getSystemConfig(), null, $registry);
  610. });
  611. $this->registerAlias(\OCP\ILogger::class, \OC\Log::class);
  612. $this->registerAlias('Logger', \OC\Log::class);
  613. $this->registerService(ILogFactory::class, function (Server $c) {
  614. return new LogFactory($c, $this->getSystemConfig());
  615. });
  616. $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
  617. $config = $c->getConfig();
  618. return new \OC\BackgroundJob\JobList(
  619. $c->getDatabaseConnection(),
  620. $config,
  621. new TimeFactory()
  622. );
  623. });
  624. $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
  625. $this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
  626. $cacheFactory = $c->getMemCacheFactory();
  627. $logger = $c->getLogger();
  628. if ($cacheFactory->isLocalCacheAvailable()) {
  629. $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
  630. } else {
  631. $router = new \OC\Route\Router($logger);
  632. }
  633. return $router;
  634. });
  635. $this->registerAlias('Router', \OCP\Route\IRouter::class);
  636. $this->registerService(\OCP\ISearch::class, function ($c) {
  637. return new Search();
  638. });
  639. $this->registerAlias('Search', \OCP\ISearch::class);
  640. $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
  641. return new \OC\Security\RateLimiting\Backend\MemoryCache(
  642. $this->getMemCacheFactory(),
  643. new \OC\AppFramework\Utility\TimeFactory()
  644. );
  645. });
  646. $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
  647. return new SecureRandom();
  648. });
  649. $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
  650. $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
  651. return new Crypto($c->getConfig(), $c->getSecureRandom());
  652. });
  653. $this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
  654. $this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
  655. return new Hasher($c->getConfig());
  656. });
  657. $this->registerAlias('Hasher', \OCP\Security\IHasher::class);
  658. $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
  659. return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
  660. });
  661. $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
  662. $this->registerService(IDBConnection::class, function (Server $c) {
  663. $systemConfig = $c->getSystemConfig();
  664. $factory = new \OC\DB\ConnectionFactory($systemConfig);
  665. $type = $systemConfig->getValue('dbtype', 'sqlite');
  666. if (!$factory->isValidType($type)) {
  667. throw new \OC\DatabaseException('Invalid database type');
  668. }
  669. $connectionParams = $factory->createConnectionParams();
  670. $connection = $factory->getConnection($type, $connectionParams);
  671. $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
  672. return $connection;
  673. });
  674. $this->registerAlias('DatabaseConnection', IDBConnection::class);
  675. $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
  676. $user = \OC_User::getUser();
  677. $uid = $user ? $user : null;
  678. return new ClientService(
  679. $c->getConfig(),
  680. new \OC\Security\CertificateManager(
  681. $uid,
  682. new View(),
  683. $c->getConfig(),
  684. $c->getLogger(),
  685. $c->getSecureRandom()
  686. )
  687. );
  688. });
  689. $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
  690. $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
  691. $eventLogger = new EventLogger();
  692. if ($c->getSystemConfig()->getValue('debug', false)) {
  693. // In debug mode, module is being activated by default
  694. $eventLogger->activate();
  695. }
  696. return $eventLogger;
  697. });
  698. $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
  699. $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
  700. $queryLogger = new QueryLogger();
  701. if ($c->getSystemConfig()->getValue('debug', false)) {
  702. // In debug mode, module is being activated by default
  703. $queryLogger->activate();
  704. }
  705. return $queryLogger;
  706. });
  707. $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
  708. $this->registerService(TempManager::class, function (Server $c) {
  709. return new TempManager(
  710. $c->getLogger(),
  711. $c->getConfig()
  712. );
  713. });
  714. $this->registerAlias('TempManager', TempManager::class);
  715. $this->registerAlias(ITempManager::class, TempManager::class);
  716. $this->registerService(AppManager::class, function (Server $c) {
  717. return new \OC\App\AppManager(
  718. $c->getUserSession(),
  719. $c->getConfig(),
  720. $c->query(\OC\AppConfig::class),
  721. $c->getGroupManager(),
  722. $c->getMemCacheFactory(),
  723. $c->getEventDispatcher(),
  724. $c->getLogger()
  725. );
  726. });
  727. $this->registerAlias('AppManager', AppManager::class);
  728. $this->registerAlias(IAppManager::class, AppManager::class);
  729. $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
  730. return new DateTimeZone(
  731. $c->getConfig(),
  732. $c->getSession()
  733. );
  734. });
  735. $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
  736. $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
  737. $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
  738. return new DateTimeFormatter(
  739. $c->getDateTimeZone()->getTimeZone(),
  740. $c->getL10N('lib', $language)
  741. );
  742. });
  743. $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
  744. $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
  745. $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
  746. $listener = new UserMountCacheListener($mountCache);
  747. $listener->listen($c->getUserManager());
  748. return $mountCache;
  749. });
  750. $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
  751. $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
  752. $loader = \OC\Files\Filesystem::getLoader();
  753. $mountCache = $c->query('UserMountCache');
  754. $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
  755. // builtin providers
  756. $config = $c->getConfig();
  757. $manager->registerProvider(new CacheMountProvider($config));
  758. $manager->registerHomeProvider(new LocalHomeMountProvider());
  759. $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
  760. return $manager;
  761. });
  762. $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
  763. $this->registerService('IniWrapper', function ($c) {
  764. return new IniGetWrapper();
  765. });
  766. $this->registerService('AsyncCommandBus', function (Server $c) {
  767. $busClass = $c->getConfig()->getSystemValue('commandbus');
  768. if ($busClass) {
  769. list($app, $class) = explode('::', $busClass, 2);
  770. if ($c->getAppManager()->isInstalled($app)) {
  771. \OC_App::loadApp($app);
  772. return $c->query($class);
  773. } else {
  774. throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
  775. }
  776. } else {
  777. $jobList = $c->getJobList();
  778. return new CronBus($jobList);
  779. }
  780. });
  781. $this->registerService('TrustedDomainHelper', function ($c) {
  782. return new TrustedDomainHelper($this->getConfig());
  783. });
  784. $this->registerService(Throttler::class, function (Server $c) {
  785. return new Throttler(
  786. $c->getDatabaseConnection(),
  787. new TimeFactory(),
  788. $c->getLogger(),
  789. $c->getConfig()
  790. );
  791. });
  792. $this->registerAlias('Throttler', Throttler::class);
  793. $this->registerService('IntegrityCodeChecker', function (Server $c) {
  794. // IConfig and IAppManager requires a working database. This code
  795. // might however be called when ownCloud is not yet setup.
  796. if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
  797. $config = $c->getConfig();
  798. $appManager = $c->getAppManager();
  799. } else {
  800. $config = null;
  801. $appManager = null;
  802. }
  803. return new Checker(
  804. new EnvironmentHelper(),
  805. new FileAccessHelper(),
  806. new AppLocator(),
  807. $config,
  808. $c->getMemCacheFactory(),
  809. $appManager,
  810. $c->getTempManager(),
  811. $c->getMimeTypeDetector()
  812. );
  813. });
  814. $this->registerService(\OCP\IRequest::class, function ($c) {
  815. if (isset($this['urlParams'])) {
  816. $urlParams = $this['urlParams'];
  817. } else {
  818. $urlParams = [];
  819. }
  820. if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
  821. && in_array('fakeinput', stream_get_wrappers())
  822. ) {
  823. $stream = 'fakeinput://data';
  824. } else {
  825. $stream = 'php://input';
  826. }
  827. return new Request(
  828. [
  829. 'get' => $_GET,
  830. 'post' => $_POST,
  831. 'files' => $_FILES,
  832. 'server' => $_SERVER,
  833. 'env' => $_ENV,
  834. 'cookies' => $_COOKIE,
  835. 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
  836. ? $_SERVER['REQUEST_METHOD']
  837. : '',
  838. 'urlParams' => $urlParams,
  839. ],
  840. $this->getSecureRandom(),
  841. $this->getConfig(),
  842. $this->getCsrfTokenManager(),
  843. $stream
  844. );
  845. });
  846. $this->registerAlias('Request', \OCP\IRequest::class);
  847. $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
  848. return new Mailer(
  849. $c->getConfig(),
  850. $c->getLogger(),
  851. $c->query(Defaults::class),
  852. $c->getURLGenerator(),
  853. $c->getL10N('lib')
  854. );
  855. });
  856. $this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
  857. $this->registerService('LDAPProvider', function (Server $c) {
  858. $config = $c->getConfig();
  859. $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
  860. if (is_null($factoryClass)) {
  861. throw new \Exception('ldapProviderFactory not set');
  862. }
  863. /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
  864. $factory = new $factoryClass($this);
  865. return $factory->getLDAPProvider();
  866. });
  867. $this->registerService(ILockingProvider::class, function (Server $c) {
  868. $ini = $c->getIniWrapper();
  869. $config = $c->getConfig();
  870. $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
  871. if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
  872. /** @var \OC\Memcache\Factory $memcacheFactory */
  873. $memcacheFactory = $c->getMemCacheFactory();
  874. $memcache = $memcacheFactory->createLocking('lock');
  875. if (!($memcache instanceof \OC\Memcache\NullCache)) {
  876. return new MemcacheLockingProvider($memcache, $ttl);
  877. }
  878. return new DBLockingProvider(
  879. $c->getDatabaseConnection(),
  880. $c->getLogger(),
  881. new TimeFactory(),
  882. $ttl,
  883. !\OC::$CLI
  884. );
  885. }
  886. return new NoopLockingProvider();
  887. });
  888. $this->registerAlias('LockingProvider', ILockingProvider::class);
  889. $this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
  890. return new \OC\Files\Mount\Manager();
  891. });
  892. $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
  893. $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
  894. return new \OC\Files\Type\Detection(
  895. $c->getURLGenerator(),
  896. $c->getLogger(),
  897. \OC::$configDir,
  898. \OC::$SERVERROOT . '/resources/config/'
  899. );
  900. });
  901. $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
  902. $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
  903. return new \OC\Files\Type\Loader(
  904. $c->getDatabaseConnection()
  905. );
  906. });
  907. $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
  908. $this->registerService(BundleFetcher::class, function () {
  909. return new BundleFetcher($this->getL10N('lib'));
  910. });
  911. $this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
  912. return new Manager(
  913. $c->query(IValidator::class),
  914. $c->getLogger()
  915. );
  916. });
  917. $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
  918. $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
  919. $manager = new \OC\CapabilitiesManager($c->getLogger());
  920. $manager->registerCapability(function () use ($c) {
  921. return new \OC\OCS\CoreCapabilities($c->getConfig());
  922. });
  923. $manager->registerCapability(function () use ($c) {
  924. return $c->query(\OC\Security\Bruteforce\Capabilities::class);
  925. });
  926. return $manager;
  927. });
  928. $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
  929. $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) {
  930. $config = $c->getConfig();
  931. $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
  932. /** @var \OCP\Comments\ICommentsManagerFactory $factory */
  933. $factory = new $factoryClass($this);
  934. $manager = $factory->getManager();
  935. $manager->registerDisplayNameResolver('user', function($id) use ($c) {
  936. $manager = $c->getUserManager();
  937. $user = $manager->get($id);
  938. if(is_null($user)) {
  939. $l = $c->getL10N('core');
  940. $displayName = $l->t('Unknown user');
  941. } else {
  942. $displayName = $user->getDisplayName();
  943. }
  944. return $displayName;
  945. });
  946. return $manager;
  947. });
  948. $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
  949. $this->registerService('ThemingDefaults', function (Server $c) {
  950. /*
  951. * Dark magic for autoloader.
  952. * If we do a class_exists it will try to load the class which will
  953. * make composer cache the result. Resulting in errors when enabling
  954. * the theming app.
  955. */
  956. $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
  957. if (isset($prefixes['OCA\\Theming\\'])) {
  958. $classExists = true;
  959. } else {
  960. $classExists = false;
  961. }
  962. if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
  963. return new ThemingDefaults(
  964. $c->getConfig(),
  965. $c->getL10N('theming'),
  966. $c->getURLGenerator(),
  967. $c->getMemCacheFactory(),
  968. new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')),
  969. new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()),
  970. $c->getAppManager(),
  971. $c->getNavigationManager()
  972. );
  973. }
  974. return new \OC_Defaults();
  975. });
  976. $this->registerService(SCSSCacher::class, function (Server $c) {
  977. return new SCSSCacher(
  978. $c->getLogger(),
  979. $c->query(\OC\Files\AppData\Factory::class),
  980. $c->getURLGenerator(),
  981. $c->getConfig(),
  982. $c->getThemingDefaults(),
  983. \OC::$SERVERROOT,
  984. $this->getMemCacheFactory(),
  985. $c->query(IconsCacher::class),
  986. new TimeFactory()
  987. );
  988. });
  989. $this->registerService(JSCombiner::class, function (Server $c) {
  990. return new JSCombiner(
  991. $c->getAppDataDir('js'),
  992. $c->getURLGenerator(),
  993. $this->getMemCacheFactory(),
  994. $c->getSystemConfig(),
  995. $c->getLogger()
  996. );
  997. });
  998. $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class);
  999. $this->registerAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class);
  1000. $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class);
  1001. $this->registerService('CryptoWrapper', function (Server $c) {
  1002. // FIXME: Instantiiated here due to cyclic dependency
  1003. $request = new Request(
  1004. [
  1005. 'get' => $_GET,
  1006. 'post' => $_POST,
  1007. 'files' => $_FILES,
  1008. 'server' => $_SERVER,
  1009. 'env' => $_ENV,
  1010. 'cookies' => $_COOKIE,
  1011. 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
  1012. ? $_SERVER['REQUEST_METHOD']
  1013. : null,
  1014. ],
  1015. $c->getSecureRandom(),
  1016. $c->getConfig()
  1017. );
  1018. return new CryptoWrapper(
  1019. $c->getConfig(),
  1020. $c->getCrypto(),
  1021. $c->getSecureRandom(),
  1022. $request
  1023. );
  1024. });
  1025. $this->registerService(CsrfTokenManager::class, function (Server $c) {
  1026. $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
  1027. return new CsrfTokenManager(
  1028. $tokenGenerator,
  1029. $c->query(SessionStorage::class)
  1030. );
  1031. });
  1032. $this->registerAlias('CsrfTokenManager', CsrfTokenManager::class);
  1033. $this->registerService(SessionStorage::class, function (Server $c) {
  1034. return new SessionStorage($c->getSession());
  1035. });
  1036. $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, \OC\Security\CSP\ContentSecurityPolicyManager::class);
  1037. $this->registerAlias('ContentSecurityPolicyManager', \OC\Security\CSP\ContentSecurityPolicyManager::class);
  1038. $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
  1039. return new ContentSecurityPolicyNonceManager(
  1040. $c->getCsrfTokenManager(),
  1041. $c->getRequest()
  1042. );
  1043. });
  1044. $this->registerService(\OCP\Share\IManager::class, function (Server $c) {
  1045. $config = $c->getConfig();
  1046. $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
  1047. /** @var \OCP\Share\IProviderFactory $factory */
  1048. $factory = new $factoryClass($this);
  1049. $manager = new \OC\Share20\Manager(
  1050. $c->getLogger(),
  1051. $c->getConfig(),
  1052. $c->getSecureRandom(),
  1053. $c->getHasher(),
  1054. $c->getMountManager(),
  1055. $c->getGroupManager(),
  1056. $c->getL10N('lib'),
  1057. $c->getL10NFactory(),
  1058. $factory,
  1059. $c->getUserManager(),
  1060. $c->getLazyRootFolder(),
  1061. $c->getEventDispatcher(),
  1062. $c->getMailer(),
  1063. $c->getURLGenerator(),
  1064. $c->getThemingDefaults(),
  1065. $c->query(IEventDispatcher::class)
  1066. );
  1067. return $manager;
  1068. });
  1069. $this->registerAlias('ShareManager', \OCP\Share\IManager::class);
  1070. $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) {
  1071. $instance = new Collaboration\Collaborators\Search($c);
  1072. // register default plugins
  1073. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
  1074. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
  1075. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
  1076. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
  1077. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
  1078. return $instance;
  1079. });
  1080. $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
  1081. $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
  1082. $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
  1083. $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class);
  1084. $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class);
  1085. $this->registerService('SettingsManager', function (Server $c) {
  1086. $manager = new \OC\Settings\Manager(
  1087. $c->getLogger(),
  1088. $c->getL10NFactory(),
  1089. $c->getURLGenerator(),
  1090. $c
  1091. );
  1092. return $manager;
  1093. });
  1094. $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
  1095. return new \OC\Files\AppData\Factory(
  1096. $c->getRootFolder(),
  1097. $c->getSystemConfig()
  1098. );
  1099. });
  1100. $this->registerService('LockdownManager', function (Server $c) {
  1101. return new LockdownManager(function () use ($c) {
  1102. return $c->getSession();
  1103. });
  1104. });
  1105. $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
  1106. return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
  1107. });
  1108. $this->registerService(ICloudIdManager::class, function (Server $c) {
  1109. return new CloudIdManager();
  1110. });
  1111. $this->registerService(IConfig::class, function (Server $c) {
  1112. return new GlobalScale\Config($c->getConfig());
  1113. });
  1114. $this->registerService(ICloudFederationProviderManager::class, function (Server $c) {
  1115. return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger());
  1116. });
  1117. $this->registerService(ICloudFederationFactory::class, function (Server $c) {
  1118. return new CloudFederationFactory();
  1119. });
  1120. $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
  1121. $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
  1122. $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
  1123. $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
  1124. $this->registerService(Defaults::class, function (Server $c) {
  1125. return new Defaults(
  1126. $c->getThemingDefaults()
  1127. );
  1128. });
  1129. $this->registerAlias('Defaults', \OCP\Defaults::class);
  1130. $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
  1131. return $c->query(\OCP\IUserSession::class)->getSession();
  1132. });
  1133. $this->registerService(IShareHelper::class, function (Server $c) {
  1134. return new ShareHelper(
  1135. $c->query(\OCP\Share\IManager::class)
  1136. );
  1137. });
  1138. $this->registerService(Installer::class, function(Server $c) {
  1139. return new Installer(
  1140. $c->getAppFetcher(),
  1141. $c->getHTTPClientService(),
  1142. $c->getTempManager(),
  1143. $c->getLogger(),
  1144. $c->getConfig()
  1145. );
  1146. });
  1147. $this->registerService(IApiFactory::class, function(Server $c) {
  1148. return new ApiFactory($c->getHTTPClientService());
  1149. });
  1150. $this->registerService(IInstanceFactory::class, function(Server $c) {
  1151. $memcacheFactory = $c->getMemCacheFactory();
  1152. return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
  1153. });
  1154. $this->registerService(IContactsStore::class, function(Server $c) {
  1155. return new ContactsStore(
  1156. $c->getContactsManager(),
  1157. $c->getConfig(),
  1158. $c->getUserManager(),
  1159. $c->getGroupManager()
  1160. );
  1161. });
  1162. $this->registerAlias(IContactsStore::class, ContactsStore::class);
  1163. $this->registerAlias(IAccountManager::class, AccountManager::class);
  1164. $this->registerService(IStorageFactory::class, function() {
  1165. return new StorageFactory();
  1166. });
  1167. $this->registerAlias(IDashboardManager::class, DashboardManager::class);
  1168. $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
  1169. $this->registerAlias(ISubAdmin::class, SubAdmin::class);
  1170. $this->registerAlias(IInitialStateService::class, InitialStateService::class);
  1171. $this->connectDispatcher();
  1172. }
  1173. /**
  1174. * @return \OCP\Calendar\IManager
  1175. */
  1176. public function getCalendarManager() {
  1177. return $this->query('CalendarManager');
  1178. }
  1179. /**
  1180. * @return \OCP\Calendar\Resource\IManager
  1181. */
  1182. public function getCalendarResourceBackendManager() {
  1183. return $this->query('CalendarResourceBackendManager');
  1184. }
  1185. /**
  1186. * @return \OCP\Calendar\Room\IManager
  1187. */
  1188. public function getCalendarRoomBackendManager() {
  1189. return $this->query('CalendarRoomBackendManager');
  1190. }
  1191. private function connectDispatcher() {
  1192. $dispatcher = $this->getEventDispatcher();
  1193. // Delete avatar on user deletion
  1194. $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) {
  1195. $logger = $this->getLogger();
  1196. $manager = $this->getAvatarManager();
  1197. /** @var IUser $user */
  1198. $user = $e->getSubject();
  1199. try {
  1200. $avatar = $manager->getAvatar($user->getUID());
  1201. $avatar->remove();
  1202. } catch (NotFoundException $e) {
  1203. // no avatar to remove
  1204. } catch (\Exception $e) {
  1205. // Ignore exceptions
  1206. $logger->info('Could not cleanup avatar of ' . $user->getUID());
  1207. }
  1208. });
  1209. $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
  1210. $manager = $this->getAvatarManager();
  1211. /** @var IUser $user */
  1212. $user = $e->getSubject();
  1213. $feature = $e->getArgument('feature');
  1214. $oldValue = $e->getArgument('oldValue');
  1215. $value = $e->getArgument('value');
  1216. // We only change the avatar on display name changes
  1217. if ($feature !== 'displayName') {
  1218. return;
  1219. }
  1220. try {
  1221. $avatar = $manager->getAvatar($user->getUID());
  1222. $avatar->userChanged($feature, $oldValue, $value);
  1223. } catch (NotFoundException $e) {
  1224. // no avatar to remove
  1225. }
  1226. });
  1227. }
  1228. /**
  1229. * @return \OCP\Contacts\IManager
  1230. */
  1231. public function getContactsManager() {
  1232. return $this->query('ContactsManager');
  1233. }
  1234. /**
  1235. * @return \OC\Encryption\Manager
  1236. */
  1237. public function getEncryptionManager() {
  1238. return $this->query('EncryptionManager');
  1239. }
  1240. /**
  1241. * @return \OC\Encryption\File
  1242. */
  1243. public function getEncryptionFilesHelper() {
  1244. return $this->query('EncryptionFileHelper');
  1245. }
  1246. /**
  1247. * @return \OCP\Encryption\Keys\IStorage
  1248. */
  1249. public function getEncryptionKeyStorage() {
  1250. return $this->query('EncryptionKeyStorage');
  1251. }
  1252. /**
  1253. * The current request object holding all information about the request
  1254. * currently being processed is returned from this method.
  1255. * In case the current execution was not initiated by a web request null is returned
  1256. *
  1257. * @return \OCP\IRequest
  1258. */
  1259. public function getRequest() {
  1260. return $this->query('Request');
  1261. }
  1262. /**
  1263. * Returns the preview manager which can create preview images for a given file
  1264. *
  1265. * @return \OCP\IPreview
  1266. */
  1267. public function getPreviewManager() {
  1268. return $this->query('PreviewManager');
  1269. }
  1270. /**
  1271. * Returns the tag manager which can get and set tags for different object types
  1272. *
  1273. * @see \OCP\ITagManager::load()
  1274. * @return \OCP\ITagManager
  1275. */
  1276. public function getTagManager() {
  1277. return $this->query('TagManager');
  1278. }
  1279. /**
  1280. * Returns the system-tag manager
  1281. *
  1282. * @return \OCP\SystemTag\ISystemTagManager
  1283. *
  1284. * @since 9.0.0
  1285. */
  1286. public function getSystemTagManager() {
  1287. return $this->query('SystemTagManager');
  1288. }
  1289. /**
  1290. * Returns the system-tag object mapper
  1291. *
  1292. * @return \OCP\SystemTag\ISystemTagObjectMapper
  1293. *
  1294. * @since 9.0.0
  1295. */
  1296. public function getSystemTagObjectMapper() {
  1297. return $this->query('SystemTagObjectMapper');
  1298. }
  1299. /**
  1300. * Returns the avatar manager, used for avatar functionality
  1301. *
  1302. * @return \OCP\IAvatarManager
  1303. */
  1304. public function getAvatarManager() {
  1305. return $this->query('AvatarManager');
  1306. }
  1307. /**
  1308. * Returns the root folder of ownCloud's data directory
  1309. *
  1310. * @return \OCP\Files\IRootFolder
  1311. */
  1312. public function getRootFolder() {
  1313. return $this->query('LazyRootFolder');
  1314. }
  1315. /**
  1316. * Returns the root folder of ownCloud's data directory
  1317. * This is the lazy variant so this gets only initialized once it
  1318. * is actually used.
  1319. *
  1320. * @return \OCP\Files\IRootFolder
  1321. */
  1322. public function getLazyRootFolder() {
  1323. return $this->query('LazyRootFolder');
  1324. }
  1325. /**
  1326. * Returns a view to ownCloud's files folder
  1327. *
  1328. * @param string $userId user ID
  1329. * @return \OCP\Files\Folder|null
  1330. */
  1331. public function getUserFolder($userId = null) {
  1332. if ($userId === null) {
  1333. $user = $this->getUserSession()->getUser();
  1334. if (!$user) {
  1335. return null;
  1336. }
  1337. $userId = $user->getUID();
  1338. }
  1339. $root = $this->getRootFolder();
  1340. return $root->getUserFolder($userId);
  1341. }
  1342. /**
  1343. * Returns an app-specific view in ownClouds data directory
  1344. *
  1345. * @return \OCP\Files\Folder
  1346. * @deprecated since 9.2.0 use IAppData
  1347. */
  1348. public function getAppFolder() {
  1349. $dir = '/' . \OC_App::getCurrentApp();
  1350. $root = $this->getRootFolder();
  1351. if (!$root->nodeExists($dir)) {
  1352. $folder = $root->newFolder($dir);
  1353. } else {
  1354. $folder = $root->get($dir);
  1355. }
  1356. return $folder;
  1357. }
  1358. /**
  1359. * @return \OC\User\Manager
  1360. */
  1361. public function getUserManager() {
  1362. return $this->query('UserManager');
  1363. }
  1364. /**
  1365. * @return \OC\Group\Manager
  1366. */
  1367. public function getGroupManager() {
  1368. return $this->query('GroupManager');
  1369. }
  1370. /**
  1371. * @return \OC\User\Session
  1372. */
  1373. public function getUserSession() {
  1374. return $this->query('UserSession');
  1375. }
  1376. /**
  1377. * @return \OCP\ISession
  1378. */
  1379. public function getSession() {
  1380. return $this->query('UserSession')->getSession();
  1381. }
  1382. /**
  1383. * @param \OCP\ISession $session
  1384. */
  1385. public function setSession(\OCP\ISession $session) {
  1386. $this->query(SessionStorage::class)->setSession($session);
  1387. $this->query('UserSession')->setSession($session);
  1388. $this->query(Store::class)->setSession($session);
  1389. }
  1390. /**
  1391. * @return \OC\Authentication\TwoFactorAuth\Manager
  1392. */
  1393. public function getTwoFactorAuthManager() {
  1394. return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
  1395. }
  1396. /**
  1397. * @return \OC\NavigationManager
  1398. */
  1399. public function getNavigationManager() {
  1400. return $this->query('NavigationManager');
  1401. }
  1402. /**
  1403. * @return \OCP\IConfig
  1404. */
  1405. public function getConfig() {
  1406. return $this->query('AllConfig');
  1407. }
  1408. /**
  1409. * @return \OC\SystemConfig
  1410. */
  1411. public function getSystemConfig() {
  1412. return $this->query('SystemConfig');
  1413. }
  1414. /**
  1415. * Returns the app config manager
  1416. *
  1417. * @return \OCP\IAppConfig
  1418. */
  1419. public function getAppConfig() {
  1420. return $this->query('AppConfig');
  1421. }
  1422. /**
  1423. * @return \OCP\L10N\IFactory
  1424. */
  1425. public function getL10NFactory() {
  1426. return $this->query('L10NFactory');
  1427. }
  1428. /**
  1429. * get an L10N instance
  1430. *
  1431. * @param string $app appid
  1432. * @param string $lang
  1433. * @return IL10N
  1434. */
  1435. public function getL10N($app, $lang = null) {
  1436. return $this->getL10NFactory()->get($app, $lang);
  1437. }
  1438. /**
  1439. * @return \OCP\IURLGenerator
  1440. */
  1441. public function getURLGenerator() {
  1442. return $this->query('URLGenerator');
  1443. }
  1444. /**
  1445. * @return AppFetcher
  1446. */
  1447. public function getAppFetcher() {
  1448. return $this->query(AppFetcher::class);
  1449. }
  1450. /**
  1451. * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
  1452. * getMemCacheFactory() instead.
  1453. *
  1454. * @return \OCP\ICache
  1455. * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
  1456. */
  1457. public function getCache() {
  1458. return $this->query('UserCache');
  1459. }
  1460. /**
  1461. * Returns an \OCP\CacheFactory instance
  1462. *
  1463. * @return \OCP\ICacheFactory
  1464. */
  1465. public function getMemCacheFactory() {
  1466. return $this->query('MemCacheFactory');
  1467. }
  1468. /**
  1469. * Returns an \OC\RedisFactory instance
  1470. *
  1471. * @return \OC\RedisFactory
  1472. */
  1473. public function getGetRedisFactory() {
  1474. return $this->query('RedisFactory');
  1475. }
  1476. /**
  1477. * Returns the current session
  1478. *
  1479. * @return \OCP\IDBConnection
  1480. */
  1481. public function getDatabaseConnection() {
  1482. return $this->query('DatabaseConnection');
  1483. }
  1484. /**
  1485. * Returns the activity manager
  1486. *
  1487. * @return \OCP\Activity\IManager
  1488. */
  1489. public function getActivityManager() {
  1490. return $this->query('ActivityManager');
  1491. }
  1492. /**
  1493. * Returns an job list for controlling background jobs
  1494. *
  1495. * @return \OCP\BackgroundJob\IJobList
  1496. */
  1497. public function getJobList() {
  1498. return $this->query('JobList');
  1499. }
  1500. /**
  1501. * Returns a logger instance
  1502. *
  1503. * @return \OCP\ILogger
  1504. */
  1505. public function getLogger() {
  1506. return $this->query('Logger');
  1507. }
  1508. /**
  1509. * @return ILogFactory
  1510. * @throws \OCP\AppFramework\QueryException
  1511. */
  1512. public function getLogFactory() {
  1513. return $this->query(ILogFactory::class);
  1514. }
  1515. /**
  1516. * Returns a router for generating and matching urls
  1517. *
  1518. * @return \OCP\Route\IRouter
  1519. */
  1520. public function getRouter() {
  1521. return $this->query('Router');
  1522. }
  1523. /**
  1524. * Returns a search instance
  1525. *
  1526. * @return \OCP\ISearch
  1527. */
  1528. public function getSearch() {
  1529. return $this->query('Search');
  1530. }
  1531. /**
  1532. * Returns a SecureRandom instance
  1533. *
  1534. * @return \OCP\Security\ISecureRandom
  1535. */
  1536. public function getSecureRandom() {
  1537. return $this->query('SecureRandom');
  1538. }
  1539. /**
  1540. * Returns a Crypto instance
  1541. *
  1542. * @return \OCP\Security\ICrypto
  1543. */
  1544. public function getCrypto() {
  1545. return $this->query('Crypto');
  1546. }
  1547. /**
  1548. * Returns a Hasher instance
  1549. *
  1550. * @return \OCP\Security\IHasher
  1551. */
  1552. public function getHasher() {
  1553. return $this->query('Hasher');
  1554. }
  1555. /**
  1556. * Returns a CredentialsManager instance
  1557. *
  1558. * @return \OCP\Security\ICredentialsManager
  1559. */
  1560. public function getCredentialsManager() {
  1561. return $this->query('CredentialsManager');
  1562. }
  1563. /**
  1564. * Get the certificate manager for the user
  1565. *
  1566. * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
  1567. * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
  1568. */
  1569. public function getCertificateManager($userId = '') {
  1570. if ($userId === '') {
  1571. $userSession = $this->getUserSession();
  1572. $user = $userSession->getUser();
  1573. if (is_null($user)) {
  1574. return null;
  1575. }
  1576. $userId = $user->getUID();
  1577. }
  1578. return new CertificateManager(
  1579. $userId,
  1580. new View(),
  1581. $this->getConfig(),
  1582. $this->getLogger(),
  1583. $this->getSecureRandom()
  1584. );
  1585. }
  1586. /**
  1587. * Returns an instance of the HTTP client service
  1588. *
  1589. * @return \OCP\Http\Client\IClientService
  1590. */
  1591. public function getHTTPClientService() {
  1592. return $this->query('HttpClientService');
  1593. }
  1594. /**
  1595. * Create a new event source
  1596. *
  1597. * @return \OCP\IEventSource
  1598. */
  1599. public function createEventSource() {
  1600. return new \OC_EventSource();
  1601. }
  1602. /**
  1603. * Get the active event logger
  1604. *
  1605. * The returned logger only logs data when debug mode is enabled
  1606. *
  1607. * @return \OCP\Diagnostics\IEventLogger
  1608. */
  1609. public function getEventLogger() {
  1610. return $this->query('EventLogger');
  1611. }
  1612. /**
  1613. * Get the active query logger
  1614. *
  1615. * The returned logger only logs data when debug mode is enabled
  1616. *
  1617. * @return \OCP\Diagnostics\IQueryLogger
  1618. */
  1619. public function getQueryLogger() {
  1620. return $this->query('QueryLogger');
  1621. }
  1622. /**
  1623. * Get the manager for temporary files and folders
  1624. *
  1625. * @return \OCP\ITempManager
  1626. */
  1627. public function getTempManager() {
  1628. return $this->query('TempManager');
  1629. }
  1630. /**
  1631. * Get the app manager
  1632. *
  1633. * @return \OCP\App\IAppManager
  1634. */
  1635. public function getAppManager() {
  1636. return $this->query('AppManager');
  1637. }
  1638. /**
  1639. * Creates a new mailer
  1640. *
  1641. * @return \OCP\Mail\IMailer
  1642. */
  1643. public function getMailer() {
  1644. return $this->query('Mailer');
  1645. }
  1646. /**
  1647. * Get the webroot
  1648. *
  1649. * @return string
  1650. */
  1651. public function getWebRoot() {
  1652. return $this->webRoot;
  1653. }
  1654. /**
  1655. * @return \OC\OCSClient
  1656. */
  1657. public function getOcsClient() {
  1658. return $this->query('OcsClient');
  1659. }
  1660. /**
  1661. * @return \OCP\IDateTimeZone
  1662. */
  1663. public function getDateTimeZone() {
  1664. return $this->query('DateTimeZone');
  1665. }
  1666. /**
  1667. * @return \OCP\IDateTimeFormatter
  1668. */
  1669. public function getDateTimeFormatter() {
  1670. return $this->query('DateTimeFormatter');
  1671. }
  1672. /**
  1673. * @return \OCP\Files\Config\IMountProviderCollection
  1674. */
  1675. public function getMountProviderCollection() {
  1676. return $this->query('MountConfigManager');
  1677. }
  1678. /**
  1679. * Get the IniWrapper
  1680. *
  1681. * @return IniGetWrapper
  1682. */
  1683. public function getIniWrapper() {
  1684. return $this->query('IniWrapper');
  1685. }
  1686. /**
  1687. * @return \OCP\Command\IBus
  1688. */
  1689. public function getCommandBus() {
  1690. return $this->query('AsyncCommandBus');
  1691. }
  1692. /**
  1693. * Get the trusted domain helper
  1694. *
  1695. * @return TrustedDomainHelper
  1696. */
  1697. public function getTrustedDomainHelper() {
  1698. return $this->query('TrustedDomainHelper');
  1699. }
  1700. /**
  1701. * Get the locking provider
  1702. *
  1703. * @return \OCP\Lock\ILockingProvider
  1704. * @since 8.1.0
  1705. */
  1706. public function getLockingProvider() {
  1707. return $this->query('LockingProvider');
  1708. }
  1709. /**
  1710. * @return \OCP\Files\Mount\IMountManager
  1711. **/
  1712. function getMountManager() {
  1713. return $this->query('MountManager');
  1714. }
  1715. /** @return \OCP\Files\Config\IUserMountCache */
  1716. function getUserMountCache() {
  1717. return $this->query('UserMountCache');
  1718. }
  1719. /**
  1720. * Get the MimeTypeDetector
  1721. *
  1722. * @return \OCP\Files\IMimeTypeDetector
  1723. */
  1724. public function getMimeTypeDetector() {
  1725. return $this->query('MimeTypeDetector');
  1726. }
  1727. /**
  1728. * Get the MimeTypeLoader
  1729. *
  1730. * @return \OCP\Files\IMimeTypeLoader
  1731. */
  1732. public function getMimeTypeLoader() {
  1733. return $this->query('MimeTypeLoader');
  1734. }
  1735. /**
  1736. * Get the manager of all the capabilities
  1737. *
  1738. * @return \OC\CapabilitiesManager
  1739. */
  1740. public function getCapabilitiesManager() {
  1741. return $this->query('CapabilitiesManager');
  1742. }
  1743. /**
  1744. * Get the EventDispatcher
  1745. *
  1746. * @return EventDispatcherInterface
  1747. * @since 8.2.0
  1748. * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher
  1749. */
  1750. public function getEventDispatcher() {
  1751. return $this->query(\OC\EventDispatcher\SymfonyAdapter::class);
  1752. }
  1753. /**
  1754. * Get the Notification Manager
  1755. *
  1756. * @return \OCP\Notification\IManager
  1757. * @since 8.2.0
  1758. */
  1759. public function getNotificationManager() {
  1760. return $this->query('NotificationManager');
  1761. }
  1762. /**
  1763. * @return \OCP\Comments\ICommentsManager
  1764. */
  1765. public function getCommentsManager() {
  1766. return $this->query('CommentsManager');
  1767. }
  1768. /**
  1769. * @return \OCA\Theming\ThemingDefaults
  1770. */
  1771. public function getThemingDefaults() {
  1772. return $this->query('ThemingDefaults');
  1773. }
  1774. /**
  1775. * @return \OC\IntegrityCheck\Checker
  1776. */
  1777. public function getIntegrityCodeChecker() {
  1778. return $this->query('IntegrityCodeChecker');
  1779. }
  1780. /**
  1781. * @return \OC\Session\CryptoWrapper
  1782. */
  1783. public function getSessionCryptoWrapper() {
  1784. return $this->query('CryptoWrapper');
  1785. }
  1786. /**
  1787. * @return CsrfTokenManager
  1788. */
  1789. public function getCsrfTokenManager() {
  1790. return $this->query(CsrfTokenManager::class);
  1791. }
  1792. /**
  1793. * @return Throttler
  1794. */
  1795. public function getBruteForceThrottler() {
  1796. return $this->query('Throttler');
  1797. }
  1798. /**
  1799. * @return IContentSecurityPolicyManager
  1800. */
  1801. public function getContentSecurityPolicyManager() {
  1802. return $this->query('ContentSecurityPolicyManager');
  1803. }
  1804. /**
  1805. * @return ContentSecurityPolicyNonceManager
  1806. */
  1807. public function getContentSecurityPolicyNonceManager() {
  1808. return $this->query('ContentSecurityPolicyNonceManager');
  1809. }
  1810. /**
  1811. * Not a public API as of 8.2, wait for 9.0
  1812. *
  1813. * @return \OCA\Files_External\Service\BackendService
  1814. */
  1815. public function getStoragesBackendService() {
  1816. return $this->query('OCA\\Files_External\\Service\\BackendService');
  1817. }
  1818. /**
  1819. * Not a public API as of 8.2, wait for 9.0
  1820. *
  1821. * @return \OCA\Files_External\Service\GlobalStoragesService
  1822. */
  1823. public function getGlobalStoragesService() {
  1824. return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
  1825. }
  1826. /**
  1827. * Not a public API as of 8.2, wait for 9.0
  1828. *
  1829. * @return \OCA\Files_External\Service\UserGlobalStoragesService
  1830. */
  1831. public function getUserGlobalStoragesService() {
  1832. return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
  1833. }
  1834. /**
  1835. * Not a public API as of 8.2, wait for 9.0
  1836. *
  1837. * @return \OCA\Files_External\Service\UserStoragesService
  1838. */
  1839. public function getUserStoragesService() {
  1840. return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
  1841. }
  1842. /**
  1843. * @return \OCP\Share\IManager
  1844. */
  1845. public function getShareManager() {
  1846. return $this->query('ShareManager');
  1847. }
  1848. /**
  1849. * @return \OCP\Collaboration\Collaborators\ISearch
  1850. */
  1851. public function getCollaboratorSearch() {
  1852. return $this->query('CollaboratorSearch');
  1853. }
  1854. /**
  1855. * @return \OCP\Collaboration\AutoComplete\IManager
  1856. */
  1857. public function getAutoCompleteManager(){
  1858. return $this->query(IManager::class);
  1859. }
  1860. /**
  1861. * Returns the LDAP Provider
  1862. *
  1863. * @return \OCP\LDAP\ILDAPProvider
  1864. */
  1865. public function getLDAPProvider() {
  1866. return $this->query('LDAPProvider');
  1867. }
  1868. /**
  1869. * @return \OCP\Settings\IManager
  1870. */
  1871. public function getSettingsManager() {
  1872. return $this->query('SettingsManager');
  1873. }
  1874. /**
  1875. * @return \OCP\Files\IAppData
  1876. */
  1877. public function getAppDataDir($app) {
  1878. /** @var \OC\Files\AppData\Factory $factory */
  1879. $factory = $this->query(\OC\Files\AppData\Factory::class);
  1880. return $factory->get($app);
  1881. }
  1882. /**
  1883. * @return \OCP\Lockdown\ILockdownManager
  1884. */
  1885. public function getLockdownManager() {
  1886. return $this->query('LockdownManager');
  1887. }
  1888. /**
  1889. * @return \OCP\Federation\ICloudIdManager
  1890. */
  1891. public function getCloudIdManager() {
  1892. return $this->query(ICloudIdManager::class);
  1893. }
  1894. /**
  1895. * @return \OCP\GlobalScale\IConfig
  1896. */
  1897. public function getGlobalScaleConfig() {
  1898. return $this->query(IConfig::class);
  1899. }
  1900. /**
  1901. * @return \OCP\Federation\ICloudFederationProviderManager
  1902. */
  1903. public function getCloudFederationProviderManager() {
  1904. return $this->query(ICloudFederationProviderManager::class);
  1905. }
  1906. /**
  1907. * @return \OCP\Remote\Api\IApiFactory
  1908. */
  1909. public function getRemoteApiFactory() {
  1910. return $this->query(IApiFactory::class);
  1911. }
  1912. /**
  1913. * @return \OCP\Federation\ICloudFederationFactory
  1914. */
  1915. public function getCloudFederationFactory() {
  1916. return $this->query(ICloudFederationFactory::class);
  1917. }
  1918. /**
  1919. * @return \OCP\Remote\IInstanceFactory
  1920. */
  1921. public function getRemoteInstanceFactory() {
  1922. return $this->query(IInstanceFactory::class);
  1923. }
  1924. /**
  1925. * @return IStorageFactory
  1926. */
  1927. public function getStorageFactory() {
  1928. return $this->query(IStorageFactory::class);
  1929. }
  1930. /**
  1931. * Get the Preview GeneratorHelper
  1932. *
  1933. * @return GeneratorHelper
  1934. * @since 17.0.0
  1935. */
  1936. public function getGeneratorHelper() {
  1937. return $this->query(\OC\Preview\GeneratorHelper::class);
  1938. }
  1939. }