@@ -164,8 +164,8 @@ |
||
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
167 | - * @param array $states |
|
168 | - * @param IProvider $providers |
|
167 | + * @param string[] $states |
|
168 | + * @param IProvider[] $providers |
|
169 | 169 | */ |
170 | 170 | private function isProviderMissing(array $states, array $providers): bool { |
171 | 171 | $indexed = []; |
@@ -44,331 +44,331 @@ |
||
44 | 44 | |
45 | 45 | class Manager { |
46 | 46 | |
47 | - const SESSION_UID_KEY = 'two_factor_auth_uid'; |
|
48 | - const SESSION_UID_DONE = 'two_factor_auth_passed'; |
|
49 | - const REMEMBER_LOGIN = 'two_factor_remember_login'; |
|
50 | - |
|
51 | - /** @var ProviderLoader */ |
|
52 | - private $providerLoader; |
|
53 | - |
|
54 | - /** @var IRegistry */ |
|
55 | - private $providerRegistry; |
|
56 | - |
|
57 | - /** @var ISession */ |
|
58 | - private $session; |
|
59 | - |
|
60 | - /** @var IConfig */ |
|
61 | - private $config; |
|
62 | - |
|
63 | - /** @var IManager */ |
|
64 | - private $activityManager; |
|
65 | - |
|
66 | - /** @var ILogger */ |
|
67 | - private $logger; |
|
68 | - |
|
69 | - /** @var TokenProvider */ |
|
70 | - private $tokenProvider; |
|
71 | - |
|
72 | - /** @var ITimeFactory */ |
|
73 | - private $timeFactory; |
|
74 | - |
|
75 | - /** @var EventDispatcherInterface */ |
|
76 | - private $dispatcher; |
|
77 | - |
|
78 | - public function __construct(ProviderLoader $providerLoader, |
|
79 | - IRegistry $providerRegistry, ISession $session, IConfig $config, |
|
80 | - IManager $activityManager, ILogger $logger, TokenProvider $tokenProvider, |
|
81 | - ITimeFactory $timeFactory, EventDispatcherInterface $eventDispatcher) { |
|
82 | - $this->providerLoader = $providerLoader; |
|
83 | - $this->session = $session; |
|
84 | - $this->config = $config; |
|
85 | - $this->activityManager = $activityManager; |
|
86 | - $this->logger = $logger; |
|
87 | - $this->tokenProvider = $tokenProvider; |
|
88 | - $this->timeFactory = $timeFactory; |
|
89 | - $this->dispatcher = $eventDispatcher; |
|
90 | - $this->providerRegistry = $providerRegistry; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Determine whether the user must provide a second factor challenge |
|
95 | - * |
|
96 | - * @param IUser $user |
|
97 | - * @return boolean |
|
98 | - */ |
|
99 | - public function isTwoFactorAuthenticated(IUser $user): bool { |
|
100 | - $twoFactorEnabled = ((int) $this->config->getUserValue($user->getUID(), 'core', 'two_factor_auth_disabled', 0)) === 0; |
|
101 | - |
|
102 | - if (!$twoFactorEnabled) { |
|
103 | - return false; |
|
104 | - } |
|
105 | - |
|
106 | - $providerStates = $this->providerRegistry->getProviderStates($user); |
|
107 | - $enabled = array_filter($providerStates); |
|
108 | - |
|
109 | - return $twoFactorEnabled && !empty($enabled); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Disable 2FA checks for the given user |
|
114 | - * |
|
115 | - * @param IUser $user |
|
116 | - */ |
|
117 | - public function disableTwoFactorAuthentication(IUser $user) { |
|
118 | - $this->config->setUserValue($user->getUID(), 'core', 'two_factor_auth_disabled', 1); |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Enable all 2FA checks for the given user |
|
123 | - * |
|
124 | - * @param IUser $user |
|
125 | - */ |
|
126 | - public function enableTwoFactorAuthentication(IUser $user) { |
|
127 | - $this->config->deleteUserValue($user->getUID(), 'core', 'two_factor_auth_disabled'); |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Get a 2FA provider by its ID |
|
132 | - * |
|
133 | - * @param IUser $user |
|
134 | - * @param string $challengeProviderId |
|
135 | - * @return IProvider|null |
|
136 | - */ |
|
137 | - public function getProvider(IUser $user, string $challengeProviderId) { |
|
138 | - $providers = $this->getProviderSet($user)->getProviders(); |
|
139 | - return $providers[$challengeProviderId] ?? null; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Check if the persistant mapping of enabled/disabled state of each available |
|
144 | - * provider is missing an entry and add it to the registry in that case. |
|
145 | - * |
|
146 | - * @todo remove in Nextcloud 17 as by then all providers should have been updated |
|
147 | - * |
|
148 | - * @param string[] $providerStates |
|
149 | - * @param IProvider[] $providers |
|
150 | - * @param IUser $user |
|
151 | - * @return string[] the updated $providerStates variable |
|
152 | - */ |
|
153 | - private function fixMissingProviderStates(array $providerStates, |
|
154 | - array $providers, IUser $user): array { |
|
155 | - |
|
156 | - foreach ($providers as $provider) { |
|
157 | - if (isset($providerStates[$provider->getId()])) { |
|
158 | - // All good |
|
159 | - continue; |
|
160 | - } |
|
161 | - |
|
162 | - $enabled = $provider->isTwoFactorAuthEnabledForUser($user); |
|
163 | - if ($enabled) { |
|
164 | - $this->providerRegistry->enableProviderFor($provider, $user); |
|
165 | - } else { |
|
166 | - $this->providerRegistry->disableProviderFor($provider, $user); |
|
167 | - } |
|
168 | - $providerStates[$provider->getId()] = $enabled; |
|
169 | - } |
|
170 | - |
|
171 | - return $providerStates; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * @param array $states |
|
176 | - * @param IProvider $providers |
|
177 | - */ |
|
178 | - private function isProviderMissing(array $states, array $providers): bool { |
|
179 | - $indexed = []; |
|
180 | - foreach ($providers as $provider) { |
|
181 | - $indexed[$provider->getId()] = $provider; |
|
182 | - } |
|
183 | - |
|
184 | - $missing = []; |
|
185 | - foreach ($states as $providerId => $enabled) { |
|
186 | - if (!$enabled) { |
|
187 | - // Don't care |
|
188 | - continue; |
|
189 | - } |
|
190 | - |
|
191 | - if (!isset($indexed[$providerId])) { |
|
192 | - $missing[] = $providerId; |
|
193 | - $this->logger->alert("two-factor auth provider '$providerId' failed to load", |
|
194 | - [ |
|
195 | - 'app' => 'core', |
|
196 | - ]); |
|
197 | - } |
|
198 | - } |
|
199 | - |
|
200 | - if (!empty($missing)) { |
|
201 | - // There was at least one provider missing |
|
202 | - $this->logger->alert(count($missing) . " two-factor auth providers failed to load", ['app' => 'core']); |
|
203 | - |
|
204 | - return true; |
|
205 | - } |
|
206 | - |
|
207 | - // If we reach this, there was not a single provider missing |
|
208 | - return false; |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * Get the list of 2FA providers for the given user |
|
213 | - * |
|
214 | - * @param IUser $user |
|
215 | - * @throws Exception |
|
216 | - */ |
|
217 | - public function getProviderSet(IUser $user): ProviderSet { |
|
218 | - $providerStates = $this->providerRegistry->getProviderStates($user); |
|
219 | - $providers = $this->providerLoader->getProviders($user); |
|
220 | - |
|
221 | - $fixedStates = $this->fixMissingProviderStates($providerStates, $providers, $user); |
|
222 | - $isProviderMissing = $this->isProviderMissing($fixedStates, $providers); |
|
223 | - |
|
224 | - $enabled = array_filter($providers, function (IProvider $provider) use ($fixedStates) { |
|
225 | - return $fixedStates[$provider->getId()]; |
|
226 | - }); |
|
227 | - return new ProviderSet($enabled, $isProviderMissing); |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Verify the given challenge |
|
232 | - * |
|
233 | - * @param string $providerId |
|
234 | - * @param IUser $user |
|
235 | - * @param string $challenge |
|
236 | - * @return boolean |
|
237 | - */ |
|
238 | - public function verifyChallenge(string $providerId, IUser $user, string $challenge): bool { |
|
239 | - $provider = $this->getProvider($user, $providerId); |
|
240 | - if ($provider === null) { |
|
241 | - return false; |
|
242 | - } |
|
243 | - |
|
244 | - $passed = $provider->verifyChallenge($user, $challenge); |
|
245 | - if ($passed) { |
|
246 | - if ($this->session->get(self::REMEMBER_LOGIN) === true) { |
|
247 | - // TODO: resolve cyclic dependency and use DI |
|
248 | - \OC::$server->getUserSession()->createRememberMeToken($user); |
|
249 | - } |
|
250 | - $this->session->remove(self::SESSION_UID_KEY); |
|
251 | - $this->session->remove(self::REMEMBER_LOGIN); |
|
252 | - $this->session->set(self::SESSION_UID_DONE, $user->getUID()); |
|
253 | - |
|
254 | - // Clear token from db |
|
255 | - $sessionId = $this->session->getId(); |
|
256 | - $token = $this->tokenProvider->getToken($sessionId); |
|
257 | - $tokenId = $token->getId(); |
|
258 | - $this->config->deleteUserValue($user->getUID(), 'login_token_2fa', $tokenId); |
|
259 | - |
|
260 | - $dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]); |
|
261 | - $this->dispatcher->dispatch(IProvider::EVENT_SUCCESS, $dispatchEvent); |
|
262 | - |
|
263 | - $this->publishEvent($user, 'twofactor_success', [ |
|
264 | - 'provider' => $provider->getDisplayName(), |
|
265 | - ]); |
|
266 | - } else { |
|
267 | - $dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]); |
|
268 | - $this->dispatcher->dispatch(IProvider::EVENT_FAILED, $dispatchEvent); |
|
269 | - |
|
270 | - $this->publishEvent($user, 'twofactor_failed', [ |
|
271 | - 'provider' => $provider->getDisplayName(), |
|
272 | - ]); |
|
273 | - } |
|
274 | - return $passed; |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Push a 2fa event the user's activity stream |
|
279 | - * |
|
280 | - * @param IUser $user |
|
281 | - * @param string $event |
|
282 | - * @param array $params |
|
283 | - */ |
|
284 | - private function publishEvent(IUser $user, string $event, array $params) { |
|
285 | - $activity = $this->activityManager->generateEvent(); |
|
286 | - $activity->setApp('core') |
|
287 | - ->setType('security') |
|
288 | - ->setAuthor($user->getUID()) |
|
289 | - ->setAffectedUser($user->getUID()) |
|
290 | - ->setSubject($event, $params); |
|
291 | - try { |
|
292 | - $this->activityManager->publish($activity); |
|
293 | - } catch (BadMethodCallException $e) { |
|
294 | - $this->logger->warning('could not publish activity', ['app' => 'core']); |
|
295 | - $this->logger->logException($e, ['app' => 'core']); |
|
296 | - } |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * Check if the currently logged in user needs to pass 2FA |
|
301 | - * |
|
302 | - * @param IUser $user the currently logged in user |
|
303 | - * @return boolean |
|
304 | - */ |
|
305 | - public function needsSecondFactor(IUser $user = null): bool { |
|
306 | - if ($user === null) { |
|
307 | - return false; |
|
308 | - } |
|
309 | - |
|
310 | - // If we are authenticated using an app password skip all this |
|
311 | - if ($this->session->exists('app_password')) { |
|
312 | - return false; |
|
313 | - } |
|
314 | - |
|
315 | - // First check if the session tells us we should do 2FA (99% case) |
|
316 | - if (!$this->session->exists(self::SESSION_UID_KEY)) { |
|
317 | - |
|
318 | - // Check if the session tells us it is 2FA authenticated already |
|
319 | - if ($this->session->exists(self::SESSION_UID_DONE) && |
|
320 | - $this->session->get(self::SESSION_UID_DONE) === $user->getUID()) { |
|
321 | - return false; |
|
322 | - } |
|
323 | - |
|
324 | - /* |
|
47 | + const SESSION_UID_KEY = 'two_factor_auth_uid'; |
|
48 | + const SESSION_UID_DONE = 'two_factor_auth_passed'; |
|
49 | + const REMEMBER_LOGIN = 'two_factor_remember_login'; |
|
50 | + |
|
51 | + /** @var ProviderLoader */ |
|
52 | + private $providerLoader; |
|
53 | + |
|
54 | + /** @var IRegistry */ |
|
55 | + private $providerRegistry; |
|
56 | + |
|
57 | + /** @var ISession */ |
|
58 | + private $session; |
|
59 | + |
|
60 | + /** @var IConfig */ |
|
61 | + private $config; |
|
62 | + |
|
63 | + /** @var IManager */ |
|
64 | + private $activityManager; |
|
65 | + |
|
66 | + /** @var ILogger */ |
|
67 | + private $logger; |
|
68 | + |
|
69 | + /** @var TokenProvider */ |
|
70 | + private $tokenProvider; |
|
71 | + |
|
72 | + /** @var ITimeFactory */ |
|
73 | + private $timeFactory; |
|
74 | + |
|
75 | + /** @var EventDispatcherInterface */ |
|
76 | + private $dispatcher; |
|
77 | + |
|
78 | + public function __construct(ProviderLoader $providerLoader, |
|
79 | + IRegistry $providerRegistry, ISession $session, IConfig $config, |
|
80 | + IManager $activityManager, ILogger $logger, TokenProvider $tokenProvider, |
|
81 | + ITimeFactory $timeFactory, EventDispatcherInterface $eventDispatcher) { |
|
82 | + $this->providerLoader = $providerLoader; |
|
83 | + $this->session = $session; |
|
84 | + $this->config = $config; |
|
85 | + $this->activityManager = $activityManager; |
|
86 | + $this->logger = $logger; |
|
87 | + $this->tokenProvider = $tokenProvider; |
|
88 | + $this->timeFactory = $timeFactory; |
|
89 | + $this->dispatcher = $eventDispatcher; |
|
90 | + $this->providerRegistry = $providerRegistry; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Determine whether the user must provide a second factor challenge |
|
95 | + * |
|
96 | + * @param IUser $user |
|
97 | + * @return boolean |
|
98 | + */ |
|
99 | + public function isTwoFactorAuthenticated(IUser $user): bool { |
|
100 | + $twoFactorEnabled = ((int) $this->config->getUserValue($user->getUID(), 'core', 'two_factor_auth_disabled', 0)) === 0; |
|
101 | + |
|
102 | + if (!$twoFactorEnabled) { |
|
103 | + return false; |
|
104 | + } |
|
105 | + |
|
106 | + $providerStates = $this->providerRegistry->getProviderStates($user); |
|
107 | + $enabled = array_filter($providerStates); |
|
108 | + |
|
109 | + return $twoFactorEnabled && !empty($enabled); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Disable 2FA checks for the given user |
|
114 | + * |
|
115 | + * @param IUser $user |
|
116 | + */ |
|
117 | + public function disableTwoFactorAuthentication(IUser $user) { |
|
118 | + $this->config->setUserValue($user->getUID(), 'core', 'two_factor_auth_disabled', 1); |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Enable all 2FA checks for the given user |
|
123 | + * |
|
124 | + * @param IUser $user |
|
125 | + */ |
|
126 | + public function enableTwoFactorAuthentication(IUser $user) { |
|
127 | + $this->config->deleteUserValue($user->getUID(), 'core', 'two_factor_auth_disabled'); |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Get a 2FA provider by its ID |
|
132 | + * |
|
133 | + * @param IUser $user |
|
134 | + * @param string $challengeProviderId |
|
135 | + * @return IProvider|null |
|
136 | + */ |
|
137 | + public function getProvider(IUser $user, string $challengeProviderId) { |
|
138 | + $providers = $this->getProviderSet($user)->getProviders(); |
|
139 | + return $providers[$challengeProviderId] ?? null; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Check if the persistant mapping of enabled/disabled state of each available |
|
144 | + * provider is missing an entry and add it to the registry in that case. |
|
145 | + * |
|
146 | + * @todo remove in Nextcloud 17 as by then all providers should have been updated |
|
147 | + * |
|
148 | + * @param string[] $providerStates |
|
149 | + * @param IProvider[] $providers |
|
150 | + * @param IUser $user |
|
151 | + * @return string[] the updated $providerStates variable |
|
152 | + */ |
|
153 | + private function fixMissingProviderStates(array $providerStates, |
|
154 | + array $providers, IUser $user): array { |
|
155 | + |
|
156 | + foreach ($providers as $provider) { |
|
157 | + if (isset($providerStates[$provider->getId()])) { |
|
158 | + // All good |
|
159 | + continue; |
|
160 | + } |
|
161 | + |
|
162 | + $enabled = $provider->isTwoFactorAuthEnabledForUser($user); |
|
163 | + if ($enabled) { |
|
164 | + $this->providerRegistry->enableProviderFor($provider, $user); |
|
165 | + } else { |
|
166 | + $this->providerRegistry->disableProviderFor($provider, $user); |
|
167 | + } |
|
168 | + $providerStates[$provider->getId()] = $enabled; |
|
169 | + } |
|
170 | + |
|
171 | + return $providerStates; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * @param array $states |
|
176 | + * @param IProvider $providers |
|
177 | + */ |
|
178 | + private function isProviderMissing(array $states, array $providers): bool { |
|
179 | + $indexed = []; |
|
180 | + foreach ($providers as $provider) { |
|
181 | + $indexed[$provider->getId()] = $provider; |
|
182 | + } |
|
183 | + |
|
184 | + $missing = []; |
|
185 | + foreach ($states as $providerId => $enabled) { |
|
186 | + if (!$enabled) { |
|
187 | + // Don't care |
|
188 | + continue; |
|
189 | + } |
|
190 | + |
|
191 | + if (!isset($indexed[$providerId])) { |
|
192 | + $missing[] = $providerId; |
|
193 | + $this->logger->alert("two-factor auth provider '$providerId' failed to load", |
|
194 | + [ |
|
195 | + 'app' => 'core', |
|
196 | + ]); |
|
197 | + } |
|
198 | + } |
|
199 | + |
|
200 | + if (!empty($missing)) { |
|
201 | + // There was at least one provider missing |
|
202 | + $this->logger->alert(count($missing) . " two-factor auth providers failed to load", ['app' => 'core']); |
|
203 | + |
|
204 | + return true; |
|
205 | + } |
|
206 | + |
|
207 | + // If we reach this, there was not a single provider missing |
|
208 | + return false; |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * Get the list of 2FA providers for the given user |
|
213 | + * |
|
214 | + * @param IUser $user |
|
215 | + * @throws Exception |
|
216 | + */ |
|
217 | + public function getProviderSet(IUser $user): ProviderSet { |
|
218 | + $providerStates = $this->providerRegistry->getProviderStates($user); |
|
219 | + $providers = $this->providerLoader->getProviders($user); |
|
220 | + |
|
221 | + $fixedStates = $this->fixMissingProviderStates($providerStates, $providers, $user); |
|
222 | + $isProviderMissing = $this->isProviderMissing($fixedStates, $providers); |
|
223 | + |
|
224 | + $enabled = array_filter($providers, function (IProvider $provider) use ($fixedStates) { |
|
225 | + return $fixedStates[$provider->getId()]; |
|
226 | + }); |
|
227 | + return new ProviderSet($enabled, $isProviderMissing); |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Verify the given challenge |
|
232 | + * |
|
233 | + * @param string $providerId |
|
234 | + * @param IUser $user |
|
235 | + * @param string $challenge |
|
236 | + * @return boolean |
|
237 | + */ |
|
238 | + public function verifyChallenge(string $providerId, IUser $user, string $challenge): bool { |
|
239 | + $provider = $this->getProvider($user, $providerId); |
|
240 | + if ($provider === null) { |
|
241 | + return false; |
|
242 | + } |
|
243 | + |
|
244 | + $passed = $provider->verifyChallenge($user, $challenge); |
|
245 | + if ($passed) { |
|
246 | + if ($this->session->get(self::REMEMBER_LOGIN) === true) { |
|
247 | + // TODO: resolve cyclic dependency and use DI |
|
248 | + \OC::$server->getUserSession()->createRememberMeToken($user); |
|
249 | + } |
|
250 | + $this->session->remove(self::SESSION_UID_KEY); |
|
251 | + $this->session->remove(self::REMEMBER_LOGIN); |
|
252 | + $this->session->set(self::SESSION_UID_DONE, $user->getUID()); |
|
253 | + |
|
254 | + // Clear token from db |
|
255 | + $sessionId = $this->session->getId(); |
|
256 | + $token = $this->tokenProvider->getToken($sessionId); |
|
257 | + $tokenId = $token->getId(); |
|
258 | + $this->config->deleteUserValue($user->getUID(), 'login_token_2fa', $tokenId); |
|
259 | + |
|
260 | + $dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]); |
|
261 | + $this->dispatcher->dispatch(IProvider::EVENT_SUCCESS, $dispatchEvent); |
|
262 | + |
|
263 | + $this->publishEvent($user, 'twofactor_success', [ |
|
264 | + 'provider' => $provider->getDisplayName(), |
|
265 | + ]); |
|
266 | + } else { |
|
267 | + $dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]); |
|
268 | + $this->dispatcher->dispatch(IProvider::EVENT_FAILED, $dispatchEvent); |
|
269 | + |
|
270 | + $this->publishEvent($user, 'twofactor_failed', [ |
|
271 | + 'provider' => $provider->getDisplayName(), |
|
272 | + ]); |
|
273 | + } |
|
274 | + return $passed; |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Push a 2fa event the user's activity stream |
|
279 | + * |
|
280 | + * @param IUser $user |
|
281 | + * @param string $event |
|
282 | + * @param array $params |
|
283 | + */ |
|
284 | + private function publishEvent(IUser $user, string $event, array $params) { |
|
285 | + $activity = $this->activityManager->generateEvent(); |
|
286 | + $activity->setApp('core') |
|
287 | + ->setType('security') |
|
288 | + ->setAuthor($user->getUID()) |
|
289 | + ->setAffectedUser($user->getUID()) |
|
290 | + ->setSubject($event, $params); |
|
291 | + try { |
|
292 | + $this->activityManager->publish($activity); |
|
293 | + } catch (BadMethodCallException $e) { |
|
294 | + $this->logger->warning('could not publish activity', ['app' => 'core']); |
|
295 | + $this->logger->logException($e, ['app' => 'core']); |
|
296 | + } |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * Check if the currently logged in user needs to pass 2FA |
|
301 | + * |
|
302 | + * @param IUser $user the currently logged in user |
|
303 | + * @return boolean |
|
304 | + */ |
|
305 | + public function needsSecondFactor(IUser $user = null): bool { |
|
306 | + if ($user === null) { |
|
307 | + return false; |
|
308 | + } |
|
309 | + |
|
310 | + // If we are authenticated using an app password skip all this |
|
311 | + if ($this->session->exists('app_password')) { |
|
312 | + return false; |
|
313 | + } |
|
314 | + |
|
315 | + // First check if the session tells us we should do 2FA (99% case) |
|
316 | + if (!$this->session->exists(self::SESSION_UID_KEY)) { |
|
317 | + |
|
318 | + // Check if the session tells us it is 2FA authenticated already |
|
319 | + if ($this->session->exists(self::SESSION_UID_DONE) && |
|
320 | + $this->session->get(self::SESSION_UID_DONE) === $user->getUID()) { |
|
321 | + return false; |
|
322 | + } |
|
323 | + |
|
324 | + /* |
|
325 | 325 | * If the session is expired check if we are not logged in by a token |
326 | 326 | * that still needs 2FA auth |
327 | 327 | */ |
328 | - try { |
|
329 | - $sessionId = $this->session->getId(); |
|
330 | - $token = $this->tokenProvider->getToken($sessionId); |
|
331 | - $tokenId = $token->getId(); |
|
332 | - $tokensNeeding2FA = $this->config->getUserKeys($user->getUID(), 'login_token_2fa'); |
|
333 | - |
|
334 | - if (!\in_array($tokenId, $tokensNeeding2FA, true)) { |
|
335 | - $this->session->set(self::SESSION_UID_DONE, $user->getUID()); |
|
336 | - return false; |
|
337 | - } |
|
338 | - } catch (InvalidTokenException $e) { |
|
339 | - } |
|
340 | - } |
|
341 | - |
|
342 | - if (!$this->isTwoFactorAuthenticated($user)) { |
|
343 | - // There is no second factor any more -> let the user pass |
|
344 | - // This prevents infinite redirect loops when a user is about |
|
345 | - // to solve the 2FA challenge, and the provider app is |
|
346 | - // disabled the same time |
|
347 | - $this->session->remove(self::SESSION_UID_KEY); |
|
348 | - |
|
349 | - $keys = $this->config->getUserKeys($user->getUID(), 'login_token_2fa'); |
|
350 | - foreach ($keys as $key) { |
|
351 | - $this->config->deleteUserValue($user->getUID(), 'login_token_2fa', $key); |
|
352 | - } |
|
353 | - return false; |
|
354 | - } |
|
355 | - |
|
356 | - return true; |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Prepare the 2FA login |
|
361 | - * |
|
362 | - * @param IUser $user |
|
363 | - * @param boolean $rememberMe |
|
364 | - */ |
|
365 | - public function prepareTwoFactorLogin(IUser $user, bool $rememberMe) { |
|
366 | - $this->session->set(self::SESSION_UID_KEY, $user->getUID()); |
|
367 | - $this->session->set(self::REMEMBER_LOGIN, $rememberMe); |
|
368 | - |
|
369 | - $id = $this->session->getId(); |
|
370 | - $token = $this->tokenProvider->getToken($id); |
|
371 | - $this->config->setUserValue($user->getUID(), 'login_token_2fa', $token->getId(), $this->timeFactory->getTime()); |
|
372 | - } |
|
328 | + try { |
|
329 | + $sessionId = $this->session->getId(); |
|
330 | + $token = $this->tokenProvider->getToken($sessionId); |
|
331 | + $tokenId = $token->getId(); |
|
332 | + $tokensNeeding2FA = $this->config->getUserKeys($user->getUID(), 'login_token_2fa'); |
|
333 | + |
|
334 | + if (!\in_array($tokenId, $tokensNeeding2FA, true)) { |
|
335 | + $this->session->set(self::SESSION_UID_DONE, $user->getUID()); |
|
336 | + return false; |
|
337 | + } |
|
338 | + } catch (InvalidTokenException $e) { |
|
339 | + } |
|
340 | + } |
|
341 | + |
|
342 | + if (!$this->isTwoFactorAuthenticated($user)) { |
|
343 | + // There is no second factor any more -> let the user pass |
|
344 | + // This prevents infinite redirect loops when a user is about |
|
345 | + // to solve the 2FA challenge, and the provider app is |
|
346 | + // disabled the same time |
|
347 | + $this->session->remove(self::SESSION_UID_KEY); |
|
348 | + |
|
349 | + $keys = $this->config->getUserKeys($user->getUID(), 'login_token_2fa'); |
|
350 | + foreach ($keys as $key) { |
|
351 | + $this->config->deleteUserValue($user->getUID(), 'login_token_2fa', $key); |
|
352 | + } |
|
353 | + return false; |
|
354 | + } |
|
355 | + |
|
356 | + return true; |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Prepare the 2FA login |
|
361 | + * |
|
362 | + * @param IUser $user |
|
363 | + * @param boolean $rememberMe |
|
364 | + */ |
|
365 | + public function prepareTwoFactorLogin(IUser $user, bool $rememberMe) { |
|
366 | + $this->session->set(self::SESSION_UID_KEY, $user->getUID()); |
|
367 | + $this->session->set(self::REMEMBER_LOGIN, $rememberMe); |
|
368 | + |
|
369 | + $id = $this->session->getId(); |
|
370 | + $token = $this->tokenProvider->getToken($id); |
|
371 | + $this->config->setUserValue($user->getUID(), 'login_token_2fa', $token->getId(), $this->timeFactory->getTime()); |
|
372 | + } |
|
373 | 373 | |
374 | 374 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | /** |
5 | 5 | * @copyright Copyright (c) 2016, ownCloud, Inc. |
6 | 6 | * |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | |
200 | 200 | if (!empty($missing)) { |
201 | 201 | // There was at least one provider missing |
202 | - $this->logger->alert(count($missing) . " two-factor auth providers failed to load", ['app' => 'core']); |
|
202 | + $this->logger->alert(count($missing)." two-factor auth providers failed to load", ['app' => 'core']); |
|
203 | 203 | |
204 | 204 | return true; |
205 | 205 | } |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | $fixedStates = $this->fixMissingProviderStates($providerStates, $providers, $user); |
222 | 222 | $isProviderMissing = $this->isProviderMissing($fixedStates, $providers); |
223 | 223 | |
224 | - $enabled = array_filter($providers, function (IProvider $provider) use ($fixedStates) { |
|
224 | + $enabled = array_filter($providers, function(IProvider $provider) use ($fixedStates) { |
|
225 | 225 | return $fixedStates[$provider->getId()]; |
226 | 226 | }); |
227 | 227 | return new ProviderSet($enabled, $isProviderMissing); |
@@ -58,299 +58,299 @@ |
||
58 | 58 | use OCP\Util; |
59 | 59 | |
60 | 60 | class LoginController extends Controller { |
61 | - /** @var IUserManager */ |
|
62 | - private $userManager; |
|
63 | - /** @var IConfig */ |
|
64 | - private $config; |
|
65 | - /** @var ISession */ |
|
66 | - private $session; |
|
67 | - /** @var IUserSession|Session */ |
|
68 | - private $userSession; |
|
69 | - /** @var IURLGenerator */ |
|
70 | - private $urlGenerator; |
|
71 | - /** @var ILogger */ |
|
72 | - private $logger; |
|
73 | - /** @var Manager */ |
|
74 | - private $twoFactorManager; |
|
75 | - /** @var Defaults */ |
|
76 | - private $defaults; |
|
77 | - /** @var Throttler */ |
|
78 | - private $throttler; |
|
79 | - |
|
80 | - /** |
|
81 | - * @param string $appName |
|
82 | - * @param IRequest $request |
|
83 | - * @param IUserManager $userManager |
|
84 | - * @param IConfig $config |
|
85 | - * @param ISession $session |
|
86 | - * @param IUserSession $userSession |
|
87 | - * @param IURLGenerator $urlGenerator |
|
88 | - * @param ILogger $logger |
|
89 | - * @param Manager $twoFactorManager |
|
90 | - * @param Defaults $defaults |
|
91 | - * @param Throttler $throttler |
|
92 | - */ |
|
93 | - public function __construct($appName, |
|
94 | - IRequest $request, |
|
95 | - IUserManager $userManager, |
|
96 | - IConfig $config, |
|
97 | - ISession $session, |
|
98 | - IUserSession $userSession, |
|
99 | - IURLGenerator $urlGenerator, |
|
100 | - ILogger $logger, |
|
101 | - Manager $twoFactorManager, |
|
102 | - Defaults $defaults, |
|
103 | - Throttler $throttler) { |
|
104 | - parent::__construct($appName, $request); |
|
105 | - $this->userManager = $userManager; |
|
106 | - $this->config = $config; |
|
107 | - $this->session = $session; |
|
108 | - $this->userSession = $userSession; |
|
109 | - $this->urlGenerator = $urlGenerator; |
|
110 | - $this->logger = $logger; |
|
111 | - $this->twoFactorManager = $twoFactorManager; |
|
112 | - $this->defaults = $defaults; |
|
113 | - $this->throttler = $throttler; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * @NoAdminRequired |
|
118 | - * @UseSession |
|
119 | - * |
|
120 | - * @return RedirectResponse |
|
121 | - */ |
|
122 | - public function logout() { |
|
123 | - $loginToken = $this->request->getCookie('nc_token'); |
|
124 | - if (!is_null($loginToken)) { |
|
125 | - $this->config->deleteUserValue($this->userSession->getUser()->getUID(), 'login_token', $loginToken); |
|
126 | - } |
|
127 | - $this->userSession->logout(); |
|
128 | - |
|
129 | - $response = new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm')); |
|
130 | - $response->addHeader('Clear-Site-Data', '"cache", "cookies", "storage", "executionContexts"'); |
|
131 | - return $response; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * @PublicPage |
|
136 | - * @NoCSRFRequired |
|
137 | - * @UseSession |
|
138 | - * |
|
139 | - * @param string $user |
|
140 | - * @param string $redirect_url |
|
141 | - * |
|
142 | - * @return TemplateResponse|RedirectResponse |
|
143 | - */ |
|
144 | - public function showLoginForm(string $user = null, string $redirect_url = null): Http\Response { |
|
145 | - |
|
146 | - if ($this->userSession->isLoggedIn()) { |
|
147 | - return new RedirectResponse(OC_Util::getDefaultPageUrl()); |
|
148 | - } |
|
149 | - |
|
150 | - $parameters = array(); |
|
151 | - $loginMessages = $this->session->get('loginMessages'); |
|
152 | - $errors = []; |
|
153 | - $messages = []; |
|
154 | - if (is_array($loginMessages)) { |
|
155 | - list($errors, $messages) = $loginMessages; |
|
156 | - } |
|
157 | - $this->session->remove('loginMessages'); |
|
158 | - foreach ($errors as $value) { |
|
159 | - $parameters[$value] = true; |
|
160 | - } |
|
161 | - |
|
162 | - $parameters['messages'] = $messages; |
|
163 | - if ($user !== null && $user !== '') { |
|
164 | - $parameters['loginName'] = $user; |
|
165 | - $parameters['user_autofocus'] = false; |
|
166 | - } else { |
|
167 | - $parameters['loginName'] = ''; |
|
168 | - $parameters['user_autofocus'] = true; |
|
169 | - } |
|
170 | - if (!empty($redirect_url)) { |
|
171 | - $parameters['redirect_url'] = $redirect_url; |
|
172 | - } |
|
173 | - |
|
174 | - $parameters['canResetPassword'] = true; |
|
175 | - $parameters['resetPasswordLink'] = $this->config->getSystemValue('lost_password_link', ''); |
|
176 | - if (!$parameters['resetPasswordLink']) { |
|
177 | - if ($user !== null && $user !== '') { |
|
178 | - $userObj = $this->userManager->get($user); |
|
179 | - if ($userObj instanceof IUser) { |
|
180 | - $parameters['canResetPassword'] = $userObj->canChangePassword(); |
|
181 | - } |
|
182 | - } |
|
183 | - } elseif ($parameters['resetPasswordLink'] === 'disabled') { |
|
184 | - $parameters['canResetPassword'] = false; |
|
185 | - } |
|
186 | - |
|
187 | - $parameters['alt_login'] = OC_App::getAlternativeLogIns(); |
|
188 | - |
|
189 | - if ($user !== null && $user !== '') { |
|
190 | - $parameters['loginName'] = $user; |
|
191 | - $parameters['user_autofocus'] = false; |
|
192 | - } else { |
|
193 | - $parameters['loginName'] = ''; |
|
194 | - $parameters['user_autofocus'] = true; |
|
195 | - } |
|
196 | - |
|
197 | - $parameters['throttle_delay'] = $this->throttler->getDelay($this->request->getRemoteAddress()); |
|
198 | - |
|
199 | - // OpenGraph Support: http://ogp.me/ |
|
200 | - Util::addHeader('meta', ['property' => 'og:title', 'content' => Util::sanitizeHTML($this->defaults->getName())]); |
|
201 | - Util::addHeader('meta', ['property' => 'og:description', 'content' => Util::sanitizeHTML($this->defaults->getSlogan())]); |
|
202 | - Util::addHeader('meta', ['property' => 'og:site_name', 'content' => Util::sanitizeHTML($this->defaults->getName())]); |
|
203 | - Util::addHeader('meta', ['property' => 'og:url', 'content' => $this->urlGenerator->getAbsoluteURL('/')]); |
|
204 | - Util::addHeader('meta', ['property' => 'og:type', 'content' => 'website']); |
|
205 | - Util::addHeader('meta', ['property' => 'og:image', 'content' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core','favicon-touch.png'))]); |
|
206 | - |
|
207 | - return new TemplateResponse( |
|
208 | - $this->appName, 'login', $parameters, 'guest' |
|
209 | - ); |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * @param string $redirectUrl |
|
214 | - * @return RedirectResponse |
|
215 | - */ |
|
216 | - private function generateRedirect($redirectUrl) { |
|
217 | - if (!is_null($redirectUrl) && $this->userSession->isLoggedIn()) { |
|
218 | - $location = $this->urlGenerator->getAbsoluteURL(urldecode($redirectUrl)); |
|
219 | - // Deny the redirect if the URL contains a @ |
|
220 | - // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
221 | - if (strpos($location, '@') === false) { |
|
222 | - return new RedirectResponse($location); |
|
223 | - } |
|
224 | - } |
|
225 | - return new RedirectResponse(OC_Util::getDefaultPageUrl()); |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * @PublicPage |
|
230 | - * @UseSession |
|
231 | - * @NoCSRFRequired |
|
232 | - * @BruteForceProtection(action=login) |
|
233 | - * |
|
234 | - * @param string $user |
|
235 | - * @param string $password |
|
236 | - * @param string $redirect_url |
|
237 | - * @param boolean $remember_login |
|
238 | - * @param string $timezone |
|
239 | - * @param string $timezone_offset |
|
240 | - * @return RedirectResponse |
|
241 | - */ |
|
242 | - public function tryLogin($user, $password, $redirect_url, $remember_login = true, $timezone = '', $timezone_offset = '') { |
|
243 | - if(!is_string($user)) { |
|
244 | - throw new \InvalidArgumentException('Username must be string'); |
|
245 | - } |
|
246 | - |
|
247 | - // If the user is already logged in and the CSRF check does not pass then |
|
248 | - // simply redirect the user to the correct page as required. This is the |
|
249 | - // case when an user has already logged-in, in another tab. |
|
250 | - if(!$this->request->passesCSRFCheck()) { |
|
251 | - return $this->generateRedirect($redirect_url); |
|
252 | - } |
|
253 | - |
|
254 | - if ($this->userManager instanceof PublicEmitter) { |
|
255 | - $this->userManager->emit('\OC\User', 'preLogin', array($user, $password)); |
|
256 | - } |
|
257 | - |
|
258 | - $originalUser = $user; |
|
259 | - // TODO: Add all the insane error handling |
|
260 | - /* @var $loginResult IUser */ |
|
261 | - $loginResult = $this->userManager->checkPasswordNoLogging($user, $password); |
|
262 | - if ($loginResult === false) { |
|
263 | - $users = $this->userManager->getByEmail($user); |
|
264 | - // we only allow login by email if unique |
|
265 | - if (count($users) === 1) { |
|
266 | - $previousUser = $user; |
|
267 | - $user = $users[0]->getUID(); |
|
268 | - if($user !== $previousUser) { |
|
269 | - $loginResult = $this->userManager->checkPassword($user, $password); |
|
270 | - } |
|
271 | - } |
|
272 | - } |
|
273 | - if ($loginResult === false) { |
|
274 | - $this->logger->warning('Login failed: \''. $user .'\' (Remote IP: \''. $this->request->getRemoteAddress(). '\')', ['app' => 'core']); |
|
275 | - // Read current user and append if possible - we need to return the unmodified user otherwise we will leak the login name |
|
276 | - $args = !is_null($user) ? ['user' => $originalUser] : []; |
|
277 | - if (!is_null($redirect_url)) { |
|
278 | - $args['redirect_url'] = $redirect_url; |
|
279 | - } |
|
280 | - $response = new RedirectResponse($this->urlGenerator->linkToRoute('core.login.showLoginForm', $args)); |
|
281 | - $response->throttle(['user' => $user]); |
|
282 | - $this->session->set('loginMessages', [ |
|
283 | - ['invalidpassword'], [] |
|
284 | - ]); |
|
285 | - return $response; |
|
286 | - } |
|
287 | - // TODO: remove password checks from above and let the user session handle failures |
|
288 | - // requires https://github.com/owncloud/core/pull/24616 |
|
289 | - $this->userSession->completeLogin($loginResult, ['loginName' => $user, 'password' => $password]); |
|
290 | - $this->userSession->createSessionToken($this->request, $loginResult->getUID(), $user, $password, IToken::REMEMBER); |
|
291 | - |
|
292 | - // User has successfully logged in, now remove the password reset link, when it is available |
|
293 | - $this->config->deleteUserValue($loginResult->getUID(), 'core', 'lostpassword'); |
|
294 | - |
|
295 | - $this->session->set('last-password-confirm', $loginResult->getLastLogin()); |
|
296 | - |
|
297 | - if ($timezone_offset !== '') { |
|
298 | - $this->config->setUserValue($loginResult->getUID(), 'core', 'timezone', $timezone); |
|
299 | - $this->session->set('timezone', $timezone_offset); |
|
300 | - } |
|
301 | - |
|
302 | - if ($this->twoFactorManager->isTwoFactorAuthenticated($loginResult)) { |
|
303 | - $this->twoFactorManager->prepareTwoFactorLogin($loginResult, $remember_login); |
|
304 | - |
|
305 | - $providers = $this->twoFactorManager->getProviderSet($loginResult)->getProviders(); |
|
306 | - if (count($providers) === 1) { |
|
307 | - // Single provider, hence we can redirect to that provider's challenge page directly |
|
308 | - /* @var $provider IProvider */ |
|
309 | - $provider = array_pop($providers); |
|
310 | - $url = 'core.TwoFactorChallenge.showChallenge'; |
|
311 | - $urlParams = [ |
|
312 | - 'challengeProviderId' => $provider->getId(), |
|
313 | - ]; |
|
314 | - } else { |
|
315 | - $url = 'core.TwoFactorChallenge.selectChallenge'; |
|
316 | - $urlParams = []; |
|
317 | - } |
|
318 | - |
|
319 | - if (!is_null($redirect_url)) { |
|
320 | - $urlParams['redirect_url'] = $redirect_url; |
|
321 | - } |
|
322 | - |
|
323 | - return new RedirectResponse($this->urlGenerator->linkToRoute($url, $urlParams)); |
|
324 | - } |
|
325 | - |
|
326 | - if ($remember_login) { |
|
327 | - $this->userSession->createRememberMeToken($loginResult); |
|
328 | - } |
|
329 | - |
|
330 | - return $this->generateRedirect($redirect_url); |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * @NoAdminRequired |
|
335 | - * @UseSession |
|
336 | - * @BruteForceProtection(action=sudo) |
|
337 | - * |
|
338 | - * @license GNU AGPL version 3 or any later version |
|
339 | - * |
|
340 | - * @param string $password |
|
341 | - * @return DataResponse |
|
342 | - */ |
|
343 | - public function confirmPassword($password) { |
|
344 | - $loginName = $this->userSession->getLoginName(); |
|
345 | - $loginResult = $this->userManager->checkPassword($loginName, $password); |
|
346 | - if ($loginResult === false) { |
|
347 | - $response = new DataResponse([], Http::STATUS_FORBIDDEN); |
|
348 | - $response->throttle(); |
|
349 | - return $response; |
|
350 | - } |
|
351 | - |
|
352 | - $confirmTimestamp = time(); |
|
353 | - $this->session->set('last-password-confirm', $confirmTimestamp); |
|
354 | - return new DataResponse(['lastLogin' => $confirmTimestamp], Http::STATUS_OK); |
|
355 | - } |
|
61 | + /** @var IUserManager */ |
|
62 | + private $userManager; |
|
63 | + /** @var IConfig */ |
|
64 | + private $config; |
|
65 | + /** @var ISession */ |
|
66 | + private $session; |
|
67 | + /** @var IUserSession|Session */ |
|
68 | + private $userSession; |
|
69 | + /** @var IURLGenerator */ |
|
70 | + private $urlGenerator; |
|
71 | + /** @var ILogger */ |
|
72 | + private $logger; |
|
73 | + /** @var Manager */ |
|
74 | + private $twoFactorManager; |
|
75 | + /** @var Defaults */ |
|
76 | + private $defaults; |
|
77 | + /** @var Throttler */ |
|
78 | + private $throttler; |
|
79 | + |
|
80 | + /** |
|
81 | + * @param string $appName |
|
82 | + * @param IRequest $request |
|
83 | + * @param IUserManager $userManager |
|
84 | + * @param IConfig $config |
|
85 | + * @param ISession $session |
|
86 | + * @param IUserSession $userSession |
|
87 | + * @param IURLGenerator $urlGenerator |
|
88 | + * @param ILogger $logger |
|
89 | + * @param Manager $twoFactorManager |
|
90 | + * @param Defaults $defaults |
|
91 | + * @param Throttler $throttler |
|
92 | + */ |
|
93 | + public function __construct($appName, |
|
94 | + IRequest $request, |
|
95 | + IUserManager $userManager, |
|
96 | + IConfig $config, |
|
97 | + ISession $session, |
|
98 | + IUserSession $userSession, |
|
99 | + IURLGenerator $urlGenerator, |
|
100 | + ILogger $logger, |
|
101 | + Manager $twoFactorManager, |
|
102 | + Defaults $defaults, |
|
103 | + Throttler $throttler) { |
|
104 | + parent::__construct($appName, $request); |
|
105 | + $this->userManager = $userManager; |
|
106 | + $this->config = $config; |
|
107 | + $this->session = $session; |
|
108 | + $this->userSession = $userSession; |
|
109 | + $this->urlGenerator = $urlGenerator; |
|
110 | + $this->logger = $logger; |
|
111 | + $this->twoFactorManager = $twoFactorManager; |
|
112 | + $this->defaults = $defaults; |
|
113 | + $this->throttler = $throttler; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * @NoAdminRequired |
|
118 | + * @UseSession |
|
119 | + * |
|
120 | + * @return RedirectResponse |
|
121 | + */ |
|
122 | + public function logout() { |
|
123 | + $loginToken = $this->request->getCookie('nc_token'); |
|
124 | + if (!is_null($loginToken)) { |
|
125 | + $this->config->deleteUserValue($this->userSession->getUser()->getUID(), 'login_token', $loginToken); |
|
126 | + } |
|
127 | + $this->userSession->logout(); |
|
128 | + |
|
129 | + $response = new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm')); |
|
130 | + $response->addHeader('Clear-Site-Data', '"cache", "cookies", "storage", "executionContexts"'); |
|
131 | + return $response; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * @PublicPage |
|
136 | + * @NoCSRFRequired |
|
137 | + * @UseSession |
|
138 | + * |
|
139 | + * @param string $user |
|
140 | + * @param string $redirect_url |
|
141 | + * |
|
142 | + * @return TemplateResponse|RedirectResponse |
|
143 | + */ |
|
144 | + public function showLoginForm(string $user = null, string $redirect_url = null): Http\Response { |
|
145 | + |
|
146 | + if ($this->userSession->isLoggedIn()) { |
|
147 | + return new RedirectResponse(OC_Util::getDefaultPageUrl()); |
|
148 | + } |
|
149 | + |
|
150 | + $parameters = array(); |
|
151 | + $loginMessages = $this->session->get('loginMessages'); |
|
152 | + $errors = []; |
|
153 | + $messages = []; |
|
154 | + if (is_array($loginMessages)) { |
|
155 | + list($errors, $messages) = $loginMessages; |
|
156 | + } |
|
157 | + $this->session->remove('loginMessages'); |
|
158 | + foreach ($errors as $value) { |
|
159 | + $parameters[$value] = true; |
|
160 | + } |
|
161 | + |
|
162 | + $parameters['messages'] = $messages; |
|
163 | + if ($user !== null && $user !== '') { |
|
164 | + $parameters['loginName'] = $user; |
|
165 | + $parameters['user_autofocus'] = false; |
|
166 | + } else { |
|
167 | + $parameters['loginName'] = ''; |
|
168 | + $parameters['user_autofocus'] = true; |
|
169 | + } |
|
170 | + if (!empty($redirect_url)) { |
|
171 | + $parameters['redirect_url'] = $redirect_url; |
|
172 | + } |
|
173 | + |
|
174 | + $parameters['canResetPassword'] = true; |
|
175 | + $parameters['resetPasswordLink'] = $this->config->getSystemValue('lost_password_link', ''); |
|
176 | + if (!$parameters['resetPasswordLink']) { |
|
177 | + if ($user !== null && $user !== '') { |
|
178 | + $userObj = $this->userManager->get($user); |
|
179 | + if ($userObj instanceof IUser) { |
|
180 | + $parameters['canResetPassword'] = $userObj->canChangePassword(); |
|
181 | + } |
|
182 | + } |
|
183 | + } elseif ($parameters['resetPasswordLink'] === 'disabled') { |
|
184 | + $parameters['canResetPassword'] = false; |
|
185 | + } |
|
186 | + |
|
187 | + $parameters['alt_login'] = OC_App::getAlternativeLogIns(); |
|
188 | + |
|
189 | + if ($user !== null && $user !== '') { |
|
190 | + $parameters['loginName'] = $user; |
|
191 | + $parameters['user_autofocus'] = false; |
|
192 | + } else { |
|
193 | + $parameters['loginName'] = ''; |
|
194 | + $parameters['user_autofocus'] = true; |
|
195 | + } |
|
196 | + |
|
197 | + $parameters['throttle_delay'] = $this->throttler->getDelay($this->request->getRemoteAddress()); |
|
198 | + |
|
199 | + // OpenGraph Support: http://ogp.me/ |
|
200 | + Util::addHeader('meta', ['property' => 'og:title', 'content' => Util::sanitizeHTML($this->defaults->getName())]); |
|
201 | + Util::addHeader('meta', ['property' => 'og:description', 'content' => Util::sanitizeHTML($this->defaults->getSlogan())]); |
|
202 | + Util::addHeader('meta', ['property' => 'og:site_name', 'content' => Util::sanitizeHTML($this->defaults->getName())]); |
|
203 | + Util::addHeader('meta', ['property' => 'og:url', 'content' => $this->urlGenerator->getAbsoluteURL('/')]); |
|
204 | + Util::addHeader('meta', ['property' => 'og:type', 'content' => 'website']); |
|
205 | + Util::addHeader('meta', ['property' => 'og:image', 'content' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core','favicon-touch.png'))]); |
|
206 | + |
|
207 | + return new TemplateResponse( |
|
208 | + $this->appName, 'login', $parameters, 'guest' |
|
209 | + ); |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * @param string $redirectUrl |
|
214 | + * @return RedirectResponse |
|
215 | + */ |
|
216 | + private function generateRedirect($redirectUrl) { |
|
217 | + if (!is_null($redirectUrl) && $this->userSession->isLoggedIn()) { |
|
218 | + $location = $this->urlGenerator->getAbsoluteURL(urldecode($redirectUrl)); |
|
219 | + // Deny the redirect if the URL contains a @ |
|
220 | + // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
221 | + if (strpos($location, '@') === false) { |
|
222 | + return new RedirectResponse($location); |
|
223 | + } |
|
224 | + } |
|
225 | + return new RedirectResponse(OC_Util::getDefaultPageUrl()); |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * @PublicPage |
|
230 | + * @UseSession |
|
231 | + * @NoCSRFRequired |
|
232 | + * @BruteForceProtection(action=login) |
|
233 | + * |
|
234 | + * @param string $user |
|
235 | + * @param string $password |
|
236 | + * @param string $redirect_url |
|
237 | + * @param boolean $remember_login |
|
238 | + * @param string $timezone |
|
239 | + * @param string $timezone_offset |
|
240 | + * @return RedirectResponse |
|
241 | + */ |
|
242 | + public function tryLogin($user, $password, $redirect_url, $remember_login = true, $timezone = '', $timezone_offset = '') { |
|
243 | + if(!is_string($user)) { |
|
244 | + throw new \InvalidArgumentException('Username must be string'); |
|
245 | + } |
|
246 | + |
|
247 | + // If the user is already logged in and the CSRF check does not pass then |
|
248 | + // simply redirect the user to the correct page as required. This is the |
|
249 | + // case when an user has already logged-in, in another tab. |
|
250 | + if(!$this->request->passesCSRFCheck()) { |
|
251 | + return $this->generateRedirect($redirect_url); |
|
252 | + } |
|
253 | + |
|
254 | + if ($this->userManager instanceof PublicEmitter) { |
|
255 | + $this->userManager->emit('\OC\User', 'preLogin', array($user, $password)); |
|
256 | + } |
|
257 | + |
|
258 | + $originalUser = $user; |
|
259 | + // TODO: Add all the insane error handling |
|
260 | + /* @var $loginResult IUser */ |
|
261 | + $loginResult = $this->userManager->checkPasswordNoLogging($user, $password); |
|
262 | + if ($loginResult === false) { |
|
263 | + $users = $this->userManager->getByEmail($user); |
|
264 | + // we only allow login by email if unique |
|
265 | + if (count($users) === 1) { |
|
266 | + $previousUser = $user; |
|
267 | + $user = $users[0]->getUID(); |
|
268 | + if($user !== $previousUser) { |
|
269 | + $loginResult = $this->userManager->checkPassword($user, $password); |
|
270 | + } |
|
271 | + } |
|
272 | + } |
|
273 | + if ($loginResult === false) { |
|
274 | + $this->logger->warning('Login failed: \''. $user .'\' (Remote IP: \''. $this->request->getRemoteAddress(). '\')', ['app' => 'core']); |
|
275 | + // Read current user and append if possible - we need to return the unmodified user otherwise we will leak the login name |
|
276 | + $args = !is_null($user) ? ['user' => $originalUser] : []; |
|
277 | + if (!is_null($redirect_url)) { |
|
278 | + $args['redirect_url'] = $redirect_url; |
|
279 | + } |
|
280 | + $response = new RedirectResponse($this->urlGenerator->linkToRoute('core.login.showLoginForm', $args)); |
|
281 | + $response->throttle(['user' => $user]); |
|
282 | + $this->session->set('loginMessages', [ |
|
283 | + ['invalidpassword'], [] |
|
284 | + ]); |
|
285 | + return $response; |
|
286 | + } |
|
287 | + // TODO: remove password checks from above and let the user session handle failures |
|
288 | + // requires https://github.com/owncloud/core/pull/24616 |
|
289 | + $this->userSession->completeLogin($loginResult, ['loginName' => $user, 'password' => $password]); |
|
290 | + $this->userSession->createSessionToken($this->request, $loginResult->getUID(), $user, $password, IToken::REMEMBER); |
|
291 | + |
|
292 | + // User has successfully logged in, now remove the password reset link, when it is available |
|
293 | + $this->config->deleteUserValue($loginResult->getUID(), 'core', 'lostpassword'); |
|
294 | + |
|
295 | + $this->session->set('last-password-confirm', $loginResult->getLastLogin()); |
|
296 | + |
|
297 | + if ($timezone_offset !== '') { |
|
298 | + $this->config->setUserValue($loginResult->getUID(), 'core', 'timezone', $timezone); |
|
299 | + $this->session->set('timezone', $timezone_offset); |
|
300 | + } |
|
301 | + |
|
302 | + if ($this->twoFactorManager->isTwoFactorAuthenticated($loginResult)) { |
|
303 | + $this->twoFactorManager->prepareTwoFactorLogin($loginResult, $remember_login); |
|
304 | + |
|
305 | + $providers = $this->twoFactorManager->getProviderSet($loginResult)->getProviders(); |
|
306 | + if (count($providers) === 1) { |
|
307 | + // Single provider, hence we can redirect to that provider's challenge page directly |
|
308 | + /* @var $provider IProvider */ |
|
309 | + $provider = array_pop($providers); |
|
310 | + $url = 'core.TwoFactorChallenge.showChallenge'; |
|
311 | + $urlParams = [ |
|
312 | + 'challengeProviderId' => $provider->getId(), |
|
313 | + ]; |
|
314 | + } else { |
|
315 | + $url = 'core.TwoFactorChallenge.selectChallenge'; |
|
316 | + $urlParams = []; |
|
317 | + } |
|
318 | + |
|
319 | + if (!is_null($redirect_url)) { |
|
320 | + $urlParams['redirect_url'] = $redirect_url; |
|
321 | + } |
|
322 | + |
|
323 | + return new RedirectResponse($this->urlGenerator->linkToRoute($url, $urlParams)); |
|
324 | + } |
|
325 | + |
|
326 | + if ($remember_login) { |
|
327 | + $this->userSession->createRememberMeToken($loginResult); |
|
328 | + } |
|
329 | + |
|
330 | + return $this->generateRedirect($redirect_url); |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * @NoAdminRequired |
|
335 | + * @UseSession |
|
336 | + * @BruteForceProtection(action=sudo) |
|
337 | + * |
|
338 | + * @license GNU AGPL version 3 or any later version |
|
339 | + * |
|
340 | + * @param string $password |
|
341 | + * @return DataResponse |
|
342 | + */ |
|
343 | + public function confirmPassword($password) { |
|
344 | + $loginName = $this->userSession->getLoginName(); |
|
345 | + $loginResult = $this->userManager->checkPassword($loginName, $password); |
|
346 | + if ($loginResult === false) { |
|
347 | + $response = new DataResponse([], Http::STATUS_FORBIDDEN); |
|
348 | + $response->throttle(); |
|
349 | + return $response; |
|
350 | + } |
|
351 | + |
|
352 | + $confirmTimestamp = time(); |
|
353 | + $this->session->set('last-password-confirm', $confirmTimestamp); |
|
354 | + return new DataResponse(['lastLogin' => $confirmTimestamp], Http::STATUS_OK); |
|
355 | + } |
|
356 | 356 | } |
@@ -35,76 +35,76 @@ |
||
35 | 35 | |
36 | 36 | class State extends Base { |
37 | 37 | |
38 | - /** @var IRegistry */ |
|
39 | - private $registry; |
|
40 | - |
|
41 | - /** @var IUserManager */ |
|
42 | - private $userManager; |
|
43 | - |
|
44 | - public function __construct(IRegistry $registry, IUserManager $userManager) { |
|
45 | - parent::__construct('twofactorauth:state'); |
|
46 | - |
|
47 | - $this->registry = $registry; |
|
48 | - $this->userManager = $userManager; |
|
49 | - } |
|
50 | - |
|
51 | - protected function configure() { |
|
52 | - parent::configure(); |
|
53 | - |
|
54 | - $this->setName('twofactorauth:state'); |
|
55 | - $this->setDescription('Get the two-factor authentication (2FA) state of a user'); |
|
56 | - $this->addArgument('uid', InputArgument::REQUIRED); |
|
57 | - } |
|
58 | - |
|
59 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
60 | - $uid = $input->getArgument('uid'); |
|
61 | - $user = $this->userManager->get($uid); |
|
62 | - if (is_null($user)) { |
|
63 | - $output->writeln("<error>Invalid UID</error>"); |
|
64 | - return; |
|
65 | - } |
|
66 | - |
|
67 | - $providerStates = $this->registry->getProviderStates($user); |
|
68 | - $filtered = $this->filterEnabledDisabledUnknownProviders($providerStates); |
|
69 | - list ($enabled, $disabled) = $filtered; |
|
70 | - |
|
71 | - if (!empty($enabled)) { |
|
72 | - $output->writeln("Two-factor authentication is enabled for user $uid"); |
|
73 | - } else { |
|
74 | - $output->writeln("Two-factor authentication is not enabled for user $uid"); |
|
75 | - } |
|
76 | - |
|
77 | - $output->writeln(""); |
|
78 | - $this->printProviders("Enabled providers", $enabled, $output); |
|
79 | - $this->printProviders("Disabled providers", $disabled, $output); |
|
80 | - } |
|
81 | - |
|
82 | - private function filterEnabledDisabledUnknownProviders(array $providerStates): array { |
|
83 | - $enabled = []; |
|
84 | - $disabled = []; |
|
85 | - |
|
86 | - foreach ($providerStates as $providerId => $isEnabled) { |
|
87 | - if ($isEnabled) { |
|
88 | - $enabled[] = $providerId; |
|
89 | - } else { |
|
90 | - $disabled[] = $providerId; |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - return [$enabled, $disabled]; |
|
95 | - } |
|
96 | - |
|
97 | - private function printProviders(string $title, array $providers, |
|
98 | - OutputInterface $output) { |
|
99 | - if (empty($providers)) { |
|
100 | - // Ignore and don't print anything |
|
101 | - return; |
|
102 | - } |
|
103 | - |
|
104 | - $output->writeln($title . ":"); |
|
105 | - foreach ($providers as $provider) { |
|
106 | - $output->writeln("- " . $provider); |
|
107 | - } |
|
108 | - } |
|
38 | + /** @var IRegistry */ |
|
39 | + private $registry; |
|
40 | + |
|
41 | + /** @var IUserManager */ |
|
42 | + private $userManager; |
|
43 | + |
|
44 | + public function __construct(IRegistry $registry, IUserManager $userManager) { |
|
45 | + parent::__construct('twofactorauth:state'); |
|
46 | + |
|
47 | + $this->registry = $registry; |
|
48 | + $this->userManager = $userManager; |
|
49 | + } |
|
50 | + |
|
51 | + protected function configure() { |
|
52 | + parent::configure(); |
|
53 | + |
|
54 | + $this->setName('twofactorauth:state'); |
|
55 | + $this->setDescription('Get the two-factor authentication (2FA) state of a user'); |
|
56 | + $this->addArgument('uid', InputArgument::REQUIRED); |
|
57 | + } |
|
58 | + |
|
59 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
60 | + $uid = $input->getArgument('uid'); |
|
61 | + $user = $this->userManager->get($uid); |
|
62 | + if (is_null($user)) { |
|
63 | + $output->writeln("<error>Invalid UID</error>"); |
|
64 | + return; |
|
65 | + } |
|
66 | + |
|
67 | + $providerStates = $this->registry->getProviderStates($user); |
|
68 | + $filtered = $this->filterEnabledDisabledUnknownProviders($providerStates); |
|
69 | + list ($enabled, $disabled) = $filtered; |
|
70 | + |
|
71 | + if (!empty($enabled)) { |
|
72 | + $output->writeln("Two-factor authentication is enabled for user $uid"); |
|
73 | + } else { |
|
74 | + $output->writeln("Two-factor authentication is not enabled for user $uid"); |
|
75 | + } |
|
76 | + |
|
77 | + $output->writeln(""); |
|
78 | + $this->printProviders("Enabled providers", $enabled, $output); |
|
79 | + $this->printProviders("Disabled providers", $disabled, $output); |
|
80 | + } |
|
81 | + |
|
82 | + private function filterEnabledDisabledUnknownProviders(array $providerStates): array { |
|
83 | + $enabled = []; |
|
84 | + $disabled = []; |
|
85 | + |
|
86 | + foreach ($providerStates as $providerId => $isEnabled) { |
|
87 | + if ($isEnabled) { |
|
88 | + $enabled[] = $providerId; |
|
89 | + } else { |
|
90 | + $disabled[] = $providerId; |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + return [$enabled, $disabled]; |
|
95 | + } |
|
96 | + |
|
97 | + private function printProviders(string $title, array $providers, |
|
98 | + OutputInterface $output) { |
|
99 | + if (empty($providers)) { |
|
100 | + // Ignore and don't print anything |
|
101 | + return; |
|
102 | + } |
|
103 | + |
|
104 | + $output->writeln($title . ":"); |
|
105 | + foreach ($providers as $provider) { |
|
106 | + $output->writeln("- " . $provider); |
|
107 | + } |
|
108 | + } |
|
109 | 109 | |
110 | 110 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | /** |
6 | 6 | * @copyright 2018 Christoph Wurst <[email protected]> |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | return; |
102 | 102 | } |
103 | 103 | |
104 | - $output->writeln($title . ":"); |
|
104 | + $output->writeln($title.":"); |
|
105 | 105 | foreach ($providers as $provider) { |
106 | - $output->writeln("- " . $provider); |
|
106 | + $output->writeln("- ".$provider); |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 |
@@ -43,124 +43,124 @@ |
||
43 | 43 | $application->add(new OC\Core\Command\App\CheckCode()); |
44 | 44 | $application->add(new OC\Core\Command\L10n\CreateJs()); |
45 | 45 | $application->add(new \OC\Core\Command\Integrity\SignApp( |
46 | - \OC::$server->getIntegrityCodeChecker(), |
|
47 | - new \OC\IntegrityCheck\Helpers\FileAccessHelper(), |
|
48 | - \OC::$server->getURLGenerator() |
|
46 | + \OC::$server->getIntegrityCodeChecker(), |
|
47 | + new \OC\IntegrityCheck\Helpers\FileAccessHelper(), |
|
48 | + \OC::$server->getURLGenerator() |
|
49 | 49 | )); |
50 | 50 | $application->add(new \OC\Core\Command\Integrity\SignCore( |
51 | - \OC::$server->getIntegrityCodeChecker(), |
|
52 | - new \OC\IntegrityCheck\Helpers\FileAccessHelper() |
|
51 | + \OC::$server->getIntegrityCodeChecker(), |
|
52 | + new \OC\IntegrityCheck\Helpers\FileAccessHelper() |
|
53 | 53 | )); |
54 | 54 | $application->add(new \OC\Core\Command\Integrity\CheckApp( |
55 | - \OC::$server->getIntegrityCodeChecker() |
|
55 | + \OC::$server->getIntegrityCodeChecker() |
|
56 | 56 | )); |
57 | 57 | $application->add(new \OC\Core\Command\Integrity\CheckCore( |
58 | - \OC::$server->getIntegrityCodeChecker() |
|
58 | + \OC::$server->getIntegrityCodeChecker() |
|
59 | 59 | )); |
60 | 60 | |
61 | 61 | |
62 | 62 | if (\OC::$server->getConfig()->getSystemValue('installed', false)) { |
63 | - $application->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager())); |
|
64 | - $application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager())); |
|
65 | - $application->add(new OC\Core\Command\App\Install()); |
|
66 | - $application->add(new OC\Core\Command\App\GetPath()); |
|
67 | - $application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager())); |
|
63 | + $application->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager())); |
|
64 | + $application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager())); |
|
65 | + $application->add(new OC\Core\Command\App\Install()); |
|
66 | + $application->add(new OC\Core\Command\App\GetPath()); |
|
67 | + $application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager())); |
|
68 | 68 | |
69 | - $application->add(new OC\Core\Command\TwoFactorAuth\Enable( |
|
70 | - \OC::$server->getTwoFactorAuthManager(), \OC::$server->getUserManager() |
|
71 | - )); |
|
72 | - $application->add(new OC\Core\Command\TwoFactorAuth\Disable( |
|
73 | - \OC::$server->getTwoFactorAuthManager(), \OC::$server->getUserManager() |
|
74 | - )); |
|
75 | - $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\State::class)); |
|
69 | + $application->add(new OC\Core\Command\TwoFactorAuth\Enable( |
|
70 | + \OC::$server->getTwoFactorAuthManager(), \OC::$server->getUserManager() |
|
71 | + )); |
|
72 | + $application->add(new OC\Core\Command\TwoFactorAuth\Disable( |
|
73 | + \OC::$server->getTwoFactorAuthManager(), \OC::$server->getUserManager() |
|
74 | + )); |
|
75 | + $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\State::class)); |
|
76 | 76 | |
77 | - $application->add(new OC\Core\Command\Background\Cron(\OC::$server->getConfig())); |
|
78 | - $application->add(new OC\Core\Command\Background\WebCron(\OC::$server->getConfig())); |
|
79 | - $application->add(new OC\Core\Command\Background\Ajax(\OC::$server->getConfig())); |
|
77 | + $application->add(new OC\Core\Command\Background\Cron(\OC::$server->getConfig())); |
|
78 | + $application->add(new OC\Core\Command\Background\WebCron(\OC::$server->getConfig())); |
|
79 | + $application->add(new OC\Core\Command\Background\Ajax(\OC::$server->getConfig())); |
|
80 | 80 | |
81 | - $application->add(new OC\Core\Command\Config\App\DeleteConfig(\OC::$server->getConfig())); |
|
82 | - $application->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig())); |
|
83 | - $application->add(new OC\Core\Command\Config\App\SetConfig(\OC::$server->getConfig())); |
|
84 | - $application->add(new OC\Core\Command\Config\Import(\OC::$server->getConfig())); |
|
85 | - $application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig())); |
|
86 | - $application->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->getSystemConfig())); |
|
87 | - $application->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->getSystemConfig())); |
|
88 | - $application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig())); |
|
81 | + $application->add(new OC\Core\Command\Config\App\DeleteConfig(\OC::$server->getConfig())); |
|
82 | + $application->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig())); |
|
83 | + $application->add(new OC\Core\Command\Config\App\SetConfig(\OC::$server->getConfig())); |
|
84 | + $application->add(new OC\Core\Command\Config\Import(\OC::$server->getConfig())); |
|
85 | + $application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig())); |
|
86 | + $application->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->getSystemConfig())); |
|
87 | + $application->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->getSystemConfig())); |
|
88 | + $application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig())); |
|
89 | 89 | |
90 | - $application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig()))); |
|
91 | - $application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->getLogger())); |
|
92 | - $application->add(new OC\Core\Command\Db\ConvertFilecacheBigInt(\OC::$server->getDatabaseConnection())); |
|
93 | - $application->add(new OC\Core\Command\Db\AddMissingIndices(\OC::$server->getDatabaseConnection(), \OC::$server->getEventDispatcher())); |
|
94 | - $application->add(new OC\Core\Command\Db\Migrations\StatusCommand(\OC::$server->getDatabaseConnection())); |
|
95 | - $application->add(new OC\Core\Command\Db\Migrations\MigrateCommand(\OC::$server->getDatabaseConnection())); |
|
96 | - $application->add(new OC\Core\Command\Db\Migrations\GenerateCommand(\OC::$server->getDatabaseConnection(), \OC::$server->getAppManager())); |
|
97 | - $application->add(new OC\Core\Command\Db\Migrations\GenerateFromSchemaFileCommand(\OC::$server->getConfig(), \OC::$server->getAppManager(), \OC::$server->getDatabaseConnection())); |
|
98 | - $application->add(new OC\Core\Command\Db\Migrations\ExecuteCommand(\OC::$server->getDatabaseConnection(), \OC::$server->getAppManager(), \OC::$server->getConfig())); |
|
90 | + $application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig()))); |
|
91 | + $application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->getLogger())); |
|
92 | + $application->add(new OC\Core\Command\Db\ConvertFilecacheBigInt(\OC::$server->getDatabaseConnection())); |
|
93 | + $application->add(new OC\Core\Command\Db\AddMissingIndices(\OC::$server->getDatabaseConnection(), \OC::$server->getEventDispatcher())); |
|
94 | + $application->add(new OC\Core\Command\Db\Migrations\StatusCommand(\OC::$server->getDatabaseConnection())); |
|
95 | + $application->add(new OC\Core\Command\Db\Migrations\MigrateCommand(\OC::$server->getDatabaseConnection())); |
|
96 | + $application->add(new OC\Core\Command\Db\Migrations\GenerateCommand(\OC::$server->getDatabaseConnection(), \OC::$server->getAppManager())); |
|
97 | + $application->add(new OC\Core\Command\Db\Migrations\GenerateFromSchemaFileCommand(\OC::$server->getConfig(), \OC::$server->getAppManager(), \OC::$server->getDatabaseConnection())); |
|
98 | + $application->add(new OC\Core\Command\Db\Migrations\ExecuteCommand(\OC::$server->getDatabaseConnection(), \OC::$server->getAppManager(), \OC::$server->getConfig())); |
|
99 | 99 | |
100 | - $application->add(new OC\Core\Command\Encryption\Disable(\OC::$server->getConfig())); |
|
101 | - $application->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig(), \OC::$server->getEncryptionManager())); |
|
102 | - $application->add(new OC\Core\Command\Encryption\ListModules(\OC::$server->getEncryptionManager())); |
|
103 | - $application->add(new OC\Core\Command\Encryption\SetDefaultModule(\OC::$server->getEncryptionManager())); |
|
104 | - $application->add(new OC\Core\Command\Encryption\Status(\OC::$server->getEncryptionManager())); |
|
105 | - $application->add(new OC\Core\Command\Encryption\EncryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getAppManager(), \OC::$server->getConfig(), new \Symfony\Component\Console\Helper\QuestionHelper())); |
|
106 | - $application->add(new OC\Core\Command\Encryption\DecryptAll( |
|
107 | - \OC::$server->getEncryptionManager(), |
|
108 | - \OC::$server->getAppManager(), |
|
109 | - \OC::$server->getConfig(), |
|
110 | - new \OC\Encryption\DecryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getUserManager(), new \OC\Files\View()), |
|
111 | - new \Symfony\Component\Console\Helper\QuestionHelper()) |
|
112 | - ); |
|
100 | + $application->add(new OC\Core\Command\Encryption\Disable(\OC::$server->getConfig())); |
|
101 | + $application->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig(), \OC::$server->getEncryptionManager())); |
|
102 | + $application->add(new OC\Core\Command\Encryption\ListModules(\OC::$server->getEncryptionManager())); |
|
103 | + $application->add(new OC\Core\Command\Encryption\SetDefaultModule(\OC::$server->getEncryptionManager())); |
|
104 | + $application->add(new OC\Core\Command\Encryption\Status(\OC::$server->getEncryptionManager())); |
|
105 | + $application->add(new OC\Core\Command\Encryption\EncryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getAppManager(), \OC::$server->getConfig(), new \Symfony\Component\Console\Helper\QuestionHelper())); |
|
106 | + $application->add(new OC\Core\Command\Encryption\DecryptAll( |
|
107 | + \OC::$server->getEncryptionManager(), |
|
108 | + \OC::$server->getAppManager(), |
|
109 | + \OC::$server->getConfig(), |
|
110 | + new \OC\Encryption\DecryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getUserManager(), new \OC\Files\View()), |
|
111 | + new \Symfony\Component\Console\Helper\QuestionHelper()) |
|
112 | + ); |
|
113 | 113 | |
114 | - $application->add(new OC\Core\Command\Log\Manage(\OC::$server->getConfig())); |
|
115 | - $application->add(new OC\Core\Command\Log\File(\OC::$server->getConfig())); |
|
114 | + $application->add(new OC\Core\Command\Log\Manage(\OC::$server->getConfig())); |
|
115 | + $application->add(new OC\Core\Command\Log\File(\OC::$server->getConfig())); |
|
116 | 116 | |
117 | - $view = new \OC\Files\View(); |
|
118 | - $util = new \OC\Encryption\Util( |
|
119 | - $view, |
|
120 | - \OC::$server->getUserManager(), |
|
121 | - \OC::$server->getGroupManager(), |
|
122 | - \OC::$server->getConfig() |
|
123 | - ); |
|
124 | - $application->add(new OC\Core\Command\Encryption\ChangeKeyStorageRoot( |
|
125 | - $view, |
|
126 | - \OC::$server->getUserManager(), |
|
127 | - \OC::$server->getConfig(), |
|
128 | - $util, |
|
129 | - new \Symfony\Component\Console\Helper\QuestionHelper() |
|
130 | - ) |
|
131 | - ); |
|
132 | - $application->add(new OC\Core\Command\Encryption\ShowKeyStorageRoot($util)); |
|
117 | + $view = new \OC\Files\View(); |
|
118 | + $util = new \OC\Encryption\Util( |
|
119 | + $view, |
|
120 | + \OC::$server->getUserManager(), |
|
121 | + \OC::$server->getGroupManager(), |
|
122 | + \OC::$server->getConfig() |
|
123 | + ); |
|
124 | + $application->add(new OC\Core\Command\Encryption\ChangeKeyStorageRoot( |
|
125 | + $view, |
|
126 | + \OC::$server->getUserManager(), |
|
127 | + \OC::$server->getConfig(), |
|
128 | + $util, |
|
129 | + new \Symfony\Component\Console\Helper\QuestionHelper() |
|
130 | + ) |
|
131 | + ); |
|
132 | + $application->add(new OC\Core\Command\Encryption\ShowKeyStorageRoot($util)); |
|
133 | 133 | |
134 | - $application->add(new OC\Core\Command\Maintenance\DataFingerprint(\OC::$server->getConfig(), new \OC\AppFramework\Utility\TimeFactory())); |
|
135 | - $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->getMimeTypeDetector(), \OC::$server->getMimeTypeLoader())); |
|
136 | - $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->getMimeTypeDetector())); |
|
137 | - $application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig())); |
|
138 | - $application->add(new OC\Core\Command\Maintenance\UpdateHtaccess()); |
|
139 | - $application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory())); |
|
134 | + $application->add(new OC\Core\Command\Maintenance\DataFingerprint(\OC::$server->getConfig(), new \OC\AppFramework\Utility\TimeFactory())); |
|
135 | + $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->getMimeTypeDetector(), \OC::$server->getMimeTypeLoader())); |
|
136 | + $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->getMimeTypeDetector())); |
|
137 | + $application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig())); |
|
138 | + $application->add(new OC\Core\Command\Maintenance\UpdateHtaccess()); |
|
139 | + $application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory())); |
|
140 | 140 | |
141 | - $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->query(\OC\Installer::class))); |
|
142 | - $application->add(new OC\Core\Command\Maintenance\Repair( |
|
143 | - new \OC\Repair(\OC\Repair::getRepairSteps(), \OC::$server->getEventDispatcher()), \OC::$server->getConfig(), |
|
144 | - \OC::$server->getEventDispatcher(), \OC::$server->getAppManager())); |
|
141 | + $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->query(\OC\Installer::class))); |
|
142 | + $application->add(new OC\Core\Command\Maintenance\Repair( |
|
143 | + new \OC\Repair(\OC\Repair::getRepairSteps(), \OC::$server->getEventDispatcher()), \OC::$server->getConfig(), |
|
144 | + \OC::$server->getEventDispatcher(), \OC::$server->getAppManager())); |
|
145 | 145 | |
146 | - $application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
147 | - $application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager())); |
|
148 | - $application->add(new OC\Core\Command\User\Disable(\OC::$server->getUserManager())); |
|
149 | - $application->add(new OC\Core\Command\User\Enable(\OC::$server->getUserManager())); |
|
150 | - $application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager())); |
|
151 | - $application->add(new OC\Core\Command\User\Report(\OC::$server->getUserManager())); |
|
152 | - $application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager())); |
|
153 | - $application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig(), \OC::$server->getDatabaseConnection())); |
|
154 | - $application->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager())); |
|
155 | - $application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
146 | + $application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
147 | + $application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager())); |
|
148 | + $application->add(new OC\Core\Command\User\Disable(\OC::$server->getUserManager())); |
|
149 | + $application->add(new OC\Core\Command\User\Enable(\OC::$server->getUserManager())); |
|
150 | + $application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager())); |
|
151 | + $application->add(new OC\Core\Command\User\Report(\OC::$server->getUserManager())); |
|
152 | + $application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager())); |
|
153 | + $application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig(), \OC::$server->getDatabaseConnection())); |
|
154 | + $application->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager())); |
|
155 | + $application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
156 | 156 | |
157 | - $application->add(new OC\Core\Command\Group\ListCommand(\OC::$server->getGroupManager())); |
|
158 | - $application->add(new OC\Core\Command\Group\AddUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
159 | - $application->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
157 | + $application->add(new OC\Core\Command\Group\ListCommand(\OC::$server->getGroupManager())); |
|
158 | + $application->add(new OC\Core\Command\Group\AddUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
159 | + $application->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
160 | 160 | |
161 | - $application->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(null), \OC::$server->getL10N('core'))); |
|
162 | - $application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager(null))); |
|
163 | - $application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager(null))); |
|
161 | + $application->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(null), \OC::$server->getL10N('core'))); |
|
162 | + $application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager(null))); |
|
163 | + $application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager(null))); |
|
164 | 164 | } else { |
165 | - $application->add(new OC\Core\Command\Maintenance\Install(\OC::$server->getSystemConfig())); |
|
165 | + $application->add(new OC\Core\Command\Maintenance\Install(\OC::$server->getSystemConfig())); |
|
166 | 166 | } |
@@ -31,52 +31,52 @@ |
||
31 | 31 | |
32 | 32 | class Version14000Date20180522074438 extends SimpleMigrationStep { |
33 | 33 | |
34 | - /** |
|
35 | - * @param IOutput $output |
|
36 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
37 | - * @param array $options |
|
38 | - */ |
|
39 | - public function preSchemaChange(IOutput $output, Closure $schemaClosure, |
|
40 | - array $options) { |
|
34 | + /** |
|
35 | + * @param IOutput $output |
|
36 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
37 | + * @param array $options |
|
38 | + */ |
|
39 | + public function preSchemaChange(IOutput $output, Closure $schemaClosure, |
|
40 | + array $options) { |
|
41 | 41 | |
42 | - } |
|
42 | + } |
|
43 | 43 | |
44 | - public function changeSchema(IOutput $output, Closure $schemaClosure, |
|
45 | - array $options): ISchemaWrapper { |
|
44 | + public function changeSchema(IOutput $output, Closure $schemaClosure, |
|
45 | + array $options): ISchemaWrapper { |
|
46 | 46 | |
47 | - $schema = $schemaClosure(); |
|
47 | + $schema = $schemaClosure(); |
|
48 | 48 | |
49 | - if (!$schema->hasTable('twofactor_providers')) { |
|
50 | - $table = $schema->createTable('twofactor_providers'); |
|
51 | - $table->addColumn('provider_id', 'string', |
|
52 | - [ |
|
53 | - 'notnull' => true, |
|
54 | - 'length' => 32, |
|
55 | - ]); |
|
56 | - $table->addColumn('uid', 'string', |
|
57 | - [ |
|
58 | - 'notnull' => true, |
|
59 | - 'length' => 64, |
|
60 | - ]); |
|
61 | - $table->addColumn('enabled', 'smallint', |
|
62 | - [ |
|
63 | - 'notnull' => true, |
|
64 | - 'length' => 1, |
|
65 | - ]); |
|
66 | - $table->setPrimaryKey(['provider_id', 'uid']); |
|
67 | - } |
|
49 | + if (!$schema->hasTable('twofactor_providers')) { |
|
50 | + $table = $schema->createTable('twofactor_providers'); |
|
51 | + $table->addColumn('provider_id', 'string', |
|
52 | + [ |
|
53 | + 'notnull' => true, |
|
54 | + 'length' => 32, |
|
55 | + ]); |
|
56 | + $table->addColumn('uid', 'string', |
|
57 | + [ |
|
58 | + 'notnull' => true, |
|
59 | + 'length' => 64, |
|
60 | + ]); |
|
61 | + $table->addColumn('enabled', 'smallint', |
|
62 | + [ |
|
63 | + 'notnull' => true, |
|
64 | + 'length' => 1, |
|
65 | + ]); |
|
66 | + $table->setPrimaryKey(['provider_id', 'uid']); |
|
67 | + } |
|
68 | 68 | |
69 | - return $schema; |
|
70 | - } |
|
69 | + return $schema; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @param IOutput $output |
|
74 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
75 | - * @param array $options |
|
76 | - */ |
|
77 | - public function postSchemaChange(IOutput $output, Closure $schemaClosure, |
|
78 | - array $options) { |
|
72 | + /** |
|
73 | + * @param IOutput $output |
|
74 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
75 | + * @param array $options |
|
76 | + */ |
|
77 | + public function postSchemaChange(IOutput $output, Closure $schemaClosure, |
|
78 | + array $options) { |
|
79 | 79 | |
80 | - } |
|
80 | + } |
|
81 | 81 | |
82 | 82 | } |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | // To find out if we are running from CLI or not |
168 | 168 | $this->registerParameter('isCLI', \OC::$CLI); |
169 | 169 | |
170 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
170 | + $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) { |
|
171 | 171 | return $c; |
172 | 172 | }); |
173 | 173 | |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | $this->registerAlias(IActionFactory::class, ActionFactory::class); |
181 | 181 | |
182 | 182 | |
183 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
183 | + $this->registerService(\OCP\IPreview::class, function(Server $c) { |
|
184 | 184 | return new PreviewManager( |
185 | 185 | $c->getConfig(), |
186 | 186 | $c->getRootFolder(), |
@@ -191,13 +191,13 @@ discard block |
||
191 | 191 | }); |
192 | 192 | $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
193 | 193 | |
194 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
194 | + $this->registerService(\OC\Preview\Watcher::class, function(Server $c) { |
|
195 | 195 | return new \OC\Preview\Watcher( |
196 | 196 | $c->getAppDataDir('preview') |
197 | 197 | ); |
198 | 198 | }); |
199 | 199 | |
200 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
200 | + $this->registerService('EncryptionManager', function(Server $c) { |
|
201 | 201 | $view = new View(); |
202 | 202 | $util = new Encryption\Util( |
203 | 203 | $view, |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | ); |
216 | 216 | }); |
217 | 217 | |
218 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
218 | + $this->registerService('EncryptionFileHelper', function(Server $c) { |
|
219 | 219 | $util = new Encryption\Util( |
220 | 220 | new View(), |
221 | 221 | $c->getUserManager(), |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | ); |
230 | 230 | }); |
231 | 231 | |
232 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
232 | + $this->registerService('EncryptionKeyStorage', function(Server $c) { |
|
233 | 233 | $view = new View(); |
234 | 234 | $util = new Encryption\Util( |
235 | 235 | $view, |
@@ -240,30 +240,30 @@ discard block |
||
240 | 240 | |
241 | 241 | return new Encryption\Keys\Storage($view, $util); |
242 | 242 | }); |
243 | - $this->registerService('TagMapper', function (Server $c) { |
|
243 | + $this->registerService('TagMapper', function(Server $c) { |
|
244 | 244 | return new TagMapper($c->getDatabaseConnection()); |
245 | 245 | }); |
246 | 246 | |
247 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
247 | + $this->registerService(\OCP\ITagManager::class, function(Server $c) { |
|
248 | 248 | $tagMapper = $c->query('TagMapper'); |
249 | 249 | return new TagManager($tagMapper, $c->getUserSession()); |
250 | 250 | }); |
251 | 251 | $this->registerAlias('TagManager', \OCP\ITagManager::class); |
252 | 252 | |
253 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
253 | + $this->registerService('SystemTagManagerFactory', function(Server $c) { |
|
254 | 254 | $config = $c->getConfig(); |
255 | 255 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
256 | 256 | return new $factoryClass($this); |
257 | 257 | }); |
258 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
258 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) { |
|
259 | 259 | return $c->query('SystemTagManagerFactory')->getManager(); |
260 | 260 | }); |
261 | 261 | $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
262 | 262 | |
263 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
263 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) { |
|
264 | 264 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
265 | 265 | }); |
266 | - $this->registerService('RootFolder', function (Server $c) { |
|
266 | + $this->registerService('RootFolder', function(Server $c) { |
|
267 | 267 | $manager = \OC\Files\Filesystem::getMountManager(null); |
268 | 268 | $view = new View(); |
269 | 269 | $root = new Root( |
@@ -284,38 +284,38 @@ discard block |
||
284 | 284 | }); |
285 | 285 | $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
286 | 286 | |
287 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
288 | - return new LazyRoot(function () use ($c) { |
|
287 | + $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) { |
|
288 | + return new LazyRoot(function() use ($c) { |
|
289 | 289 | return $c->query('RootFolder'); |
290 | 290 | }); |
291 | 291 | }); |
292 | 292 | $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
293 | 293 | |
294 | - $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
294 | + $this->registerService(\OC\User\Manager::class, function(Server $c) { |
|
295 | 295 | $config = $c->getConfig(); |
296 | 296 | return new \OC\User\Manager($config); |
297 | 297 | }); |
298 | 298 | $this->registerAlias('UserManager', \OC\User\Manager::class); |
299 | 299 | $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
300 | 300 | |
301 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
301 | + $this->registerService(\OCP\IGroupManager::class, function(Server $c) { |
|
302 | 302 | $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
303 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
303 | + $groupManager->listen('\OC\Group', 'preCreate', function($gid) { |
|
304 | 304 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
305 | 305 | }); |
306 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
306 | + $groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) { |
|
307 | 307 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
308 | 308 | }); |
309 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
309 | + $groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) { |
|
310 | 310 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
311 | 311 | }); |
312 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
312 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) { |
|
313 | 313 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
314 | 314 | }); |
315 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
315 | + $groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
316 | 316 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
317 | 317 | }); |
318 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
318 | + $groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
319 | 319 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
320 | 320 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
321 | 321 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | }); |
325 | 325 | $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
326 | 326 | |
327 | - $this->registerService(Store::class, function (Server $c) { |
|
327 | + $this->registerService(Store::class, function(Server $c) { |
|
328 | 328 | $session = $c->getSession(); |
329 | 329 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
330 | 330 | $tokenProvider = $c->query(IProvider::class); |
@@ -335,11 +335,11 @@ discard block |
||
335 | 335 | return new Store($session, $logger, $tokenProvider); |
336 | 336 | }); |
337 | 337 | $this->registerAlias(IStore::class, Store::class); |
338 | - $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
338 | + $this->registerService(Authentication\Token\DefaultTokenMapper::class, function(Server $c) { |
|
339 | 339 | $dbConnection = $c->getDatabaseConnection(); |
340 | 340 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
341 | 341 | }); |
342 | - $this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) { |
|
342 | + $this->registerService(Authentication\Token\DefaultTokenProvider::class, function(Server $c) { |
|
343 | 343 | $mapper = $c->query(Authentication\Token\DefaultTokenMapper::class); |
344 | 344 | $crypto = $c->getCrypto(); |
345 | 345 | $config = $c->getConfig(); |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | }); |
350 | 350 | $this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class); |
351 | 351 | |
352 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
352 | + $this->registerService(\OCP\IUserSession::class, function(Server $c) { |
|
353 | 353 | $manager = $c->getUserManager(); |
354 | 354 | $session = new \OC\Session\Memory(''); |
355 | 355 | $timeFactory = new TimeFactory(); |
@@ -373,45 +373,45 @@ discard block |
||
373 | 373 | $c->getLockdownManager(), |
374 | 374 | $c->getLogger() |
375 | 375 | ); |
376 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
376 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
377 | 377 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
378 | 378 | }); |
379 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
379 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
380 | 380 | /** @var $user \OC\User\User */ |
381 | 381 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
382 | 382 | }); |
383 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
383 | + $userSession->listen('\OC\User', 'preDelete', function($user) use ($dispatcher) { |
|
384 | 384 | /** @var $user \OC\User\User */ |
385 | 385 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
386 | 386 | $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
387 | 387 | }); |
388 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
388 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
389 | 389 | /** @var $user \OC\User\User */ |
390 | 390 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
391 | 391 | }); |
392 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
392 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
393 | 393 | /** @var $user \OC\User\User */ |
394 | 394 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
395 | 395 | }); |
396 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
396 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
397 | 397 | /** @var $user \OC\User\User */ |
398 | 398 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
399 | 399 | }); |
400 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
400 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
401 | 401 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
402 | 402 | }); |
403 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
403 | + $userSession->listen('\OC\User', 'postLogin', function($user, $password) { |
|
404 | 404 | /** @var $user \OC\User\User */ |
405 | 405 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
406 | 406 | }); |
407 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
407 | + $userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) { |
|
408 | 408 | /** @var $user \OC\User\User */ |
409 | 409 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
410 | 410 | }); |
411 | - $userSession->listen('\OC\User', 'logout', function () { |
|
411 | + $userSession->listen('\OC\User', 'logout', function() { |
|
412 | 412 | \OC_Hook::emit('OC_User', 'logout', array()); |
413 | 413 | }); |
414 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
414 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
415 | 415 | /** @var $user \OC\User\User */ |
416 | 416 | \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
417 | 417 | $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
426 | 426 | $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
427 | 427 | |
428 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
428 | + $this->registerService(\OC\AllConfig::class, function(Server $c) { |
|
429 | 429 | return new \OC\AllConfig( |
430 | 430 | $c->getSystemConfig() |
431 | 431 | ); |
@@ -433,17 +433,17 @@ discard block |
||
433 | 433 | $this->registerAlias('AllConfig', \OC\AllConfig::class); |
434 | 434 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
435 | 435 | |
436 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
436 | + $this->registerService('SystemConfig', function($c) use ($config) { |
|
437 | 437 | return new \OC\SystemConfig($config); |
438 | 438 | }); |
439 | 439 | |
440 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
440 | + $this->registerService(\OC\AppConfig::class, function(Server $c) { |
|
441 | 441 | return new \OC\AppConfig($c->getDatabaseConnection()); |
442 | 442 | }); |
443 | 443 | $this->registerAlias('AppConfig', \OC\AppConfig::class); |
444 | 444 | $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
445 | 445 | |
446 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
446 | + $this->registerService(\OCP\L10N\IFactory::class, function(Server $c) { |
|
447 | 447 | return new \OC\L10N\Factory( |
448 | 448 | $c->getConfig(), |
449 | 449 | $c->getRequest(), |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | }); |
454 | 454 | $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
455 | 455 | |
456 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
456 | + $this->registerService(\OCP\IURLGenerator::class, function(Server $c) { |
|
457 | 457 | $config = $c->getConfig(); |
458 | 458 | $cacheFactory = $c->getMemCacheFactory(); |
459 | 459 | $request = $c->getRequest(); |
@@ -468,12 +468,12 @@ discard block |
||
468 | 468 | $this->registerAlias('AppFetcher', AppFetcher::class); |
469 | 469 | $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
470 | 470 | |
471 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
471 | + $this->registerService(\OCP\ICache::class, function($c) { |
|
472 | 472 | return new Cache\File(); |
473 | 473 | }); |
474 | 474 | $this->registerAlias('UserCache', \OCP\ICache::class); |
475 | 475 | |
476 | - $this->registerService(Factory::class, function (Server $c) { |
|
476 | + $this->registerService(Factory::class, function(Server $c) { |
|
477 | 477 | |
478 | 478 | $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
479 | 479 | ArrayCache::class, |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | $version = implode(',', $v); |
491 | 491 | $instanceId = \OC_Util::getInstanceId(); |
492 | 492 | $path = \OC::$SERVERROOT; |
493 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
493 | + $prefix = md5($instanceId.'-'.$version.'-'.$path); |
|
494 | 494 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
495 | 495 | $config->getSystemValue('memcache.local', null), |
496 | 496 | $config->getSystemValue('memcache.distributed', null), |
@@ -503,12 +503,12 @@ discard block |
||
503 | 503 | $this->registerAlias('MemCacheFactory', Factory::class); |
504 | 504 | $this->registerAlias(ICacheFactory::class, Factory::class); |
505 | 505 | |
506 | - $this->registerService('RedisFactory', function (Server $c) { |
|
506 | + $this->registerService('RedisFactory', function(Server $c) { |
|
507 | 507 | $systemConfig = $c->getSystemConfig(); |
508 | 508 | return new RedisFactory($systemConfig); |
509 | 509 | }); |
510 | 510 | |
511 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
511 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
512 | 512 | return new \OC\Activity\Manager( |
513 | 513 | $c->getRequest(), |
514 | 514 | $c->getUserSession(), |
@@ -518,14 +518,14 @@ discard block |
||
518 | 518 | }); |
519 | 519 | $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
520 | 520 | |
521 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
521 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
522 | 522 | return new \OC\Activity\EventMerger( |
523 | 523 | $c->getL10N('lib') |
524 | 524 | ); |
525 | 525 | }); |
526 | 526 | $this->registerAlias(IValidator::class, Validator::class); |
527 | 527 | |
528 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
528 | + $this->registerService(\OCP\IAvatarManager::class, function(Server $c) { |
|
529 | 529 | return new AvatarManager( |
530 | 530 | $c->query(\OC\User\Manager::class), |
531 | 531 | $c->getAppDataDir('avatar'), |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | |
539 | 539 | $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
540 | 540 | |
541 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
541 | + $this->registerService(\OCP\ILogger::class, function(Server $c) { |
|
542 | 542 | $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
543 | 543 | $factory = new LogFactory($c, $this->getSystemConfig()); |
544 | 544 | $logger = $factory->get($logType); |
@@ -548,11 +548,11 @@ discard block |
||
548 | 548 | }); |
549 | 549 | $this->registerAlias('Logger', \OCP\ILogger::class); |
550 | 550 | |
551 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
551 | + $this->registerService(ILogFactory::class, function(Server $c) { |
|
552 | 552 | return new LogFactory($c, $this->getSystemConfig()); |
553 | 553 | }); |
554 | 554 | |
555 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
555 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) { |
|
556 | 556 | $config = $c->getConfig(); |
557 | 557 | return new \OC\BackgroundJob\JobList( |
558 | 558 | $c->getDatabaseConnection(), |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | }); |
563 | 563 | $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
564 | 564 | |
565 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
565 | + $this->registerService(\OCP\Route\IRouter::class, function(Server $c) { |
|
566 | 566 | $cacheFactory = $c->getMemCacheFactory(); |
567 | 567 | $logger = $c->getLogger(); |
568 | 568 | if ($cacheFactory->isLocalCacheAvailable()) { |
@@ -574,12 +574,12 @@ discard block |
||
574 | 574 | }); |
575 | 575 | $this->registerAlias('Router', \OCP\Route\IRouter::class); |
576 | 576 | |
577 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
577 | + $this->registerService(\OCP\ISearch::class, function($c) { |
|
578 | 578 | return new Search(); |
579 | 579 | }); |
580 | 580 | $this->registerAlias('Search', \OCP\ISearch::class); |
581 | 581 | |
582 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
582 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function(Server $c) { |
|
583 | 583 | return new \OC\Security\RateLimiting\Limiter( |
584 | 584 | $this->getUserSession(), |
585 | 585 | $this->getRequest(), |
@@ -587,34 +587,34 @@ discard block |
||
587 | 587 | $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
588 | 588 | ); |
589 | 589 | }); |
590 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
590 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
591 | 591 | return new \OC\Security\RateLimiting\Backend\MemoryCache( |
592 | 592 | $this->getMemCacheFactory(), |
593 | 593 | new \OC\AppFramework\Utility\TimeFactory() |
594 | 594 | ); |
595 | 595 | }); |
596 | 596 | |
597 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
597 | + $this->registerService(\OCP\Security\ISecureRandom::class, function($c) { |
|
598 | 598 | return new SecureRandom(); |
599 | 599 | }); |
600 | 600 | $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
601 | 601 | |
602 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
602 | + $this->registerService(\OCP\Security\ICrypto::class, function(Server $c) { |
|
603 | 603 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
604 | 604 | }); |
605 | 605 | $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
606 | 606 | |
607 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
607 | + $this->registerService(\OCP\Security\IHasher::class, function(Server $c) { |
|
608 | 608 | return new Hasher($c->getConfig()); |
609 | 609 | }); |
610 | 610 | $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
611 | 611 | |
612 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
612 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) { |
|
613 | 613 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
614 | 614 | }); |
615 | 615 | $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
616 | 616 | |
617 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
617 | + $this->registerService(IDBConnection::class, function(Server $c) { |
|
618 | 618 | $systemConfig = $c->getSystemConfig(); |
619 | 619 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
620 | 620 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -629,7 +629,7 @@ discard block |
||
629 | 629 | $this->registerAlias('DatabaseConnection', IDBConnection::class); |
630 | 630 | |
631 | 631 | |
632 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
632 | + $this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) { |
|
633 | 633 | $user = \OC_User::getUser(); |
634 | 634 | $uid = $user ? $user : null; |
635 | 635 | return new ClientService( |
@@ -644,7 +644,7 @@ discard block |
||
644 | 644 | ); |
645 | 645 | }); |
646 | 646 | $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
647 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
647 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) { |
|
648 | 648 | $eventLogger = new EventLogger(); |
649 | 649 | if ($c->getSystemConfig()->getValue('debug', false)) { |
650 | 650 | // In debug mode, module is being activated by default |
@@ -654,7 +654,7 @@ discard block |
||
654 | 654 | }); |
655 | 655 | $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
656 | 656 | |
657 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
657 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) { |
|
658 | 658 | $queryLogger = new QueryLogger(); |
659 | 659 | if ($c->getSystemConfig()->getValue('debug', false)) { |
660 | 660 | // In debug mode, module is being activated by default |
@@ -664,7 +664,7 @@ discard block |
||
664 | 664 | }); |
665 | 665 | $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
666 | 666 | |
667 | - $this->registerService(TempManager::class, function (Server $c) { |
|
667 | + $this->registerService(TempManager::class, function(Server $c) { |
|
668 | 668 | return new TempManager( |
669 | 669 | $c->getLogger(), |
670 | 670 | $c->getConfig() |
@@ -673,7 +673,7 @@ discard block |
||
673 | 673 | $this->registerAlias('TempManager', TempManager::class); |
674 | 674 | $this->registerAlias(ITempManager::class, TempManager::class); |
675 | 675 | |
676 | - $this->registerService(AppManager::class, function (Server $c) { |
|
676 | + $this->registerService(AppManager::class, function(Server $c) { |
|
677 | 677 | return new \OC\App\AppManager( |
678 | 678 | $c->getUserSession(), |
679 | 679 | $c->query(\OC\AppConfig::class), |
@@ -685,7 +685,7 @@ discard block |
||
685 | 685 | $this->registerAlias('AppManager', AppManager::class); |
686 | 686 | $this->registerAlias(IAppManager::class, AppManager::class); |
687 | 687 | |
688 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
688 | + $this->registerService(\OCP\IDateTimeZone::class, function(Server $c) { |
|
689 | 689 | return new DateTimeZone( |
690 | 690 | $c->getConfig(), |
691 | 691 | $c->getSession() |
@@ -693,7 +693,7 @@ discard block |
||
693 | 693 | }); |
694 | 694 | $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
695 | 695 | |
696 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
696 | + $this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) { |
|
697 | 697 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
698 | 698 | |
699 | 699 | return new DateTimeFormatter( |
@@ -703,7 +703,7 @@ discard block |
||
703 | 703 | }); |
704 | 704 | $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
705 | 705 | |
706 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
706 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) { |
|
707 | 707 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
708 | 708 | $listener = new UserMountCacheListener($mountCache); |
709 | 709 | $listener->listen($c->getUserManager()); |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | }); |
712 | 712 | $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
713 | 713 | |
714 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
714 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) { |
|
715 | 715 | $loader = \OC\Files\Filesystem::getLoader(); |
716 | 716 | $mountCache = $c->query('UserMountCache'); |
717 | 717 | $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
@@ -727,10 +727,10 @@ discard block |
||
727 | 727 | }); |
728 | 728 | $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
729 | 729 | |
730 | - $this->registerService('IniWrapper', function ($c) { |
|
730 | + $this->registerService('IniWrapper', function($c) { |
|
731 | 731 | return new IniGetWrapper(); |
732 | 732 | }); |
733 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
733 | + $this->registerService('AsyncCommandBus', function(Server $c) { |
|
734 | 734 | $busClass = $c->getConfig()->getSystemValue('commandbus'); |
735 | 735 | if ($busClass) { |
736 | 736 | list($app, $class) = explode('::', $busClass, 2); |
@@ -745,10 +745,10 @@ discard block |
||
745 | 745 | return new CronBus($jobList); |
746 | 746 | } |
747 | 747 | }); |
748 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
748 | + $this->registerService('TrustedDomainHelper', function($c) { |
|
749 | 749 | return new TrustedDomainHelper($this->getConfig()); |
750 | 750 | }); |
751 | - $this->registerService('Throttler', function (Server $c) { |
|
751 | + $this->registerService('Throttler', function(Server $c) { |
|
752 | 752 | return new Throttler( |
753 | 753 | $c->getDatabaseConnection(), |
754 | 754 | new TimeFactory(), |
@@ -756,7 +756,7 @@ discard block |
||
756 | 756 | $c->getConfig() |
757 | 757 | ); |
758 | 758 | }); |
759 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
759 | + $this->registerService('IntegrityCodeChecker', function(Server $c) { |
|
760 | 760 | // IConfig and IAppManager requires a working database. This code |
761 | 761 | // might however be called when ownCloud is not yet setup. |
762 | 762 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
@@ -777,7 +777,7 @@ discard block |
||
777 | 777 | $c->getTempManager() |
778 | 778 | ); |
779 | 779 | }); |
780 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
780 | + $this->registerService(\OCP\IRequest::class, function($c) { |
|
781 | 781 | if (isset($this['urlParams'])) { |
782 | 782 | $urlParams = $this['urlParams']; |
783 | 783 | } else { |
@@ -813,7 +813,7 @@ discard block |
||
813 | 813 | }); |
814 | 814 | $this->registerAlias('Request', \OCP\IRequest::class); |
815 | 815 | |
816 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
816 | + $this->registerService(\OCP\Mail\IMailer::class, function(Server $c) { |
|
817 | 817 | return new Mailer( |
818 | 818 | $c->getConfig(), |
819 | 819 | $c->getLogger(), |
@@ -824,7 +824,7 @@ discard block |
||
824 | 824 | }); |
825 | 825 | $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
826 | 826 | |
827 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
827 | + $this->registerService('LDAPProvider', function(Server $c) { |
|
828 | 828 | $config = $c->getConfig(); |
829 | 829 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
830 | 830 | if (is_null($factoryClass)) { |
@@ -834,7 +834,7 @@ discard block |
||
834 | 834 | $factory = new $factoryClass($this); |
835 | 835 | return $factory->getLDAPProvider(); |
836 | 836 | }); |
837 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
837 | + $this->registerService(ILockingProvider::class, function(Server $c) { |
|
838 | 838 | $ini = $c->getIniWrapper(); |
839 | 839 | $config = $c->getConfig(); |
840 | 840 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -857,49 +857,49 @@ discard block |
||
857 | 857 | }); |
858 | 858 | $this->registerAlias('LockingProvider', ILockingProvider::class); |
859 | 859 | |
860 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
860 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function() { |
|
861 | 861 | return new \OC\Files\Mount\Manager(); |
862 | 862 | }); |
863 | 863 | $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
864 | 864 | |
865 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
865 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) { |
|
866 | 866 | return new \OC\Files\Type\Detection( |
867 | 867 | $c->getURLGenerator(), |
868 | 868 | \OC::$configDir, |
869 | - \OC::$SERVERROOT . '/resources/config/' |
|
869 | + \OC::$SERVERROOT.'/resources/config/' |
|
870 | 870 | ); |
871 | 871 | }); |
872 | 872 | $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
873 | 873 | |
874 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
874 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) { |
|
875 | 875 | return new \OC\Files\Type\Loader( |
876 | 876 | $c->getDatabaseConnection() |
877 | 877 | ); |
878 | 878 | }); |
879 | 879 | $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
880 | - $this->registerService(BundleFetcher::class, function () { |
|
880 | + $this->registerService(BundleFetcher::class, function() { |
|
881 | 881 | return new BundleFetcher($this->getL10N('lib')); |
882 | 882 | }); |
883 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
883 | + $this->registerService(\OCP\Notification\IManager::class, function(Server $c) { |
|
884 | 884 | return new Manager( |
885 | 885 | $c->query(IValidator::class) |
886 | 886 | ); |
887 | 887 | }); |
888 | 888 | $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
889 | 889 | |
890 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
890 | + $this->registerService(\OC\CapabilitiesManager::class, function(Server $c) { |
|
891 | 891 | $manager = new \OC\CapabilitiesManager($c->getLogger()); |
892 | - $manager->registerCapability(function () use ($c) { |
|
892 | + $manager->registerCapability(function() use ($c) { |
|
893 | 893 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
894 | 894 | }); |
895 | - $manager->registerCapability(function () use ($c) { |
|
895 | + $manager->registerCapability(function() use ($c) { |
|
896 | 896 | return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
897 | 897 | }); |
898 | 898 | return $manager; |
899 | 899 | }); |
900 | 900 | $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
901 | 901 | |
902 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
902 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
903 | 903 | $config = $c->getConfig(); |
904 | 904 | $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
905 | 905 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
@@ -909,7 +909,7 @@ discard block |
||
909 | 909 | $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
910 | 910 | $manager = $c->getUserManager(); |
911 | 911 | $user = $manager->get($id); |
912 | - if(is_null($user)) { |
|
912 | + if (is_null($user)) { |
|
913 | 913 | $l = $c->getL10N('core'); |
914 | 914 | $displayName = $l->t('Unknown user'); |
915 | 915 | } else { |
@@ -922,7 +922,7 @@ discard block |
||
922 | 922 | }); |
923 | 923 | $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
924 | 924 | |
925 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
925 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
926 | 926 | /* |
927 | 927 | * Dark magic for autoloader. |
928 | 928 | * If we do a class_exists it will try to load the class which will |
@@ -949,7 +949,7 @@ discard block |
||
949 | 949 | } |
950 | 950 | return new \OC_Defaults(); |
951 | 951 | }); |
952 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
952 | + $this->registerService(SCSSCacher::class, function(Server $c) { |
|
953 | 953 | /** @var Factory $cacheFactory */ |
954 | 954 | $cacheFactory = $c->query(Factory::class); |
955 | 955 | return new SCSSCacher( |
@@ -962,7 +962,7 @@ discard block |
||
962 | 962 | $this->getMemCacheFactory() |
963 | 963 | ); |
964 | 964 | }); |
965 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
965 | + $this->registerService(JSCombiner::class, function(Server $c) { |
|
966 | 966 | /** @var Factory $cacheFactory */ |
967 | 967 | $cacheFactory = $c->query(Factory::class); |
968 | 968 | return new JSCombiner( |
@@ -973,13 +973,13 @@ discard block |
||
973 | 973 | $c->getLogger() |
974 | 974 | ); |
975 | 975 | }); |
976 | - $this->registerService(EventDispatcher::class, function () { |
|
976 | + $this->registerService(EventDispatcher::class, function() { |
|
977 | 977 | return new EventDispatcher(); |
978 | 978 | }); |
979 | 979 | $this->registerAlias('EventDispatcher', EventDispatcher::class); |
980 | 980 | $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
981 | 981 | |
982 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
982 | + $this->registerService('CryptoWrapper', function(Server $c) { |
|
983 | 983 | // FIXME: Instantiiated here due to cyclic dependency |
984 | 984 | $request = new Request( |
985 | 985 | [ |
@@ -1004,7 +1004,7 @@ discard block |
||
1004 | 1004 | $request |
1005 | 1005 | ); |
1006 | 1006 | }); |
1007 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
1007 | + $this->registerService('CsrfTokenManager', function(Server $c) { |
|
1008 | 1008 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
1009 | 1009 | |
1010 | 1010 | return new CsrfTokenManager( |
@@ -1012,22 +1012,22 @@ discard block |
||
1012 | 1012 | $c->query(SessionStorage::class) |
1013 | 1013 | ); |
1014 | 1014 | }); |
1015 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
1015 | + $this->registerService(SessionStorage::class, function(Server $c) { |
|
1016 | 1016 | return new SessionStorage($c->getSession()); |
1017 | 1017 | }); |
1018 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1018 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) { |
|
1019 | 1019 | return new ContentSecurityPolicyManager(); |
1020 | 1020 | }); |
1021 | 1021 | $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
1022 | 1022 | |
1023 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1023 | + $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
1024 | 1024 | return new ContentSecurityPolicyNonceManager( |
1025 | 1025 | $c->getCsrfTokenManager(), |
1026 | 1026 | $c->getRequest() |
1027 | 1027 | ); |
1028 | 1028 | }); |
1029 | 1029 | |
1030 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1030 | + $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
1031 | 1031 | $config = $c->getConfig(); |
1032 | 1032 | $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
1033 | 1033 | /** @var \OCP\Share\IProviderFactory $factory */ |
@@ -1070,7 +1070,7 @@ discard block |
||
1070 | 1070 | |
1071 | 1071 | $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
1072 | 1072 | |
1073 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1073 | + $this->registerService('SettingsManager', function(Server $c) { |
|
1074 | 1074 | $manager = new \OC\Settings\Manager( |
1075 | 1075 | $c->getLogger(), |
1076 | 1076 | $c->getDatabaseConnection(), |
@@ -1088,24 +1088,24 @@ discard block |
||
1088 | 1088 | ); |
1089 | 1089 | return $manager; |
1090 | 1090 | }); |
1091 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1091 | + $this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) { |
|
1092 | 1092 | return new \OC\Files\AppData\Factory( |
1093 | 1093 | $c->getRootFolder(), |
1094 | 1094 | $c->getSystemConfig() |
1095 | 1095 | ); |
1096 | 1096 | }); |
1097 | 1097 | |
1098 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1099 | - return new LockdownManager(function () use ($c) { |
|
1098 | + $this->registerService('LockdownManager', function(Server $c) { |
|
1099 | + return new LockdownManager(function() use ($c) { |
|
1100 | 1100 | return $c->getSession(); |
1101 | 1101 | }); |
1102 | 1102 | }); |
1103 | 1103 | |
1104 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1104 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) { |
|
1105 | 1105 | return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
1106 | 1106 | }); |
1107 | 1107 | |
1108 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1108 | + $this->registerService(ICloudIdManager::class, function(Server $c) { |
|
1109 | 1109 | return new CloudIdManager(); |
1110 | 1110 | }); |
1111 | 1111 | |
@@ -1115,18 +1115,18 @@ discard block |
||
1115 | 1115 | $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
1116 | 1116 | $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
1117 | 1117 | |
1118 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1118 | + $this->registerService(Defaults::class, function(Server $c) { |
|
1119 | 1119 | return new Defaults( |
1120 | 1120 | $c->getThemingDefaults() |
1121 | 1121 | ); |
1122 | 1122 | }); |
1123 | 1123 | $this->registerAlias('Defaults', \OCP\Defaults::class); |
1124 | 1124 | |
1125 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1125 | + $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
1126 | 1126 | return $c->query(\OCP\IUserSession::class)->getSession(); |
1127 | 1127 | }); |
1128 | 1128 | |
1129 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1129 | + $this->registerService(IShareHelper::class, function(Server $c) { |
|
1130 | 1130 | return new ShareHelper( |
1131 | 1131 | $c->query(\OCP\Share\IManager::class) |
1132 | 1132 | ); |
@@ -1188,11 +1188,11 @@ discard block |
||
1188 | 1188 | // no avatar to remove |
1189 | 1189 | } catch (\Exception $e) { |
1190 | 1190 | // Ignore exceptions |
1191 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1191 | + $logger->info('Could not cleanup avatar of '.$user->getUID()); |
|
1192 | 1192 | } |
1193 | 1193 | }); |
1194 | 1194 | |
1195 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1195 | + $dispatcher->addListener('OCP\IUser::changeUser', function(GenericEvent $e) { |
|
1196 | 1196 | $manager = $this->getAvatarManager(); |
1197 | 1197 | /** @var IUser $user */ |
1198 | 1198 | $user = $e->getSubject(); |
@@ -1343,7 +1343,7 @@ discard block |
||
1343 | 1343 | * @deprecated since 9.2.0 use IAppData |
1344 | 1344 | */ |
1345 | 1345 | public function getAppFolder() { |
1346 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1346 | + $dir = '/'.\OC_App::getCurrentApp(); |
|
1347 | 1347 | $root = $this->getRootFolder(); |
1348 | 1348 | if (!$root->nodeExists($dir)) { |
1349 | 1349 | $folder = $root->newFolder($dir); |
@@ -1918,7 +1918,7 @@ discard block |
||
1918 | 1918 | /** |
1919 | 1919 | * @return \OCP\Collaboration\AutoComplete\IManager |
1920 | 1920 | */ |
1921 | - public function getAutoCompleteManager(){ |
|
1921 | + public function getAutoCompleteManager() { |
|
1922 | 1922 | return $this->query(IManager::class); |
1923 | 1923 | } |
1924 | 1924 |
@@ -153,1825 +153,1825 @@ |
||
153 | 153 | * TODO: hookup all manager classes |
154 | 154 | */ |
155 | 155 | class Server extends ServerContainer implements IServerContainer { |
156 | - /** @var string */ |
|
157 | - private $webRoot; |
|
158 | - |
|
159 | - /** |
|
160 | - * @param string $webRoot |
|
161 | - * @param \OC\Config $config |
|
162 | - */ |
|
163 | - public function __construct($webRoot, \OC\Config $config) { |
|
164 | - parent::__construct(); |
|
165 | - $this->webRoot = $webRoot; |
|
166 | - |
|
167 | - // To find out if we are running from CLI or not |
|
168 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
169 | - |
|
170 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
171 | - return $c; |
|
172 | - }); |
|
173 | - |
|
174 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
175 | - $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
176 | - |
|
177 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
178 | - $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
179 | - |
|
180 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
181 | - |
|
182 | - |
|
183 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
184 | - return new PreviewManager( |
|
185 | - $c->getConfig(), |
|
186 | - $c->getRootFolder(), |
|
187 | - $c->getAppDataDir('preview'), |
|
188 | - $c->getEventDispatcher(), |
|
189 | - $c->getSession()->get('user_id') |
|
190 | - ); |
|
191 | - }); |
|
192 | - $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
193 | - |
|
194 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
195 | - return new \OC\Preview\Watcher( |
|
196 | - $c->getAppDataDir('preview') |
|
197 | - ); |
|
198 | - }); |
|
199 | - |
|
200 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
201 | - $view = new View(); |
|
202 | - $util = new Encryption\Util( |
|
203 | - $view, |
|
204 | - $c->getUserManager(), |
|
205 | - $c->getGroupManager(), |
|
206 | - $c->getConfig() |
|
207 | - ); |
|
208 | - return new Encryption\Manager( |
|
209 | - $c->getConfig(), |
|
210 | - $c->getLogger(), |
|
211 | - $c->getL10N('core'), |
|
212 | - new View(), |
|
213 | - $util, |
|
214 | - new ArrayCache() |
|
215 | - ); |
|
216 | - }); |
|
217 | - |
|
218 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
219 | - $util = new Encryption\Util( |
|
220 | - new View(), |
|
221 | - $c->getUserManager(), |
|
222 | - $c->getGroupManager(), |
|
223 | - $c->getConfig() |
|
224 | - ); |
|
225 | - return new Encryption\File( |
|
226 | - $util, |
|
227 | - $c->getRootFolder(), |
|
228 | - $c->getShareManager() |
|
229 | - ); |
|
230 | - }); |
|
231 | - |
|
232 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
233 | - $view = new View(); |
|
234 | - $util = new Encryption\Util( |
|
235 | - $view, |
|
236 | - $c->getUserManager(), |
|
237 | - $c->getGroupManager(), |
|
238 | - $c->getConfig() |
|
239 | - ); |
|
240 | - |
|
241 | - return new Encryption\Keys\Storage($view, $util); |
|
242 | - }); |
|
243 | - $this->registerService('TagMapper', function (Server $c) { |
|
244 | - return new TagMapper($c->getDatabaseConnection()); |
|
245 | - }); |
|
246 | - |
|
247 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
248 | - $tagMapper = $c->query('TagMapper'); |
|
249 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
250 | - }); |
|
251 | - $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
252 | - |
|
253 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
254 | - $config = $c->getConfig(); |
|
255 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
256 | - return new $factoryClass($this); |
|
257 | - }); |
|
258 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
259 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
260 | - }); |
|
261 | - $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
262 | - |
|
263 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
264 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
265 | - }); |
|
266 | - $this->registerService('RootFolder', function (Server $c) { |
|
267 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
268 | - $view = new View(); |
|
269 | - $root = new Root( |
|
270 | - $manager, |
|
271 | - $view, |
|
272 | - null, |
|
273 | - $c->getUserMountCache(), |
|
274 | - $this->getLogger(), |
|
275 | - $this->getUserManager() |
|
276 | - ); |
|
277 | - $connector = new HookConnector($root, $view); |
|
278 | - $connector->viewToNode(); |
|
279 | - |
|
280 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
281 | - $previewConnector->connectWatcher(); |
|
282 | - |
|
283 | - return $root; |
|
284 | - }); |
|
285 | - $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
286 | - |
|
287 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
288 | - return new LazyRoot(function () use ($c) { |
|
289 | - return $c->query('RootFolder'); |
|
290 | - }); |
|
291 | - }); |
|
292 | - $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
293 | - |
|
294 | - $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
295 | - $config = $c->getConfig(); |
|
296 | - return new \OC\User\Manager($config); |
|
297 | - }); |
|
298 | - $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
299 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
300 | - |
|
301 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
302 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
303 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
304 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
305 | - }); |
|
306 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
307 | - \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
308 | - }); |
|
309 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
310 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
311 | - }); |
|
312 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
313 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
314 | - }); |
|
315 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
316 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
317 | - }); |
|
318 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
319 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
320 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
321 | - \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
322 | - }); |
|
323 | - return $groupManager; |
|
324 | - }); |
|
325 | - $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
326 | - |
|
327 | - $this->registerService(Store::class, function (Server $c) { |
|
328 | - $session = $c->getSession(); |
|
329 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
330 | - $tokenProvider = $c->query(IProvider::class); |
|
331 | - } else { |
|
332 | - $tokenProvider = null; |
|
333 | - } |
|
334 | - $logger = $c->getLogger(); |
|
335 | - return new Store($session, $logger, $tokenProvider); |
|
336 | - }); |
|
337 | - $this->registerAlias(IStore::class, Store::class); |
|
338 | - $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
339 | - $dbConnection = $c->getDatabaseConnection(); |
|
340 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
341 | - }); |
|
342 | - $this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) { |
|
343 | - $mapper = $c->query(Authentication\Token\DefaultTokenMapper::class); |
|
344 | - $crypto = $c->getCrypto(); |
|
345 | - $config = $c->getConfig(); |
|
346 | - $logger = $c->getLogger(); |
|
347 | - $timeFactory = new TimeFactory(); |
|
348 | - return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
349 | - }); |
|
350 | - $this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class); |
|
351 | - |
|
352 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
353 | - $manager = $c->getUserManager(); |
|
354 | - $session = new \OC\Session\Memory(''); |
|
355 | - $timeFactory = new TimeFactory(); |
|
356 | - // Token providers might require a working database. This code |
|
357 | - // might however be called when ownCloud is not yet setup. |
|
358 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
359 | - $defaultTokenProvider = $c->query(IProvider::class); |
|
360 | - } else { |
|
361 | - $defaultTokenProvider = null; |
|
362 | - } |
|
363 | - |
|
364 | - $dispatcher = $c->getEventDispatcher(); |
|
365 | - |
|
366 | - $userSession = new \OC\User\Session( |
|
367 | - $manager, |
|
368 | - $session, |
|
369 | - $timeFactory, |
|
370 | - $defaultTokenProvider, |
|
371 | - $c->getConfig(), |
|
372 | - $c->getSecureRandom(), |
|
373 | - $c->getLockdownManager(), |
|
374 | - $c->getLogger() |
|
375 | - ); |
|
376 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
377 | - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
378 | - }); |
|
379 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
380 | - /** @var $user \OC\User\User */ |
|
381 | - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
382 | - }); |
|
383 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
384 | - /** @var $user \OC\User\User */ |
|
385 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
386 | - $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
387 | - }); |
|
388 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
389 | - /** @var $user \OC\User\User */ |
|
390 | - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
391 | - }); |
|
392 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
393 | - /** @var $user \OC\User\User */ |
|
394 | - \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
395 | - }); |
|
396 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
397 | - /** @var $user \OC\User\User */ |
|
398 | - \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
399 | - }); |
|
400 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
401 | - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
402 | - }); |
|
403 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
404 | - /** @var $user \OC\User\User */ |
|
405 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
406 | - }); |
|
407 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
408 | - /** @var $user \OC\User\User */ |
|
409 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
410 | - }); |
|
411 | - $userSession->listen('\OC\User', 'logout', function () { |
|
412 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
413 | - }); |
|
414 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
415 | - /** @var $user \OC\User\User */ |
|
416 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
417 | - $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
|
418 | - }); |
|
419 | - return $userSession; |
|
420 | - }); |
|
421 | - $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
422 | - |
|
423 | - $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
424 | - |
|
425 | - $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
426 | - $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
427 | - |
|
428 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
429 | - return new \OC\AllConfig( |
|
430 | - $c->getSystemConfig() |
|
431 | - ); |
|
432 | - }); |
|
433 | - $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
434 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
435 | - |
|
436 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
437 | - return new \OC\SystemConfig($config); |
|
438 | - }); |
|
439 | - |
|
440 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
441 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
442 | - }); |
|
443 | - $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
444 | - $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
445 | - |
|
446 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
447 | - return new \OC\L10N\Factory( |
|
448 | - $c->getConfig(), |
|
449 | - $c->getRequest(), |
|
450 | - $c->getUserSession(), |
|
451 | - \OC::$SERVERROOT |
|
452 | - ); |
|
453 | - }); |
|
454 | - $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
455 | - |
|
456 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
457 | - $config = $c->getConfig(); |
|
458 | - $cacheFactory = $c->getMemCacheFactory(); |
|
459 | - $request = $c->getRequest(); |
|
460 | - return new \OC\URLGenerator( |
|
461 | - $config, |
|
462 | - $cacheFactory, |
|
463 | - $request |
|
464 | - ); |
|
465 | - }); |
|
466 | - $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
467 | - |
|
468 | - $this->registerAlias('AppFetcher', AppFetcher::class); |
|
469 | - $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
470 | - |
|
471 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
472 | - return new Cache\File(); |
|
473 | - }); |
|
474 | - $this->registerAlias('UserCache', \OCP\ICache::class); |
|
475 | - |
|
476 | - $this->registerService(Factory::class, function (Server $c) { |
|
477 | - |
|
478 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
479 | - ArrayCache::class, |
|
480 | - ArrayCache::class, |
|
481 | - ArrayCache::class |
|
482 | - ); |
|
483 | - $config = $c->getConfig(); |
|
484 | - $request = $c->getRequest(); |
|
485 | - $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
486 | - |
|
487 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
488 | - $v = \OC_App::getAppVersions(); |
|
489 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
490 | - $version = implode(',', $v); |
|
491 | - $instanceId = \OC_Util::getInstanceId(); |
|
492 | - $path = \OC::$SERVERROOT; |
|
493 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
494 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
495 | - $config->getSystemValue('memcache.local', null), |
|
496 | - $config->getSystemValue('memcache.distributed', null), |
|
497 | - $config->getSystemValue('memcache.locking', null) |
|
498 | - ); |
|
499 | - } |
|
500 | - return $arrayCacheFactory; |
|
501 | - |
|
502 | - }); |
|
503 | - $this->registerAlias('MemCacheFactory', Factory::class); |
|
504 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
505 | - |
|
506 | - $this->registerService('RedisFactory', function (Server $c) { |
|
507 | - $systemConfig = $c->getSystemConfig(); |
|
508 | - return new RedisFactory($systemConfig); |
|
509 | - }); |
|
510 | - |
|
511 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
512 | - return new \OC\Activity\Manager( |
|
513 | - $c->getRequest(), |
|
514 | - $c->getUserSession(), |
|
515 | - $c->getConfig(), |
|
516 | - $c->query(IValidator::class) |
|
517 | - ); |
|
518 | - }); |
|
519 | - $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
520 | - |
|
521 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
522 | - return new \OC\Activity\EventMerger( |
|
523 | - $c->getL10N('lib') |
|
524 | - ); |
|
525 | - }); |
|
526 | - $this->registerAlias(IValidator::class, Validator::class); |
|
527 | - |
|
528 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
529 | - return new AvatarManager( |
|
530 | - $c->query(\OC\User\Manager::class), |
|
531 | - $c->getAppDataDir('avatar'), |
|
532 | - $c->getL10N('lib'), |
|
533 | - $c->getLogger(), |
|
534 | - $c->getConfig() |
|
535 | - ); |
|
536 | - }); |
|
537 | - $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
538 | - |
|
539 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
540 | - |
|
541 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
542 | - $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
543 | - $factory = new LogFactory($c, $this->getSystemConfig()); |
|
544 | - $logger = $factory->get($logType); |
|
545 | - $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
546 | - |
|
547 | - return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
548 | - }); |
|
549 | - $this->registerAlias('Logger', \OCP\ILogger::class); |
|
550 | - |
|
551 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
552 | - return new LogFactory($c, $this->getSystemConfig()); |
|
553 | - }); |
|
554 | - |
|
555 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
556 | - $config = $c->getConfig(); |
|
557 | - return new \OC\BackgroundJob\JobList( |
|
558 | - $c->getDatabaseConnection(), |
|
559 | - $config, |
|
560 | - new TimeFactory() |
|
561 | - ); |
|
562 | - }); |
|
563 | - $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
564 | - |
|
565 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
566 | - $cacheFactory = $c->getMemCacheFactory(); |
|
567 | - $logger = $c->getLogger(); |
|
568 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
569 | - $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
570 | - } else { |
|
571 | - $router = new \OC\Route\Router($logger); |
|
572 | - } |
|
573 | - return $router; |
|
574 | - }); |
|
575 | - $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
576 | - |
|
577 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
578 | - return new Search(); |
|
579 | - }); |
|
580 | - $this->registerAlias('Search', \OCP\ISearch::class); |
|
581 | - |
|
582 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
583 | - return new \OC\Security\RateLimiting\Limiter( |
|
584 | - $this->getUserSession(), |
|
585 | - $this->getRequest(), |
|
586 | - new \OC\AppFramework\Utility\TimeFactory(), |
|
587 | - $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
588 | - ); |
|
589 | - }); |
|
590 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
591 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
592 | - $this->getMemCacheFactory(), |
|
593 | - new \OC\AppFramework\Utility\TimeFactory() |
|
594 | - ); |
|
595 | - }); |
|
596 | - |
|
597 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
598 | - return new SecureRandom(); |
|
599 | - }); |
|
600 | - $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
601 | - |
|
602 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
603 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
604 | - }); |
|
605 | - $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
606 | - |
|
607 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
608 | - return new Hasher($c->getConfig()); |
|
609 | - }); |
|
610 | - $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
611 | - |
|
612 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
613 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
614 | - }); |
|
615 | - $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
616 | - |
|
617 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
618 | - $systemConfig = $c->getSystemConfig(); |
|
619 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
620 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
621 | - if (!$factory->isValidType($type)) { |
|
622 | - throw new \OC\DatabaseException('Invalid database type'); |
|
623 | - } |
|
624 | - $connectionParams = $factory->createConnectionParams(); |
|
625 | - $connection = $factory->getConnection($type, $connectionParams); |
|
626 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
627 | - return $connection; |
|
628 | - }); |
|
629 | - $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
630 | - |
|
631 | - |
|
632 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
633 | - $user = \OC_User::getUser(); |
|
634 | - $uid = $user ? $user : null; |
|
635 | - return new ClientService( |
|
636 | - $c->getConfig(), |
|
637 | - new \OC\Security\CertificateManager( |
|
638 | - $uid, |
|
639 | - new View(), |
|
640 | - $c->getConfig(), |
|
641 | - $c->getLogger(), |
|
642 | - $c->getSecureRandom() |
|
643 | - ) |
|
644 | - ); |
|
645 | - }); |
|
646 | - $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
647 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
648 | - $eventLogger = new EventLogger(); |
|
649 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
650 | - // In debug mode, module is being activated by default |
|
651 | - $eventLogger->activate(); |
|
652 | - } |
|
653 | - return $eventLogger; |
|
654 | - }); |
|
655 | - $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
656 | - |
|
657 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
658 | - $queryLogger = new QueryLogger(); |
|
659 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
660 | - // In debug mode, module is being activated by default |
|
661 | - $queryLogger->activate(); |
|
662 | - } |
|
663 | - return $queryLogger; |
|
664 | - }); |
|
665 | - $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
666 | - |
|
667 | - $this->registerService(TempManager::class, function (Server $c) { |
|
668 | - return new TempManager( |
|
669 | - $c->getLogger(), |
|
670 | - $c->getConfig() |
|
671 | - ); |
|
672 | - }); |
|
673 | - $this->registerAlias('TempManager', TempManager::class); |
|
674 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
675 | - |
|
676 | - $this->registerService(AppManager::class, function (Server $c) { |
|
677 | - return new \OC\App\AppManager( |
|
678 | - $c->getUserSession(), |
|
679 | - $c->query(\OC\AppConfig::class), |
|
680 | - $c->getGroupManager(), |
|
681 | - $c->getMemCacheFactory(), |
|
682 | - $c->getEventDispatcher() |
|
683 | - ); |
|
684 | - }); |
|
685 | - $this->registerAlias('AppManager', AppManager::class); |
|
686 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
687 | - |
|
688 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
689 | - return new DateTimeZone( |
|
690 | - $c->getConfig(), |
|
691 | - $c->getSession() |
|
692 | - ); |
|
693 | - }); |
|
694 | - $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
695 | - |
|
696 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
697 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
698 | - |
|
699 | - return new DateTimeFormatter( |
|
700 | - $c->getDateTimeZone()->getTimeZone(), |
|
701 | - $c->getL10N('lib', $language) |
|
702 | - ); |
|
703 | - }); |
|
704 | - $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
705 | - |
|
706 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
707 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
708 | - $listener = new UserMountCacheListener($mountCache); |
|
709 | - $listener->listen($c->getUserManager()); |
|
710 | - return $mountCache; |
|
711 | - }); |
|
712 | - $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
713 | - |
|
714 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
715 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
716 | - $mountCache = $c->query('UserMountCache'); |
|
717 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
718 | - |
|
719 | - // builtin providers |
|
720 | - |
|
721 | - $config = $c->getConfig(); |
|
722 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
723 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
724 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
725 | - |
|
726 | - return $manager; |
|
727 | - }); |
|
728 | - $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
729 | - |
|
730 | - $this->registerService('IniWrapper', function ($c) { |
|
731 | - return new IniGetWrapper(); |
|
732 | - }); |
|
733 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
734 | - $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
735 | - if ($busClass) { |
|
736 | - list($app, $class) = explode('::', $busClass, 2); |
|
737 | - if ($c->getAppManager()->isInstalled($app)) { |
|
738 | - \OC_App::loadApp($app); |
|
739 | - return $c->query($class); |
|
740 | - } else { |
|
741 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
742 | - } |
|
743 | - } else { |
|
744 | - $jobList = $c->getJobList(); |
|
745 | - return new CronBus($jobList); |
|
746 | - } |
|
747 | - }); |
|
748 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
749 | - return new TrustedDomainHelper($this->getConfig()); |
|
750 | - }); |
|
751 | - $this->registerService('Throttler', function (Server $c) { |
|
752 | - return new Throttler( |
|
753 | - $c->getDatabaseConnection(), |
|
754 | - new TimeFactory(), |
|
755 | - $c->getLogger(), |
|
756 | - $c->getConfig() |
|
757 | - ); |
|
758 | - }); |
|
759 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
760 | - // IConfig and IAppManager requires a working database. This code |
|
761 | - // might however be called when ownCloud is not yet setup. |
|
762 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
763 | - $config = $c->getConfig(); |
|
764 | - $appManager = $c->getAppManager(); |
|
765 | - } else { |
|
766 | - $config = null; |
|
767 | - $appManager = null; |
|
768 | - } |
|
769 | - |
|
770 | - return new Checker( |
|
771 | - new EnvironmentHelper(), |
|
772 | - new FileAccessHelper(), |
|
773 | - new AppLocator(), |
|
774 | - $config, |
|
775 | - $c->getMemCacheFactory(), |
|
776 | - $appManager, |
|
777 | - $c->getTempManager() |
|
778 | - ); |
|
779 | - }); |
|
780 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
781 | - if (isset($this['urlParams'])) { |
|
782 | - $urlParams = $this['urlParams']; |
|
783 | - } else { |
|
784 | - $urlParams = []; |
|
785 | - } |
|
786 | - |
|
787 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
788 | - && in_array('fakeinput', stream_get_wrappers()) |
|
789 | - ) { |
|
790 | - $stream = 'fakeinput://data'; |
|
791 | - } else { |
|
792 | - $stream = 'php://input'; |
|
793 | - } |
|
794 | - |
|
795 | - return new Request( |
|
796 | - [ |
|
797 | - 'get' => $_GET, |
|
798 | - 'post' => $_POST, |
|
799 | - 'files' => $_FILES, |
|
800 | - 'server' => $_SERVER, |
|
801 | - 'env' => $_ENV, |
|
802 | - 'cookies' => $_COOKIE, |
|
803 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
804 | - ? $_SERVER['REQUEST_METHOD'] |
|
805 | - : '', |
|
806 | - 'urlParams' => $urlParams, |
|
807 | - ], |
|
808 | - $this->getSecureRandom(), |
|
809 | - $this->getConfig(), |
|
810 | - $this->getCsrfTokenManager(), |
|
811 | - $stream |
|
812 | - ); |
|
813 | - }); |
|
814 | - $this->registerAlias('Request', \OCP\IRequest::class); |
|
815 | - |
|
816 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
817 | - return new Mailer( |
|
818 | - $c->getConfig(), |
|
819 | - $c->getLogger(), |
|
820 | - $c->query(Defaults::class), |
|
821 | - $c->getURLGenerator(), |
|
822 | - $c->getL10N('lib') |
|
823 | - ); |
|
824 | - }); |
|
825 | - $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
826 | - |
|
827 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
828 | - $config = $c->getConfig(); |
|
829 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
830 | - if (is_null($factoryClass)) { |
|
831 | - throw new \Exception('ldapProviderFactory not set'); |
|
832 | - } |
|
833 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
834 | - $factory = new $factoryClass($this); |
|
835 | - return $factory->getLDAPProvider(); |
|
836 | - }); |
|
837 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
838 | - $ini = $c->getIniWrapper(); |
|
839 | - $config = $c->getConfig(); |
|
840 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
841 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
842 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
843 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
844 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
845 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
846 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
847 | - } |
|
848 | - return new DBLockingProvider( |
|
849 | - $c->getDatabaseConnection(), |
|
850 | - $c->getLogger(), |
|
851 | - new TimeFactory(), |
|
852 | - $ttl, |
|
853 | - !\OC::$CLI |
|
854 | - ); |
|
855 | - } |
|
856 | - return new NoopLockingProvider(); |
|
857 | - }); |
|
858 | - $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
859 | - |
|
860 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
861 | - return new \OC\Files\Mount\Manager(); |
|
862 | - }); |
|
863 | - $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
864 | - |
|
865 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
866 | - return new \OC\Files\Type\Detection( |
|
867 | - $c->getURLGenerator(), |
|
868 | - \OC::$configDir, |
|
869 | - \OC::$SERVERROOT . '/resources/config/' |
|
870 | - ); |
|
871 | - }); |
|
872 | - $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
873 | - |
|
874 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
875 | - return new \OC\Files\Type\Loader( |
|
876 | - $c->getDatabaseConnection() |
|
877 | - ); |
|
878 | - }); |
|
879 | - $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
880 | - $this->registerService(BundleFetcher::class, function () { |
|
881 | - return new BundleFetcher($this->getL10N('lib')); |
|
882 | - }); |
|
883 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
884 | - return new Manager( |
|
885 | - $c->query(IValidator::class) |
|
886 | - ); |
|
887 | - }); |
|
888 | - $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
889 | - |
|
890 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
891 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
892 | - $manager->registerCapability(function () use ($c) { |
|
893 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
894 | - }); |
|
895 | - $manager->registerCapability(function () use ($c) { |
|
896 | - return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
897 | - }); |
|
898 | - return $manager; |
|
899 | - }); |
|
900 | - $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
901 | - |
|
902 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
903 | - $config = $c->getConfig(); |
|
904 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
905 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
906 | - $factory = new $factoryClass($this); |
|
907 | - $manager = $factory->getManager(); |
|
908 | - |
|
909 | - $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
910 | - $manager = $c->getUserManager(); |
|
911 | - $user = $manager->get($id); |
|
912 | - if(is_null($user)) { |
|
913 | - $l = $c->getL10N('core'); |
|
914 | - $displayName = $l->t('Unknown user'); |
|
915 | - } else { |
|
916 | - $displayName = $user->getDisplayName(); |
|
917 | - } |
|
918 | - return $displayName; |
|
919 | - }); |
|
920 | - |
|
921 | - return $manager; |
|
922 | - }); |
|
923 | - $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
924 | - |
|
925 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
926 | - /* |
|
156 | + /** @var string */ |
|
157 | + private $webRoot; |
|
158 | + |
|
159 | + /** |
|
160 | + * @param string $webRoot |
|
161 | + * @param \OC\Config $config |
|
162 | + */ |
|
163 | + public function __construct($webRoot, \OC\Config $config) { |
|
164 | + parent::__construct(); |
|
165 | + $this->webRoot = $webRoot; |
|
166 | + |
|
167 | + // To find out if we are running from CLI or not |
|
168 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
169 | + |
|
170 | + $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
171 | + return $c; |
|
172 | + }); |
|
173 | + |
|
174 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
175 | + $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
176 | + |
|
177 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
178 | + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
179 | + |
|
180 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
181 | + |
|
182 | + |
|
183 | + $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
184 | + return new PreviewManager( |
|
185 | + $c->getConfig(), |
|
186 | + $c->getRootFolder(), |
|
187 | + $c->getAppDataDir('preview'), |
|
188 | + $c->getEventDispatcher(), |
|
189 | + $c->getSession()->get('user_id') |
|
190 | + ); |
|
191 | + }); |
|
192 | + $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
193 | + |
|
194 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
195 | + return new \OC\Preview\Watcher( |
|
196 | + $c->getAppDataDir('preview') |
|
197 | + ); |
|
198 | + }); |
|
199 | + |
|
200 | + $this->registerService('EncryptionManager', function (Server $c) { |
|
201 | + $view = new View(); |
|
202 | + $util = new Encryption\Util( |
|
203 | + $view, |
|
204 | + $c->getUserManager(), |
|
205 | + $c->getGroupManager(), |
|
206 | + $c->getConfig() |
|
207 | + ); |
|
208 | + return new Encryption\Manager( |
|
209 | + $c->getConfig(), |
|
210 | + $c->getLogger(), |
|
211 | + $c->getL10N('core'), |
|
212 | + new View(), |
|
213 | + $util, |
|
214 | + new ArrayCache() |
|
215 | + ); |
|
216 | + }); |
|
217 | + |
|
218 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
219 | + $util = new Encryption\Util( |
|
220 | + new View(), |
|
221 | + $c->getUserManager(), |
|
222 | + $c->getGroupManager(), |
|
223 | + $c->getConfig() |
|
224 | + ); |
|
225 | + return new Encryption\File( |
|
226 | + $util, |
|
227 | + $c->getRootFolder(), |
|
228 | + $c->getShareManager() |
|
229 | + ); |
|
230 | + }); |
|
231 | + |
|
232 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
233 | + $view = new View(); |
|
234 | + $util = new Encryption\Util( |
|
235 | + $view, |
|
236 | + $c->getUserManager(), |
|
237 | + $c->getGroupManager(), |
|
238 | + $c->getConfig() |
|
239 | + ); |
|
240 | + |
|
241 | + return new Encryption\Keys\Storage($view, $util); |
|
242 | + }); |
|
243 | + $this->registerService('TagMapper', function (Server $c) { |
|
244 | + return new TagMapper($c->getDatabaseConnection()); |
|
245 | + }); |
|
246 | + |
|
247 | + $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
248 | + $tagMapper = $c->query('TagMapper'); |
|
249 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
250 | + }); |
|
251 | + $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
252 | + |
|
253 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
254 | + $config = $c->getConfig(); |
|
255 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
256 | + return new $factoryClass($this); |
|
257 | + }); |
|
258 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
259 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
260 | + }); |
|
261 | + $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
262 | + |
|
263 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
264 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
265 | + }); |
|
266 | + $this->registerService('RootFolder', function (Server $c) { |
|
267 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
268 | + $view = new View(); |
|
269 | + $root = new Root( |
|
270 | + $manager, |
|
271 | + $view, |
|
272 | + null, |
|
273 | + $c->getUserMountCache(), |
|
274 | + $this->getLogger(), |
|
275 | + $this->getUserManager() |
|
276 | + ); |
|
277 | + $connector = new HookConnector($root, $view); |
|
278 | + $connector->viewToNode(); |
|
279 | + |
|
280 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
281 | + $previewConnector->connectWatcher(); |
|
282 | + |
|
283 | + return $root; |
|
284 | + }); |
|
285 | + $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
286 | + |
|
287 | + $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
288 | + return new LazyRoot(function () use ($c) { |
|
289 | + return $c->query('RootFolder'); |
|
290 | + }); |
|
291 | + }); |
|
292 | + $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
293 | + |
|
294 | + $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
295 | + $config = $c->getConfig(); |
|
296 | + return new \OC\User\Manager($config); |
|
297 | + }); |
|
298 | + $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
299 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
300 | + |
|
301 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
302 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
303 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
304 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
305 | + }); |
|
306 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
307 | + \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
308 | + }); |
|
309 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
310 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
311 | + }); |
|
312 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
313 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
314 | + }); |
|
315 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
316 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
317 | + }); |
|
318 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
319 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
320 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
321 | + \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
322 | + }); |
|
323 | + return $groupManager; |
|
324 | + }); |
|
325 | + $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
326 | + |
|
327 | + $this->registerService(Store::class, function (Server $c) { |
|
328 | + $session = $c->getSession(); |
|
329 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
330 | + $tokenProvider = $c->query(IProvider::class); |
|
331 | + } else { |
|
332 | + $tokenProvider = null; |
|
333 | + } |
|
334 | + $logger = $c->getLogger(); |
|
335 | + return new Store($session, $logger, $tokenProvider); |
|
336 | + }); |
|
337 | + $this->registerAlias(IStore::class, Store::class); |
|
338 | + $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
339 | + $dbConnection = $c->getDatabaseConnection(); |
|
340 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
341 | + }); |
|
342 | + $this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) { |
|
343 | + $mapper = $c->query(Authentication\Token\DefaultTokenMapper::class); |
|
344 | + $crypto = $c->getCrypto(); |
|
345 | + $config = $c->getConfig(); |
|
346 | + $logger = $c->getLogger(); |
|
347 | + $timeFactory = new TimeFactory(); |
|
348 | + return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
349 | + }); |
|
350 | + $this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class); |
|
351 | + |
|
352 | + $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
353 | + $manager = $c->getUserManager(); |
|
354 | + $session = new \OC\Session\Memory(''); |
|
355 | + $timeFactory = new TimeFactory(); |
|
356 | + // Token providers might require a working database. This code |
|
357 | + // might however be called when ownCloud is not yet setup. |
|
358 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
359 | + $defaultTokenProvider = $c->query(IProvider::class); |
|
360 | + } else { |
|
361 | + $defaultTokenProvider = null; |
|
362 | + } |
|
363 | + |
|
364 | + $dispatcher = $c->getEventDispatcher(); |
|
365 | + |
|
366 | + $userSession = new \OC\User\Session( |
|
367 | + $manager, |
|
368 | + $session, |
|
369 | + $timeFactory, |
|
370 | + $defaultTokenProvider, |
|
371 | + $c->getConfig(), |
|
372 | + $c->getSecureRandom(), |
|
373 | + $c->getLockdownManager(), |
|
374 | + $c->getLogger() |
|
375 | + ); |
|
376 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
377 | + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
378 | + }); |
|
379 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
380 | + /** @var $user \OC\User\User */ |
|
381 | + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
382 | + }); |
|
383 | + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
384 | + /** @var $user \OC\User\User */ |
|
385 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
386 | + $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
387 | + }); |
|
388 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
389 | + /** @var $user \OC\User\User */ |
|
390 | + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
391 | + }); |
|
392 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
393 | + /** @var $user \OC\User\User */ |
|
394 | + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
395 | + }); |
|
396 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
397 | + /** @var $user \OC\User\User */ |
|
398 | + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
399 | + }); |
|
400 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
401 | + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
402 | + }); |
|
403 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
404 | + /** @var $user \OC\User\User */ |
|
405 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
406 | + }); |
|
407 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
408 | + /** @var $user \OC\User\User */ |
|
409 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
410 | + }); |
|
411 | + $userSession->listen('\OC\User', 'logout', function () { |
|
412 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
413 | + }); |
|
414 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
415 | + /** @var $user \OC\User\User */ |
|
416 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
417 | + $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
|
418 | + }); |
|
419 | + return $userSession; |
|
420 | + }); |
|
421 | + $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
422 | + |
|
423 | + $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
424 | + |
|
425 | + $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
426 | + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
427 | + |
|
428 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
429 | + return new \OC\AllConfig( |
|
430 | + $c->getSystemConfig() |
|
431 | + ); |
|
432 | + }); |
|
433 | + $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
434 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
435 | + |
|
436 | + $this->registerService('SystemConfig', function ($c) use ($config) { |
|
437 | + return new \OC\SystemConfig($config); |
|
438 | + }); |
|
439 | + |
|
440 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
441 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
442 | + }); |
|
443 | + $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
444 | + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
445 | + |
|
446 | + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
447 | + return new \OC\L10N\Factory( |
|
448 | + $c->getConfig(), |
|
449 | + $c->getRequest(), |
|
450 | + $c->getUserSession(), |
|
451 | + \OC::$SERVERROOT |
|
452 | + ); |
|
453 | + }); |
|
454 | + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
455 | + |
|
456 | + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
457 | + $config = $c->getConfig(); |
|
458 | + $cacheFactory = $c->getMemCacheFactory(); |
|
459 | + $request = $c->getRequest(); |
|
460 | + return new \OC\URLGenerator( |
|
461 | + $config, |
|
462 | + $cacheFactory, |
|
463 | + $request |
|
464 | + ); |
|
465 | + }); |
|
466 | + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
467 | + |
|
468 | + $this->registerAlias('AppFetcher', AppFetcher::class); |
|
469 | + $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
470 | + |
|
471 | + $this->registerService(\OCP\ICache::class, function ($c) { |
|
472 | + return new Cache\File(); |
|
473 | + }); |
|
474 | + $this->registerAlias('UserCache', \OCP\ICache::class); |
|
475 | + |
|
476 | + $this->registerService(Factory::class, function (Server $c) { |
|
477 | + |
|
478 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
479 | + ArrayCache::class, |
|
480 | + ArrayCache::class, |
|
481 | + ArrayCache::class |
|
482 | + ); |
|
483 | + $config = $c->getConfig(); |
|
484 | + $request = $c->getRequest(); |
|
485 | + $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
486 | + |
|
487 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
488 | + $v = \OC_App::getAppVersions(); |
|
489 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
490 | + $version = implode(',', $v); |
|
491 | + $instanceId = \OC_Util::getInstanceId(); |
|
492 | + $path = \OC::$SERVERROOT; |
|
493 | + $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
494 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
495 | + $config->getSystemValue('memcache.local', null), |
|
496 | + $config->getSystemValue('memcache.distributed', null), |
|
497 | + $config->getSystemValue('memcache.locking', null) |
|
498 | + ); |
|
499 | + } |
|
500 | + return $arrayCacheFactory; |
|
501 | + |
|
502 | + }); |
|
503 | + $this->registerAlias('MemCacheFactory', Factory::class); |
|
504 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
505 | + |
|
506 | + $this->registerService('RedisFactory', function (Server $c) { |
|
507 | + $systemConfig = $c->getSystemConfig(); |
|
508 | + return new RedisFactory($systemConfig); |
|
509 | + }); |
|
510 | + |
|
511 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
512 | + return new \OC\Activity\Manager( |
|
513 | + $c->getRequest(), |
|
514 | + $c->getUserSession(), |
|
515 | + $c->getConfig(), |
|
516 | + $c->query(IValidator::class) |
|
517 | + ); |
|
518 | + }); |
|
519 | + $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
520 | + |
|
521 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
522 | + return new \OC\Activity\EventMerger( |
|
523 | + $c->getL10N('lib') |
|
524 | + ); |
|
525 | + }); |
|
526 | + $this->registerAlias(IValidator::class, Validator::class); |
|
527 | + |
|
528 | + $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
529 | + return new AvatarManager( |
|
530 | + $c->query(\OC\User\Manager::class), |
|
531 | + $c->getAppDataDir('avatar'), |
|
532 | + $c->getL10N('lib'), |
|
533 | + $c->getLogger(), |
|
534 | + $c->getConfig() |
|
535 | + ); |
|
536 | + }); |
|
537 | + $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
538 | + |
|
539 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
540 | + |
|
541 | + $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
542 | + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
543 | + $factory = new LogFactory($c, $this->getSystemConfig()); |
|
544 | + $logger = $factory->get($logType); |
|
545 | + $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
546 | + |
|
547 | + return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
548 | + }); |
|
549 | + $this->registerAlias('Logger', \OCP\ILogger::class); |
|
550 | + |
|
551 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
552 | + return new LogFactory($c, $this->getSystemConfig()); |
|
553 | + }); |
|
554 | + |
|
555 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
556 | + $config = $c->getConfig(); |
|
557 | + return new \OC\BackgroundJob\JobList( |
|
558 | + $c->getDatabaseConnection(), |
|
559 | + $config, |
|
560 | + new TimeFactory() |
|
561 | + ); |
|
562 | + }); |
|
563 | + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
564 | + |
|
565 | + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
566 | + $cacheFactory = $c->getMemCacheFactory(); |
|
567 | + $logger = $c->getLogger(); |
|
568 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
569 | + $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
570 | + } else { |
|
571 | + $router = new \OC\Route\Router($logger); |
|
572 | + } |
|
573 | + return $router; |
|
574 | + }); |
|
575 | + $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
576 | + |
|
577 | + $this->registerService(\OCP\ISearch::class, function ($c) { |
|
578 | + return new Search(); |
|
579 | + }); |
|
580 | + $this->registerAlias('Search', \OCP\ISearch::class); |
|
581 | + |
|
582 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
583 | + return new \OC\Security\RateLimiting\Limiter( |
|
584 | + $this->getUserSession(), |
|
585 | + $this->getRequest(), |
|
586 | + new \OC\AppFramework\Utility\TimeFactory(), |
|
587 | + $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
588 | + ); |
|
589 | + }); |
|
590 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
591 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
592 | + $this->getMemCacheFactory(), |
|
593 | + new \OC\AppFramework\Utility\TimeFactory() |
|
594 | + ); |
|
595 | + }); |
|
596 | + |
|
597 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
598 | + return new SecureRandom(); |
|
599 | + }); |
|
600 | + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
601 | + |
|
602 | + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
603 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
604 | + }); |
|
605 | + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
606 | + |
|
607 | + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
608 | + return new Hasher($c->getConfig()); |
|
609 | + }); |
|
610 | + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
611 | + |
|
612 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
613 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
614 | + }); |
|
615 | + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
616 | + |
|
617 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
618 | + $systemConfig = $c->getSystemConfig(); |
|
619 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
620 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
621 | + if (!$factory->isValidType($type)) { |
|
622 | + throw new \OC\DatabaseException('Invalid database type'); |
|
623 | + } |
|
624 | + $connectionParams = $factory->createConnectionParams(); |
|
625 | + $connection = $factory->getConnection($type, $connectionParams); |
|
626 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
627 | + return $connection; |
|
628 | + }); |
|
629 | + $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
630 | + |
|
631 | + |
|
632 | + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
633 | + $user = \OC_User::getUser(); |
|
634 | + $uid = $user ? $user : null; |
|
635 | + return new ClientService( |
|
636 | + $c->getConfig(), |
|
637 | + new \OC\Security\CertificateManager( |
|
638 | + $uid, |
|
639 | + new View(), |
|
640 | + $c->getConfig(), |
|
641 | + $c->getLogger(), |
|
642 | + $c->getSecureRandom() |
|
643 | + ) |
|
644 | + ); |
|
645 | + }); |
|
646 | + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
647 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
648 | + $eventLogger = new EventLogger(); |
|
649 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
650 | + // In debug mode, module is being activated by default |
|
651 | + $eventLogger->activate(); |
|
652 | + } |
|
653 | + return $eventLogger; |
|
654 | + }); |
|
655 | + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
656 | + |
|
657 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
658 | + $queryLogger = new QueryLogger(); |
|
659 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
660 | + // In debug mode, module is being activated by default |
|
661 | + $queryLogger->activate(); |
|
662 | + } |
|
663 | + return $queryLogger; |
|
664 | + }); |
|
665 | + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
666 | + |
|
667 | + $this->registerService(TempManager::class, function (Server $c) { |
|
668 | + return new TempManager( |
|
669 | + $c->getLogger(), |
|
670 | + $c->getConfig() |
|
671 | + ); |
|
672 | + }); |
|
673 | + $this->registerAlias('TempManager', TempManager::class); |
|
674 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
675 | + |
|
676 | + $this->registerService(AppManager::class, function (Server $c) { |
|
677 | + return new \OC\App\AppManager( |
|
678 | + $c->getUserSession(), |
|
679 | + $c->query(\OC\AppConfig::class), |
|
680 | + $c->getGroupManager(), |
|
681 | + $c->getMemCacheFactory(), |
|
682 | + $c->getEventDispatcher() |
|
683 | + ); |
|
684 | + }); |
|
685 | + $this->registerAlias('AppManager', AppManager::class); |
|
686 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
687 | + |
|
688 | + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
689 | + return new DateTimeZone( |
|
690 | + $c->getConfig(), |
|
691 | + $c->getSession() |
|
692 | + ); |
|
693 | + }); |
|
694 | + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
695 | + |
|
696 | + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
697 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
698 | + |
|
699 | + return new DateTimeFormatter( |
|
700 | + $c->getDateTimeZone()->getTimeZone(), |
|
701 | + $c->getL10N('lib', $language) |
|
702 | + ); |
|
703 | + }); |
|
704 | + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
705 | + |
|
706 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
707 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
708 | + $listener = new UserMountCacheListener($mountCache); |
|
709 | + $listener->listen($c->getUserManager()); |
|
710 | + return $mountCache; |
|
711 | + }); |
|
712 | + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
713 | + |
|
714 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
715 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
716 | + $mountCache = $c->query('UserMountCache'); |
|
717 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
718 | + |
|
719 | + // builtin providers |
|
720 | + |
|
721 | + $config = $c->getConfig(); |
|
722 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
723 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
724 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
725 | + |
|
726 | + return $manager; |
|
727 | + }); |
|
728 | + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
729 | + |
|
730 | + $this->registerService('IniWrapper', function ($c) { |
|
731 | + return new IniGetWrapper(); |
|
732 | + }); |
|
733 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
734 | + $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
735 | + if ($busClass) { |
|
736 | + list($app, $class) = explode('::', $busClass, 2); |
|
737 | + if ($c->getAppManager()->isInstalled($app)) { |
|
738 | + \OC_App::loadApp($app); |
|
739 | + return $c->query($class); |
|
740 | + } else { |
|
741 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
742 | + } |
|
743 | + } else { |
|
744 | + $jobList = $c->getJobList(); |
|
745 | + return new CronBus($jobList); |
|
746 | + } |
|
747 | + }); |
|
748 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
749 | + return new TrustedDomainHelper($this->getConfig()); |
|
750 | + }); |
|
751 | + $this->registerService('Throttler', function (Server $c) { |
|
752 | + return new Throttler( |
|
753 | + $c->getDatabaseConnection(), |
|
754 | + new TimeFactory(), |
|
755 | + $c->getLogger(), |
|
756 | + $c->getConfig() |
|
757 | + ); |
|
758 | + }); |
|
759 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
760 | + // IConfig and IAppManager requires a working database. This code |
|
761 | + // might however be called when ownCloud is not yet setup. |
|
762 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
763 | + $config = $c->getConfig(); |
|
764 | + $appManager = $c->getAppManager(); |
|
765 | + } else { |
|
766 | + $config = null; |
|
767 | + $appManager = null; |
|
768 | + } |
|
769 | + |
|
770 | + return new Checker( |
|
771 | + new EnvironmentHelper(), |
|
772 | + new FileAccessHelper(), |
|
773 | + new AppLocator(), |
|
774 | + $config, |
|
775 | + $c->getMemCacheFactory(), |
|
776 | + $appManager, |
|
777 | + $c->getTempManager() |
|
778 | + ); |
|
779 | + }); |
|
780 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
781 | + if (isset($this['urlParams'])) { |
|
782 | + $urlParams = $this['urlParams']; |
|
783 | + } else { |
|
784 | + $urlParams = []; |
|
785 | + } |
|
786 | + |
|
787 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
788 | + && in_array('fakeinput', stream_get_wrappers()) |
|
789 | + ) { |
|
790 | + $stream = 'fakeinput://data'; |
|
791 | + } else { |
|
792 | + $stream = 'php://input'; |
|
793 | + } |
|
794 | + |
|
795 | + return new Request( |
|
796 | + [ |
|
797 | + 'get' => $_GET, |
|
798 | + 'post' => $_POST, |
|
799 | + 'files' => $_FILES, |
|
800 | + 'server' => $_SERVER, |
|
801 | + 'env' => $_ENV, |
|
802 | + 'cookies' => $_COOKIE, |
|
803 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
804 | + ? $_SERVER['REQUEST_METHOD'] |
|
805 | + : '', |
|
806 | + 'urlParams' => $urlParams, |
|
807 | + ], |
|
808 | + $this->getSecureRandom(), |
|
809 | + $this->getConfig(), |
|
810 | + $this->getCsrfTokenManager(), |
|
811 | + $stream |
|
812 | + ); |
|
813 | + }); |
|
814 | + $this->registerAlias('Request', \OCP\IRequest::class); |
|
815 | + |
|
816 | + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
817 | + return new Mailer( |
|
818 | + $c->getConfig(), |
|
819 | + $c->getLogger(), |
|
820 | + $c->query(Defaults::class), |
|
821 | + $c->getURLGenerator(), |
|
822 | + $c->getL10N('lib') |
|
823 | + ); |
|
824 | + }); |
|
825 | + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
826 | + |
|
827 | + $this->registerService('LDAPProvider', function (Server $c) { |
|
828 | + $config = $c->getConfig(); |
|
829 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
830 | + if (is_null($factoryClass)) { |
|
831 | + throw new \Exception('ldapProviderFactory not set'); |
|
832 | + } |
|
833 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
834 | + $factory = new $factoryClass($this); |
|
835 | + return $factory->getLDAPProvider(); |
|
836 | + }); |
|
837 | + $this->registerService(ILockingProvider::class, function (Server $c) { |
|
838 | + $ini = $c->getIniWrapper(); |
|
839 | + $config = $c->getConfig(); |
|
840 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
841 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
842 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
843 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
844 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
845 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
846 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
847 | + } |
|
848 | + return new DBLockingProvider( |
|
849 | + $c->getDatabaseConnection(), |
|
850 | + $c->getLogger(), |
|
851 | + new TimeFactory(), |
|
852 | + $ttl, |
|
853 | + !\OC::$CLI |
|
854 | + ); |
|
855 | + } |
|
856 | + return new NoopLockingProvider(); |
|
857 | + }); |
|
858 | + $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
859 | + |
|
860 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
861 | + return new \OC\Files\Mount\Manager(); |
|
862 | + }); |
|
863 | + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
864 | + |
|
865 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
866 | + return new \OC\Files\Type\Detection( |
|
867 | + $c->getURLGenerator(), |
|
868 | + \OC::$configDir, |
|
869 | + \OC::$SERVERROOT . '/resources/config/' |
|
870 | + ); |
|
871 | + }); |
|
872 | + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
873 | + |
|
874 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
875 | + return new \OC\Files\Type\Loader( |
|
876 | + $c->getDatabaseConnection() |
|
877 | + ); |
|
878 | + }); |
|
879 | + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
880 | + $this->registerService(BundleFetcher::class, function () { |
|
881 | + return new BundleFetcher($this->getL10N('lib')); |
|
882 | + }); |
|
883 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
884 | + return new Manager( |
|
885 | + $c->query(IValidator::class) |
|
886 | + ); |
|
887 | + }); |
|
888 | + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
889 | + |
|
890 | + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
891 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
892 | + $manager->registerCapability(function () use ($c) { |
|
893 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
894 | + }); |
|
895 | + $manager->registerCapability(function () use ($c) { |
|
896 | + return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
897 | + }); |
|
898 | + return $manager; |
|
899 | + }); |
|
900 | + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
901 | + |
|
902 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
903 | + $config = $c->getConfig(); |
|
904 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
905 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
906 | + $factory = new $factoryClass($this); |
|
907 | + $manager = $factory->getManager(); |
|
908 | + |
|
909 | + $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
910 | + $manager = $c->getUserManager(); |
|
911 | + $user = $manager->get($id); |
|
912 | + if(is_null($user)) { |
|
913 | + $l = $c->getL10N('core'); |
|
914 | + $displayName = $l->t('Unknown user'); |
|
915 | + } else { |
|
916 | + $displayName = $user->getDisplayName(); |
|
917 | + } |
|
918 | + return $displayName; |
|
919 | + }); |
|
920 | + |
|
921 | + return $manager; |
|
922 | + }); |
|
923 | + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
924 | + |
|
925 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
926 | + /* |
|
927 | 927 | * Dark magic for autoloader. |
928 | 928 | * If we do a class_exists it will try to load the class which will |
929 | 929 | * make composer cache the result. Resulting in errors when enabling |
930 | 930 | * the theming app. |
931 | 931 | */ |
932 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
933 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
934 | - $classExists = true; |
|
935 | - } else { |
|
936 | - $classExists = false; |
|
937 | - } |
|
938 | - |
|
939 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
940 | - return new ThemingDefaults( |
|
941 | - $c->getConfig(), |
|
942 | - $c->getL10N('theming'), |
|
943 | - $c->getURLGenerator(), |
|
944 | - $c->getMemCacheFactory(), |
|
945 | - new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
946 | - new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()), |
|
947 | - $c->getAppManager() |
|
948 | - ); |
|
949 | - } |
|
950 | - return new \OC_Defaults(); |
|
951 | - }); |
|
952 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
953 | - /** @var Factory $cacheFactory */ |
|
954 | - $cacheFactory = $c->query(Factory::class); |
|
955 | - return new SCSSCacher( |
|
956 | - $c->getLogger(), |
|
957 | - $c->query(\OC\Files\AppData\Factory::class), |
|
958 | - $c->getURLGenerator(), |
|
959 | - $c->getConfig(), |
|
960 | - $c->getThemingDefaults(), |
|
961 | - \OC::$SERVERROOT, |
|
962 | - $this->getMemCacheFactory() |
|
963 | - ); |
|
964 | - }); |
|
965 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
966 | - /** @var Factory $cacheFactory */ |
|
967 | - $cacheFactory = $c->query(Factory::class); |
|
968 | - return new JSCombiner( |
|
969 | - $c->getAppDataDir('js'), |
|
970 | - $c->getURLGenerator(), |
|
971 | - $this->getMemCacheFactory(), |
|
972 | - $c->getSystemConfig(), |
|
973 | - $c->getLogger() |
|
974 | - ); |
|
975 | - }); |
|
976 | - $this->registerService(EventDispatcher::class, function () { |
|
977 | - return new EventDispatcher(); |
|
978 | - }); |
|
979 | - $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
980 | - $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
981 | - |
|
982 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
983 | - // FIXME: Instantiiated here due to cyclic dependency |
|
984 | - $request = new Request( |
|
985 | - [ |
|
986 | - 'get' => $_GET, |
|
987 | - 'post' => $_POST, |
|
988 | - 'files' => $_FILES, |
|
989 | - 'server' => $_SERVER, |
|
990 | - 'env' => $_ENV, |
|
991 | - 'cookies' => $_COOKIE, |
|
992 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
993 | - ? $_SERVER['REQUEST_METHOD'] |
|
994 | - : null, |
|
995 | - ], |
|
996 | - $c->getSecureRandom(), |
|
997 | - $c->getConfig() |
|
998 | - ); |
|
999 | - |
|
1000 | - return new CryptoWrapper( |
|
1001 | - $c->getConfig(), |
|
1002 | - $c->getCrypto(), |
|
1003 | - $c->getSecureRandom(), |
|
1004 | - $request |
|
1005 | - ); |
|
1006 | - }); |
|
1007 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
1008 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
1009 | - |
|
1010 | - return new CsrfTokenManager( |
|
1011 | - $tokenGenerator, |
|
1012 | - $c->query(SessionStorage::class) |
|
1013 | - ); |
|
1014 | - }); |
|
1015 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
1016 | - return new SessionStorage($c->getSession()); |
|
1017 | - }); |
|
1018 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1019 | - return new ContentSecurityPolicyManager(); |
|
1020 | - }); |
|
1021 | - $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
1022 | - |
|
1023 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1024 | - return new ContentSecurityPolicyNonceManager( |
|
1025 | - $c->getCsrfTokenManager(), |
|
1026 | - $c->getRequest() |
|
1027 | - ); |
|
1028 | - }); |
|
1029 | - |
|
1030 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1031 | - $config = $c->getConfig(); |
|
1032 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1033 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
1034 | - $factory = new $factoryClass($this); |
|
1035 | - |
|
1036 | - $manager = new \OC\Share20\Manager( |
|
1037 | - $c->getLogger(), |
|
1038 | - $c->getConfig(), |
|
1039 | - $c->getSecureRandom(), |
|
1040 | - $c->getHasher(), |
|
1041 | - $c->getMountManager(), |
|
1042 | - $c->getGroupManager(), |
|
1043 | - $c->getL10N('lib'), |
|
1044 | - $c->getL10NFactory(), |
|
1045 | - $factory, |
|
1046 | - $c->getUserManager(), |
|
1047 | - $c->getLazyRootFolder(), |
|
1048 | - $c->getEventDispatcher(), |
|
1049 | - $c->getMailer(), |
|
1050 | - $c->getURLGenerator(), |
|
1051 | - $c->getThemingDefaults() |
|
1052 | - ); |
|
1053 | - |
|
1054 | - return $manager; |
|
1055 | - }); |
|
1056 | - $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1057 | - |
|
1058 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1059 | - $instance = new Collaboration\Collaborators\Search($c); |
|
1060 | - |
|
1061 | - // register default plugins |
|
1062 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1063 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1064 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1065 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1066 | - |
|
1067 | - return $instance; |
|
1068 | - }); |
|
1069 | - $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1070 | - |
|
1071 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1072 | - |
|
1073 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1074 | - $manager = new \OC\Settings\Manager( |
|
1075 | - $c->getLogger(), |
|
1076 | - $c->getDatabaseConnection(), |
|
1077 | - $c->getL10N('lib'), |
|
1078 | - $c->getConfig(), |
|
1079 | - $c->getEncryptionManager(), |
|
1080 | - $c->getUserManager(), |
|
1081 | - $c->getLockingProvider(), |
|
1082 | - $c->getRequest(), |
|
1083 | - $c->getURLGenerator(), |
|
1084 | - $c->query(AccountManager::class), |
|
1085 | - $c->getGroupManager(), |
|
1086 | - $c->getL10NFactory(), |
|
1087 | - $c->getAppManager() |
|
1088 | - ); |
|
1089 | - return $manager; |
|
1090 | - }); |
|
1091 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1092 | - return new \OC\Files\AppData\Factory( |
|
1093 | - $c->getRootFolder(), |
|
1094 | - $c->getSystemConfig() |
|
1095 | - ); |
|
1096 | - }); |
|
1097 | - |
|
1098 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1099 | - return new LockdownManager(function () use ($c) { |
|
1100 | - return $c->getSession(); |
|
1101 | - }); |
|
1102 | - }); |
|
1103 | - |
|
1104 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1105 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1106 | - }); |
|
1107 | - |
|
1108 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1109 | - return new CloudIdManager(); |
|
1110 | - }); |
|
1111 | - |
|
1112 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1113 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1114 | - |
|
1115 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1116 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1117 | - |
|
1118 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1119 | - return new Defaults( |
|
1120 | - $c->getThemingDefaults() |
|
1121 | - ); |
|
1122 | - }); |
|
1123 | - $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1124 | - |
|
1125 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1126 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1127 | - }); |
|
1128 | - |
|
1129 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1130 | - return new ShareHelper( |
|
1131 | - $c->query(\OCP\Share\IManager::class) |
|
1132 | - ); |
|
1133 | - }); |
|
1134 | - |
|
1135 | - $this->registerService(Installer::class, function(Server $c) { |
|
1136 | - return new Installer( |
|
1137 | - $c->getAppFetcher(), |
|
1138 | - $c->getHTTPClientService(), |
|
1139 | - $c->getTempManager(), |
|
1140 | - $c->getLogger(), |
|
1141 | - $c->getConfig() |
|
1142 | - ); |
|
1143 | - }); |
|
1144 | - |
|
1145 | - $this->registerService(IApiFactory::class, function(Server $c) { |
|
1146 | - return new ApiFactory($c->getHTTPClientService()); |
|
1147 | - }); |
|
1148 | - |
|
1149 | - $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
1150 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
1151 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1152 | - }); |
|
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 | - |
|
1164 | - $this->connectDispatcher(); |
|
1165 | - } |
|
1166 | - |
|
1167 | - /** |
|
1168 | - * @return \OCP\Calendar\IManager |
|
1169 | - */ |
|
1170 | - public function getCalendarManager() { |
|
1171 | - return $this->query('CalendarManager'); |
|
1172 | - } |
|
1173 | - |
|
1174 | - private function connectDispatcher() { |
|
1175 | - $dispatcher = $this->getEventDispatcher(); |
|
1176 | - |
|
1177 | - // Delete avatar on user deletion |
|
1178 | - $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1179 | - $logger = $this->getLogger(); |
|
1180 | - $manager = $this->getAvatarManager(); |
|
1181 | - /** @var IUser $user */ |
|
1182 | - $user = $e->getSubject(); |
|
1183 | - |
|
1184 | - try { |
|
1185 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1186 | - $avatar->remove(); |
|
1187 | - } catch (NotFoundException $e) { |
|
1188 | - // no avatar to remove |
|
1189 | - } catch (\Exception $e) { |
|
1190 | - // Ignore exceptions |
|
1191 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1192 | - } |
|
1193 | - }); |
|
1194 | - |
|
1195 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1196 | - $manager = $this->getAvatarManager(); |
|
1197 | - /** @var IUser $user */ |
|
1198 | - $user = $e->getSubject(); |
|
1199 | - $feature = $e->getArgument('feature'); |
|
1200 | - $oldValue = $e->getArgument('oldValue'); |
|
1201 | - $value = $e->getArgument('value'); |
|
1202 | - |
|
1203 | - try { |
|
1204 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1205 | - $avatar->userChanged($feature, $oldValue, $value); |
|
1206 | - } catch (NotFoundException $e) { |
|
1207 | - // no avatar to remove |
|
1208 | - } |
|
1209 | - }); |
|
1210 | - } |
|
1211 | - |
|
1212 | - /** |
|
1213 | - * @return \OCP\Contacts\IManager |
|
1214 | - */ |
|
1215 | - public function getContactsManager() { |
|
1216 | - return $this->query('ContactsManager'); |
|
1217 | - } |
|
1218 | - |
|
1219 | - /** |
|
1220 | - * @return \OC\Encryption\Manager |
|
1221 | - */ |
|
1222 | - public function getEncryptionManager() { |
|
1223 | - return $this->query('EncryptionManager'); |
|
1224 | - } |
|
1225 | - |
|
1226 | - /** |
|
1227 | - * @return \OC\Encryption\File |
|
1228 | - */ |
|
1229 | - public function getEncryptionFilesHelper() { |
|
1230 | - return $this->query('EncryptionFileHelper'); |
|
1231 | - } |
|
1232 | - |
|
1233 | - /** |
|
1234 | - * @return \OCP\Encryption\Keys\IStorage |
|
1235 | - */ |
|
1236 | - public function getEncryptionKeyStorage() { |
|
1237 | - return $this->query('EncryptionKeyStorage'); |
|
1238 | - } |
|
1239 | - |
|
1240 | - /** |
|
1241 | - * The current request object holding all information about the request |
|
1242 | - * currently being processed is returned from this method. |
|
1243 | - * In case the current execution was not initiated by a web request null is returned |
|
1244 | - * |
|
1245 | - * @return \OCP\IRequest |
|
1246 | - */ |
|
1247 | - public function getRequest() { |
|
1248 | - return $this->query('Request'); |
|
1249 | - } |
|
1250 | - |
|
1251 | - /** |
|
1252 | - * Returns the preview manager which can create preview images for a given file |
|
1253 | - * |
|
1254 | - * @return \OCP\IPreview |
|
1255 | - */ |
|
1256 | - public function getPreviewManager() { |
|
1257 | - return $this->query('PreviewManager'); |
|
1258 | - } |
|
1259 | - |
|
1260 | - /** |
|
1261 | - * Returns the tag manager which can get and set tags for different object types |
|
1262 | - * |
|
1263 | - * @see \OCP\ITagManager::load() |
|
1264 | - * @return \OCP\ITagManager |
|
1265 | - */ |
|
1266 | - public function getTagManager() { |
|
1267 | - return $this->query('TagManager'); |
|
1268 | - } |
|
1269 | - |
|
1270 | - /** |
|
1271 | - * Returns the system-tag manager |
|
1272 | - * |
|
1273 | - * @return \OCP\SystemTag\ISystemTagManager |
|
1274 | - * |
|
1275 | - * @since 9.0.0 |
|
1276 | - */ |
|
1277 | - public function getSystemTagManager() { |
|
1278 | - return $this->query('SystemTagManager'); |
|
1279 | - } |
|
1280 | - |
|
1281 | - /** |
|
1282 | - * Returns the system-tag object mapper |
|
1283 | - * |
|
1284 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1285 | - * |
|
1286 | - * @since 9.0.0 |
|
1287 | - */ |
|
1288 | - public function getSystemTagObjectMapper() { |
|
1289 | - return $this->query('SystemTagObjectMapper'); |
|
1290 | - } |
|
1291 | - |
|
1292 | - /** |
|
1293 | - * Returns the avatar manager, used for avatar functionality |
|
1294 | - * |
|
1295 | - * @return \OCP\IAvatarManager |
|
1296 | - */ |
|
1297 | - public function getAvatarManager() { |
|
1298 | - return $this->query('AvatarManager'); |
|
1299 | - } |
|
1300 | - |
|
1301 | - /** |
|
1302 | - * Returns the root folder of ownCloud's data directory |
|
1303 | - * |
|
1304 | - * @return \OCP\Files\IRootFolder |
|
1305 | - */ |
|
1306 | - public function getRootFolder() { |
|
1307 | - return $this->query('LazyRootFolder'); |
|
1308 | - } |
|
1309 | - |
|
1310 | - /** |
|
1311 | - * Returns the root folder of ownCloud's data directory |
|
1312 | - * This is the lazy variant so this gets only initialized once it |
|
1313 | - * is actually used. |
|
1314 | - * |
|
1315 | - * @return \OCP\Files\IRootFolder |
|
1316 | - */ |
|
1317 | - public function getLazyRootFolder() { |
|
1318 | - return $this->query('LazyRootFolder'); |
|
1319 | - } |
|
1320 | - |
|
1321 | - /** |
|
1322 | - * Returns a view to ownCloud's files folder |
|
1323 | - * |
|
1324 | - * @param string $userId user ID |
|
1325 | - * @return \OCP\Files\Folder|null |
|
1326 | - */ |
|
1327 | - public function getUserFolder($userId = null) { |
|
1328 | - if ($userId === null) { |
|
1329 | - $user = $this->getUserSession()->getUser(); |
|
1330 | - if (!$user) { |
|
1331 | - return null; |
|
1332 | - } |
|
1333 | - $userId = $user->getUID(); |
|
1334 | - } |
|
1335 | - $root = $this->getRootFolder(); |
|
1336 | - return $root->getUserFolder($userId); |
|
1337 | - } |
|
1338 | - |
|
1339 | - /** |
|
1340 | - * Returns an app-specific view in ownClouds data directory |
|
1341 | - * |
|
1342 | - * @return \OCP\Files\Folder |
|
1343 | - * @deprecated since 9.2.0 use IAppData |
|
1344 | - */ |
|
1345 | - public function getAppFolder() { |
|
1346 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1347 | - $root = $this->getRootFolder(); |
|
1348 | - if (!$root->nodeExists($dir)) { |
|
1349 | - $folder = $root->newFolder($dir); |
|
1350 | - } else { |
|
1351 | - $folder = $root->get($dir); |
|
1352 | - } |
|
1353 | - return $folder; |
|
1354 | - } |
|
1355 | - |
|
1356 | - /** |
|
1357 | - * @return \OC\User\Manager |
|
1358 | - */ |
|
1359 | - public function getUserManager() { |
|
1360 | - return $this->query('UserManager'); |
|
1361 | - } |
|
1362 | - |
|
1363 | - /** |
|
1364 | - * @return \OC\Group\Manager |
|
1365 | - */ |
|
1366 | - public function getGroupManager() { |
|
1367 | - return $this->query('GroupManager'); |
|
1368 | - } |
|
1369 | - |
|
1370 | - /** |
|
1371 | - * @return \OC\User\Session |
|
1372 | - */ |
|
1373 | - public function getUserSession() { |
|
1374 | - return $this->query('UserSession'); |
|
1375 | - } |
|
1376 | - |
|
1377 | - /** |
|
1378 | - * @return \OCP\ISession |
|
1379 | - */ |
|
1380 | - public function getSession() { |
|
1381 | - return $this->query('UserSession')->getSession(); |
|
1382 | - } |
|
1383 | - |
|
1384 | - /** |
|
1385 | - * @param \OCP\ISession $session |
|
1386 | - */ |
|
1387 | - public function setSession(\OCP\ISession $session) { |
|
1388 | - $this->query(SessionStorage::class)->setSession($session); |
|
1389 | - $this->query('UserSession')->setSession($session); |
|
1390 | - $this->query(Store::class)->setSession($session); |
|
1391 | - } |
|
1392 | - |
|
1393 | - /** |
|
1394 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1395 | - */ |
|
1396 | - public function getTwoFactorAuthManager() { |
|
1397 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1398 | - } |
|
1399 | - |
|
1400 | - /** |
|
1401 | - * @return \OC\NavigationManager |
|
1402 | - */ |
|
1403 | - public function getNavigationManager() { |
|
1404 | - return $this->query('NavigationManager'); |
|
1405 | - } |
|
1406 | - |
|
1407 | - /** |
|
1408 | - * @return \OCP\IConfig |
|
1409 | - */ |
|
1410 | - public function getConfig() { |
|
1411 | - return $this->query('AllConfig'); |
|
1412 | - } |
|
1413 | - |
|
1414 | - /** |
|
1415 | - * @return \OC\SystemConfig |
|
1416 | - */ |
|
1417 | - public function getSystemConfig() { |
|
1418 | - return $this->query('SystemConfig'); |
|
1419 | - } |
|
1420 | - |
|
1421 | - /** |
|
1422 | - * Returns the app config manager |
|
1423 | - * |
|
1424 | - * @return \OCP\IAppConfig |
|
1425 | - */ |
|
1426 | - public function getAppConfig() { |
|
1427 | - return $this->query('AppConfig'); |
|
1428 | - } |
|
1429 | - |
|
1430 | - /** |
|
1431 | - * @return \OCP\L10N\IFactory |
|
1432 | - */ |
|
1433 | - public function getL10NFactory() { |
|
1434 | - return $this->query('L10NFactory'); |
|
1435 | - } |
|
1436 | - |
|
1437 | - /** |
|
1438 | - * get an L10N instance |
|
1439 | - * |
|
1440 | - * @param string $app appid |
|
1441 | - * @param string $lang |
|
1442 | - * @return IL10N |
|
1443 | - */ |
|
1444 | - public function getL10N($app, $lang = null) { |
|
1445 | - return $this->getL10NFactory()->get($app, $lang); |
|
1446 | - } |
|
1447 | - |
|
1448 | - /** |
|
1449 | - * @return \OCP\IURLGenerator |
|
1450 | - */ |
|
1451 | - public function getURLGenerator() { |
|
1452 | - return $this->query('URLGenerator'); |
|
1453 | - } |
|
1454 | - |
|
1455 | - /** |
|
1456 | - * @return AppFetcher |
|
1457 | - */ |
|
1458 | - public function getAppFetcher() { |
|
1459 | - return $this->query(AppFetcher::class); |
|
1460 | - } |
|
1461 | - |
|
1462 | - /** |
|
1463 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1464 | - * getMemCacheFactory() instead. |
|
1465 | - * |
|
1466 | - * @return \OCP\ICache |
|
1467 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1468 | - */ |
|
1469 | - public function getCache() { |
|
1470 | - return $this->query('UserCache'); |
|
1471 | - } |
|
1472 | - |
|
1473 | - /** |
|
1474 | - * Returns an \OCP\CacheFactory instance |
|
1475 | - * |
|
1476 | - * @return \OCP\ICacheFactory |
|
1477 | - */ |
|
1478 | - public function getMemCacheFactory() { |
|
1479 | - return $this->query('MemCacheFactory'); |
|
1480 | - } |
|
1481 | - |
|
1482 | - /** |
|
1483 | - * Returns an \OC\RedisFactory instance |
|
1484 | - * |
|
1485 | - * @return \OC\RedisFactory |
|
1486 | - */ |
|
1487 | - public function getGetRedisFactory() { |
|
1488 | - return $this->query('RedisFactory'); |
|
1489 | - } |
|
1490 | - |
|
1491 | - |
|
1492 | - /** |
|
1493 | - * Returns the current session |
|
1494 | - * |
|
1495 | - * @return \OCP\IDBConnection |
|
1496 | - */ |
|
1497 | - public function getDatabaseConnection() { |
|
1498 | - return $this->query('DatabaseConnection'); |
|
1499 | - } |
|
1500 | - |
|
1501 | - /** |
|
1502 | - * Returns the activity manager |
|
1503 | - * |
|
1504 | - * @return \OCP\Activity\IManager |
|
1505 | - */ |
|
1506 | - public function getActivityManager() { |
|
1507 | - return $this->query('ActivityManager'); |
|
1508 | - } |
|
1509 | - |
|
1510 | - /** |
|
1511 | - * Returns an job list for controlling background jobs |
|
1512 | - * |
|
1513 | - * @return \OCP\BackgroundJob\IJobList |
|
1514 | - */ |
|
1515 | - public function getJobList() { |
|
1516 | - return $this->query('JobList'); |
|
1517 | - } |
|
1518 | - |
|
1519 | - /** |
|
1520 | - * Returns a logger instance |
|
1521 | - * |
|
1522 | - * @return \OCP\ILogger |
|
1523 | - */ |
|
1524 | - public function getLogger() { |
|
1525 | - return $this->query('Logger'); |
|
1526 | - } |
|
1527 | - |
|
1528 | - /** |
|
1529 | - * @return ILogFactory |
|
1530 | - * @throws \OCP\AppFramework\QueryException |
|
1531 | - */ |
|
1532 | - public function getLogFactory() { |
|
1533 | - return $this->query(ILogFactory::class); |
|
1534 | - } |
|
1535 | - |
|
1536 | - /** |
|
1537 | - * Returns a router for generating and matching urls |
|
1538 | - * |
|
1539 | - * @return \OCP\Route\IRouter |
|
1540 | - */ |
|
1541 | - public function getRouter() { |
|
1542 | - return $this->query('Router'); |
|
1543 | - } |
|
1544 | - |
|
1545 | - /** |
|
1546 | - * Returns a search instance |
|
1547 | - * |
|
1548 | - * @return \OCP\ISearch |
|
1549 | - */ |
|
1550 | - public function getSearch() { |
|
1551 | - return $this->query('Search'); |
|
1552 | - } |
|
1553 | - |
|
1554 | - /** |
|
1555 | - * Returns a SecureRandom instance |
|
1556 | - * |
|
1557 | - * @return \OCP\Security\ISecureRandom |
|
1558 | - */ |
|
1559 | - public function getSecureRandom() { |
|
1560 | - return $this->query('SecureRandom'); |
|
1561 | - } |
|
1562 | - |
|
1563 | - /** |
|
1564 | - * Returns a Crypto instance |
|
1565 | - * |
|
1566 | - * @return \OCP\Security\ICrypto |
|
1567 | - */ |
|
1568 | - public function getCrypto() { |
|
1569 | - return $this->query('Crypto'); |
|
1570 | - } |
|
1571 | - |
|
1572 | - /** |
|
1573 | - * Returns a Hasher instance |
|
1574 | - * |
|
1575 | - * @return \OCP\Security\IHasher |
|
1576 | - */ |
|
1577 | - public function getHasher() { |
|
1578 | - return $this->query('Hasher'); |
|
1579 | - } |
|
1580 | - |
|
1581 | - /** |
|
1582 | - * Returns a CredentialsManager instance |
|
1583 | - * |
|
1584 | - * @return \OCP\Security\ICredentialsManager |
|
1585 | - */ |
|
1586 | - public function getCredentialsManager() { |
|
1587 | - return $this->query('CredentialsManager'); |
|
1588 | - } |
|
1589 | - |
|
1590 | - /** |
|
1591 | - * Get the certificate manager for the user |
|
1592 | - * |
|
1593 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1594 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1595 | - */ |
|
1596 | - public function getCertificateManager($userId = '') { |
|
1597 | - if ($userId === '') { |
|
1598 | - $userSession = $this->getUserSession(); |
|
1599 | - $user = $userSession->getUser(); |
|
1600 | - if (is_null($user)) { |
|
1601 | - return null; |
|
1602 | - } |
|
1603 | - $userId = $user->getUID(); |
|
1604 | - } |
|
1605 | - return new CertificateManager( |
|
1606 | - $userId, |
|
1607 | - new View(), |
|
1608 | - $this->getConfig(), |
|
1609 | - $this->getLogger(), |
|
1610 | - $this->getSecureRandom() |
|
1611 | - ); |
|
1612 | - } |
|
1613 | - |
|
1614 | - /** |
|
1615 | - * Returns an instance of the HTTP client service |
|
1616 | - * |
|
1617 | - * @return \OCP\Http\Client\IClientService |
|
1618 | - */ |
|
1619 | - public function getHTTPClientService() { |
|
1620 | - return $this->query('HttpClientService'); |
|
1621 | - } |
|
1622 | - |
|
1623 | - /** |
|
1624 | - * Create a new event source |
|
1625 | - * |
|
1626 | - * @return \OCP\IEventSource |
|
1627 | - */ |
|
1628 | - public function createEventSource() { |
|
1629 | - return new \OC_EventSource(); |
|
1630 | - } |
|
1631 | - |
|
1632 | - /** |
|
1633 | - * Get the active event logger |
|
1634 | - * |
|
1635 | - * The returned logger only logs data when debug mode is enabled |
|
1636 | - * |
|
1637 | - * @return \OCP\Diagnostics\IEventLogger |
|
1638 | - */ |
|
1639 | - public function getEventLogger() { |
|
1640 | - return $this->query('EventLogger'); |
|
1641 | - } |
|
1642 | - |
|
1643 | - /** |
|
1644 | - * Get the active query logger |
|
1645 | - * |
|
1646 | - * The returned logger only logs data when debug mode is enabled |
|
1647 | - * |
|
1648 | - * @return \OCP\Diagnostics\IQueryLogger |
|
1649 | - */ |
|
1650 | - public function getQueryLogger() { |
|
1651 | - return $this->query('QueryLogger'); |
|
1652 | - } |
|
1653 | - |
|
1654 | - /** |
|
1655 | - * Get the manager for temporary files and folders |
|
1656 | - * |
|
1657 | - * @return \OCP\ITempManager |
|
1658 | - */ |
|
1659 | - public function getTempManager() { |
|
1660 | - return $this->query('TempManager'); |
|
1661 | - } |
|
1662 | - |
|
1663 | - /** |
|
1664 | - * Get the app manager |
|
1665 | - * |
|
1666 | - * @return \OCP\App\IAppManager |
|
1667 | - */ |
|
1668 | - public function getAppManager() { |
|
1669 | - return $this->query('AppManager'); |
|
1670 | - } |
|
1671 | - |
|
1672 | - /** |
|
1673 | - * Creates a new mailer |
|
1674 | - * |
|
1675 | - * @return \OCP\Mail\IMailer |
|
1676 | - */ |
|
1677 | - public function getMailer() { |
|
1678 | - return $this->query('Mailer'); |
|
1679 | - } |
|
1680 | - |
|
1681 | - /** |
|
1682 | - * Get the webroot |
|
1683 | - * |
|
1684 | - * @return string |
|
1685 | - */ |
|
1686 | - public function getWebRoot() { |
|
1687 | - return $this->webRoot; |
|
1688 | - } |
|
1689 | - |
|
1690 | - /** |
|
1691 | - * @return \OC\OCSClient |
|
1692 | - */ |
|
1693 | - public function getOcsClient() { |
|
1694 | - return $this->query('OcsClient'); |
|
1695 | - } |
|
1696 | - |
|
1697 | - /** |
|
1698 | - * @return \OCP\IDateTimeZone |
|
1699 | - */ |
|
1700 | - public function getDateTimeZone() { |
|
1701 | - return $this->query('DateTimeZone'); |
|
1702 | - } |
|
1703 | - |
|
1704 | - /** |
|
1705 | - * @return \OCP\IDateTimeFormatter |
|
1706 | - */ |
|
1707 | - public function getDateTimeFormatter() { |
|
1708 | - return $this->query('DateTimeFormatter'); |
|
1709 | - } |
|
1710 | - |
|
1711 | - /** |
|
1712 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
1713 | - */ |
|
1714 | - public function getMountProviderCollection() { |
|
1715 | - return $this->query('MountConfigManager'); |
|
1716 | - } |
|
1717 | - |
|
1718 | - /** |
|
1719 | - * Get the IniWrapper |
|
1720 | - * |
|
1721 | - * @return IniGetWrapper |
|
1722 | - */ |
|
1723 | - public function getIniWrapper() { |
|
1724 | - return $this->query('IniWrapper'); |
|
1725 | - } |
|
1726 | - |
|
1727 | - /** |
|
1728 | - * @return \OCP\Command\IBus |
|
1729 | - */ |
|
1730 | - public function getCommandBus() { |
|
1731 | - return $this->query('AsyncCommandBus'); |
|
1732 | - } |
|
1733 | - |
|
1734 | - /** |
|
1735 | - * Get the trusted domain helper |
|
1736 | - * |
|
1737 | - * @return TrustedDomainHelper |
|
1738 | - */ |
|
1739 | - public function getTrustedDomainHelper() { |
|
1740 | - return $this->query('TrustedDomainHelper'); |
|
1741 | - } |
|
1742 | - |
|
1743 | - /** |
|
1744 | - * Get the locking provider |
|
1745 | - * |
|
1746 | - * @return \OCP\Lock\ILockingProvider |
|
1747 | - * @since 8.1.0 |
|
1748 | - */ |
|
1749 | - public function getLockingProvider() { |
|
1750 | - return $this->query('LockingProvider'); |
|
1751 | - } |
|
1752 | - |
|
1753 | - /** |
|
1754 | - * @return \OCP\Files\Mount\IMountManager |
|
1755 | - **/ |
|
1756 | - function getMountManager() { |
|
1757 | - return $this->query('MountManager'); |
|
1758 | - } |
|
1759 | - |
|
1760 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
1761 | - function getUserMountCache() { |
|
1762 | - return $this->query('UserMountCache'); |
|
1763 | - } |
|
1764 | - |
|
1765 | - /** |
|
1766 | - * Get the MimeTypeDetector |
|
1767 | - * |
|
1768 | - * @return \OCP\Files\IMimeTypeDetector |
|
1769 | - */ |
|
1770 | - public function getMimeTypeDetector() { |
|
1771 | - return $this->query('MimeTypeDetector'); |
|
1772 | - } |
|
1773 | - |
|
1774 | - /** |
|
1775 | - * Get the MimeTypeLoader |
|
1776 | - * |
|
1777 | - * @return \OCP\Files\IMimeTypeLoader |
|
1778 | - */ |
|
1779 | - public function getMimeTypeLoader() { |
|
1780 | - return $this->query('MimeTypeLoader'); |
|
1781 | - } |
|
1782 | - |
|
1783 | - /** |
|
1784 | - * Get the manager of all the capabilities |
|
1785 | - * |
|
1786 | - * @return \OC\CapabilitiesManager |
|
1787 | - */ |
|
1788 | - public function getCapabilitiesManager() { |
|
1789 | - return $this->query('CapabilitiesManager'); |
|
1790 | - } |
|
1791 | - |
|
1792 | - /** |
|
1793 | - * Get the EventDispatcher |
|
1794 | - * |
|
1795 | - * @return EventDispatcherInterface |
|
1796 | - * @since 8.2.0 |
|
1797 | - */ |
|
1798 | - public function getEventDispatcher() { |
|
1799 | - return $this->query('EventDispatcher'); |
|
1800 | - } |
|
1801 | - |
|
1802 | - /** |
|
1803 | - * Get the Notification Manager |
|
1804 | - * |
|
1805 | - * @return \OCP\Notification\IManager |
|
1806 | - * @since 8.2.0 |
|
1807 | - */ |
|
1808 | - public function getNotificationManager() { |
|
1809 | - return $this->query('NotificationManager'); |
|
1810 | - } |
|
1811 | - |
|
1812 | - /** |
|
1813 | - * @return \OCP\Comments\ICommentsManager |
|
1814 | - */ |
|
1815 | - public function getCommentsManager() { |
|
1816 | - return $this->query('CommentsManager'); |
|
1817 | - } |
|
1818 | - |
|
1819 | - /** |
|
1820 | - * @return \OCA\Theming\ThemingDefaults |
|
1821 | - */ |
|
1822 | - public function getThemingDefaults() { |
|
1823 | - return $this->query('ThemingDefaults'); |
|
1824 | - } |
|
1825 | - |
|
1826 | - /** |
|
1827 | - * @return \OC\IntegrityCheck\Checker |
|
1828 | - */ |
|
1829 | - public function getIntegrityCodeChecker() { |
|
1830 | - return $this->query('IntegrityCodeChecker'); |
|
1831 | - } |
|
1832 | - |
|
1833 | - /** |
|
1834 | - * @return \OC\Session\CryptoWrapper |
|
1835 | - */ |
|
1836 | - public function getSessionCryptoWrapper() { |
|
1837 | - return $this->query('CryptoWrapper'); |
|
1838 | - } |
|
1839 | - |
|
1840 | - /** |
|
1841 | - * @return CsrfTokenManager |
|
1842 | - */ |
|
1843 | - public function getCsrfTokenManager() { |
|
1844 | - return $this->query('CsrfTokenManager'); |
|
1845 | - } |
|
1846 | - |
|
1847 | - /** |
|
1848 | - * @return Throttler |
|
1849 | - */ |
|
1850 | - public function getBruteForceThrottler() { |
|
1851 | - return $this->query('Throttler'); |
|
1852 | - } |
|
1853 | - |
|
1854 | - /** |
|
1855 | - * @return IContentSecurityPolicyManager |
|
1856 | - */ |
|
1857 | - public function getContentSecurityPolicyManager() { |
|
1858 | - return $this->query('ContentSecurityPolicyManager'); |
|
1859 | - } |
|
1860 | - |
|
1861 | - /** |
|
1862 | - * @return ContentSecurityPolicyNonceManager |
|
1863 | - */ |
|
1864 | - public function getContentSecurityPolicyNonceManager() { |
|
1865 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
1866 | - } |
|
1867 | - |
|
1868 | - /** |
|
1869 | - * Not a public API as of 8.2, wait for 9.0 |
|
1870 | - * |
|
1871 | - * @return \OCA\Files_External\Service\BackendService |
|
1872 | - */ |
|
1873 | - public function getStoragesBackendService() { |
|
1874 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1875 | - } |
|
1876 | - |
|
1877 | - /** |
|
1878 | - * Not a public API as of 8.2, wait for 9.0 |
|
1879 | - * |
|
1880 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1881 | - */ |
|
1882 | - public function getGlobalStoragesService() { |
|
1883 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1884 | - } |
|
1885 | - |
|
1886 | - /** |
|
1887 | - * Not a public API as of 8.2, wait for 9.0 |
|
1888 | - * |
|
1889 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1890 | - */ |
|
1891 | - public function getUserGlobalStoragesService() { |
|
1892 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1893 | - } |
|
1894 | - |
|
1895 | - /** |
|
1896 | - * Not a public API as of 8.2, wait for 9.0 |
|
1897 | - * |
|
1898 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
1899 | - */ |
|
1900 | - public function getUserStoragesService() { |
|
1901 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1902 | - } |
|
1903 | - |
|
1904 | - /** |
|
1905 | - * @return \OCP\Share\IManager |
|
1906 | - */ |
|
1907 | - public function getShareManager() { |
|
1908 | - return $this->query('ShareManager'); |
|
1909 | - } |
|
1910 | - |
|
1911 | - /** |
|
1912 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
1913 | - */ |
|
1914 | - public function getCollaboratorSearch() { |
|
1915 | - return $this->query('CollaboratorSearch'); |
|
1916 | - } |
|
1917 | - |
|
1918 | - /** |
|
1919 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
1920 | - */ |
|
1921 | - public function getAutoCompleteManager(){ |
|
1922 | - return $this->query(IManager::class); |
|
1923 | - } |
|
1924 | - |
|
1925 | - /** |
|
1926 | - * Returns the LDAP Provider |
|
1927 | - * |
|
1928 | - * @return \OCP\LDAP\ILDAPProvider |
|
1929 | - */ |
|
1930 | - public function getLDAPProvider() { |
|
1931 | - return $this->query('LDAPProvider'); |
|
1932 | - } |
|
1933 | - |
|
1934 | - /** |
|
1935 | - * @return \OCP\Settings\IManager |
|
1936 | - */ |
|
1937 | - public function getSettingsManager() { |
|
1938 | - return $this->query('SettingsManager'); |
|
1939 | - } |
|
1940 | - |
|
1941 | - /** |
|
1942 | - * @return \OCP\Files\IAppData |
|
1943 | - */ |
|
1944 | - public function getAppDataDir($app) { |
|
1945 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
1946 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1947 | - return $factory->get($app); |
|
1948 | - } |
|
1949 | - |
|
1950 | - /** |
|
1951 | - * @return \OCP\Lockdown\ILockdownManager |
|
1952 | - */ |
|
1953 | - public function getLockdownManager() { |
|
1954 | - return $this->query('LockdownManager'); |
|
1955 | - } |
|
1956 | - |
|
1957 | - /** |
|
1958 | - * @return \OCP\Federation\ICloudIdManager |
|
1959 | - */ |
|
1960 | - public function getCloudIdManager() { |
|
1961 | - return $this->query(ICloudIdManager::class); |
|
1962 | - } |
|
1963 | - |
|
1964 | - /** |
|
1965 | - * @return \OCP\Remote\Api\IApiFactory |
|
1966 | - */ |
|
1967 | - public function getRemoteApiFactory() { |
|
1968 | - return $this->query(IApiFactory::class); |
|
1969 | - } |
|
1970 | - |
|
1971 | - /** |
|
1972 | - * @return \OCP\Remote\IInstanceFactory |
|
1973 | - */ |
|
1974 | - public function getRemoteInstanceFactory() { |
|
1975 | - return $this->query(IInstanceFactory::class); |
|
1976 | - } |
|
932 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
933 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
934 | + $classExists = true; |
|
935 | + } else { |
|
936 | + $classExists = false; |
|
937 | + } |
|
938 | + |
|
939 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
940 | + return new ThemingDefaults( |
|
941 | + $c->getConfig(), |
|
942 | + $c->getL10N('theming'), |
|
943 | + $c->getURLGenerator(), |
|
944 | + $c->getMemCacheFactory(), |
|
945 | + new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
946 | + new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()), |
|
947 | + $c->getAppManager() |
|
948 | + ); |
|
949 | + } |
|
950 | + return new \OC_Defaults(); |
|
951 | + }); |
|
952 | + $this->registerService(SCSSCacher::class, function (Server $c) { |
|
953 | + /** @var Factory $cacheFactory */ |
|
954 | + $cacheFactory = $c->query(Factory::class); |
|
955 | + return new SCSSCacher( |
|
956 | + $c->getLogger(), |
|
957 | + $c->query(\OC\Files\AppData\Factory::class), |
|
958 | + $c->getURLGenerator(), |
|
959 | + $c->getConfig(), |
|
960 | + $c->getThemingDefaults(), |
|
961 | + \OC::$SERVERROOT, |
|
962 | + $this->getMemCacheFactory() |
|
963 | + ); |
|
964 | + }); |
|
965 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
966 | + /** @var Factory $cacheFactory */ |
|
967 | + $cacheFactory = $c->query(Factory::class); |
|
968 | + return new JSCombiner( |
|
969 | + $c->getAppDataDir('js'), |
|
970 | + $c->getURLGenerator(), |
|
971 | + $this->getMemCacheFactory(), |
|
972 | + $c->getSystemConfig(), |
|
973 | + $c->getLogger() |
|
974 | + ); |
|
975 | + }); |
|
976 | + $this->registerService(EventDispatcher::class, function () { |
|
977 | + return new EventDispatcher(); |
|
978 | + }); |
|
979 | + $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
980 | + $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
981 | + |
|
982 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
983 | + // FIXME: Instantiiated here due to cyclic dependency |
|
984 | + $request = new Request( |
|
985 | + [ |
|
986 | + 'get' => $_GET, |
|
987 | + 'post' => $_POST, |
|
988 | + 'files' => $_FILES, |
|
989 | + 'server' => $_SERVER, |
|
990 | + 'env' => $_ENV, |
|
991 | + 'cookies' => $_COOKIE, |
|
992 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
993 | + ? $_SERVER['REQUEST_METHOD'] |
|
994 | + : null, |
|
995 | + ], |
|
996 | + $c->getSecureRandom(), |
|
997 | + $c->getConfig() |
|
998 | + ); |
|
999 | + |
|
1000 | + return new CryptoWrapper( |
|
1001 | + $c->getConfig(), |
|
1002 | + $c->getCrypto(), |
|
1003 | + $c->getSecureRandom(), |
|
1004 | + $request |
|
1005 | + ); |
|
1006 | + }); |
|
1007 | + $this->registerService('CsrfTokenManager', function (Server $c) { |
|
1008 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
1009 | + |
|
1010 | + return new CsrfTokenManager( |
|
1011 | + $tokenGenerator, |
|
1012 | + $c->query(SessionStorage::class) |
|
1013 | + ); |
|
1014 | + }); |
|
1015 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
1016 | + return new SessionStorage($c->getSession()); |
|
1017 | + }); |
|
1018 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1019 | + return new ContentSecurityPolicyManager(); |
|
1020 | + }); |
|
1021 | + $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
1022 | + |
|
1023 | + $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1024 | + return new ContentSecurityPolicyNonceManager( |
|
1025 | + $c->getCsrfTokenManager(), |
|
1026 | + $c->getRequest() |
|
1027 | + ); |
|
1028 | + }); |
|
1029 | + |
|
1030 | + $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1031 | + $config = $c->getConfig(); |
|
1032 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1033 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
1034 | + $factory = new $factoryClass($this); |
|
1035 | + |
|
1036 | + $manager = new \OC\Share20\Manager( |
|
1037 | + $c->getLogger(), |
|
1038 | + $c->getConfig(), |
|
1039 | + $c->getSecureRandom(), |
|
1040 | + $c->getHasher(), |
|
1041 | + $c->getMountManager(), |
|
1042 | + $c->getGroupManager(), |
|
1043 | + $c->getL10N('lib'), |
|
1044 | + $c->getL10NFactory(), |
|
1045 | + $factory, |
|
1046 | + $c->getUserManager(), |
|
1047 | + $c->getLazyRootFolder(), |
|
1048 | + $c->getEventDispatcher(), |
|
1049 | + $c->getMailer(), |
|
1050 | + $c->getURLGenerator(), |
|
1051 | + $c->getThemingDefaults() |
|
1052 | + ); |
|
1053 | + |
|
1054 | + return $manager; |
|
1055 | + }); |
|
1056 | + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1057 | + |
|
1058 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1059 | + $instance = new Collaboration\Collaborators\Search($c); |
|
1060 | + |
|
1061 | + // register default plugins |
|
1062 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1063 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1064 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1065 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1066 | + |
|
1067 | + return $instance; |
|
1068 | + }); |
|
1069 | + $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1070 | + |
|
1071 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1072 | + |
|
1073 | + $this->registerService('SettingsManager', function (Server $c) { |
|
1074 | + $manager = new \OC\Settings\Manager( |
|
1075 | + $c->getLogger(), |
|
1076 | + $c->getDatabaseConnection(), |
|
1077 | + $c->getL10N('lib'), |
|
1078 | + $c->getConfig(), |
|
1079 | + $c->getEncryptionManager(), |
|
1080 | + $c->getUserManager(), |
|
1081 | + $c->getLockingProvider(), |
|
1082 | + $c->getRequest(), |
|
1083 | + $c->getURLGenerator(), |
|
1084 | + $c->query(AccountManager::class), |
|
1085 | + $c->getGroupManager(), |
|
1086 | + $c->getL10NFactory(), |
|
1087 | + $c->getAppManager() |
|
1088 | + ); |
|
1089 | + return $manager; |
|
1090 | + }); |
|
1091 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1092 | + return new \OC\Files\AppData\Factory( |
|
1093 | + $c->getRootFolder(), |
|
1094 | + $c->getSystemConfig() |
|
1095 | + ); |
|
1096 | + }); |
|
1097 | + |
|
1098 | + $this->registerService('LockdownManager', function (Server $c) { |
|
1099 | + return new LockdownManager(function () use ($c) { |
|
1100 | + return $c->getSession(); |
|
1101 | + }); |
|
1102 | + }); |
|
1103 | + |
|
1104 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1105 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1106 | + }); |
|
1107 | + |
|
1108 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1109 | + return new CloudIdManager(); |
|
1110 | + }); |
|
1111 | + |
|
1112 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1113 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1114 | + |
|
1115 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1116 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1117 | + |
|
1118 | + $this->registerService(Defaults::class, function (Server $c) { |
|
1119 | + return new Defaults( |
|
1120 | + $c->getThemingDefaults() |
|
1121 | + ); |
|
1122 | + }); |
|
1123 | + $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1124 | + |
|
1125 | + $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1126 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1127 | + }); |
|
1128 | + |
|
1129 | + $this->registerService(IShareHelper::class, function (Server $c) { |
|
1130 | + return new ShareHelper( |
|
1131 | + $c->query(\OCP\Share\IManager::class) |
|
1132 | + ); |
|
1133 | + }); |
|
1134 | + |
|
1135 | + $this->registerService(Installer::class, function(Server $c) { |
|
1136 | + return new Installer( |
|
1137 | + $c->getAppFetcher(), |
|
1138 | + $c->getHTTPClientService(), |
|
1139 | + $c->getTempManager(), |
|
1140 | + $c->getLogger(), |
|
1141 | + $c->getConfig() |
|
1142 | + ); |
|
1143 | + }); |
|
1144 | + |
|
1145 | + $this->registerService(IApiFactory::class, function(Server $c) { |
|
1146 | + return new ApiFactory($c->getHTTPClientService()); |
|
1147 | + }); |
|
1148 | + |
|
1149 | + $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
1150 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
1151 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1152 | + }); |
|
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 | + |
|
1164 | + $this->connectDispatcher(); |
|
1165 | + } |
|
1166 | + |
|
1167 | + /** |
|
1168 | + * @return \OCP\Calendar\IManager |
|
1169 | + */ |
|
1170 | + public function getCalendarManager() { |
|
1171 | + return $this->query('CalendarManager'); |
|
1172 | + } |
|
1173 | + |
|
1174 | + private function connectDispatcher() { |
|
1175 | + $dispatcher = $this->getEventDispatcher(); |
|
1176 | + |
|
1177 | + // Delete avatar on user deletion |
|
1178 | + $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1179 | + $logger = $this->getLogger(); |
|
1180 | + $manager = $this->getAvatarManager(); |
|
1181 | + /** @var IUser $user */ |
|
1182 | + $user = $e->getSubject(); |
|
1183 | + |
|
1184 | + try { |
|
1185 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1186 | + $avatar->remove(); |
|
1187 | + } catch (NotFoundException $e) { |
|
1188 | + // no avatar to remove |
|
1189 | + } catch (\Exception $e) { |
|
1190 | + // Ignore exceptions |
|
1191 | + $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1192 | + } |
|
1193 | + }); |
|
1194 | + |
|
1195 | + $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1196 | + $manager = $this->getAvatarManager(); |
|
1197 | + /** @var IUser $user */ |
|
1198 | + $user = $e->getSubject(); |
|
1199 | + $feature = $e->getArgument('feature'); |
|
1200 | + $oldValue = $e->getArgument('oldValue'); |
|
1201 | + $value = $e->getArgument('value'); |
|
1202 | + |
|
1203 | + try { |
|
1204 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1205 | + $avatar->userChanged($feature, $oldValue, $value); |
|
1206 | + } catch (NotFoundException $e) { |
|
1207 | + // no avatar to remove |
|
1208 | + } |
|
1209 | + }); |
|
1210 | + } |
|
1211 | + |
|
1212 | + /** |
|
1213 | + * @return \OCP\Contacts\IManager |
|
1214 | + */ |
|
1215 | + public function getContactsManager() { |
|
1216 | + return $this->query('ContactsManager'); |
|
1217 | + } |
|
1218 | + |
|
1219 | + /** |
|
1220 | + * @return \OC\Encryption\Manager |
|
1221 | + */ |
|
1222 | + public function getEncryptionManager() { |
|
1223 | + return $this->query('EncryptionManager'); |
|
1224 | + } |
|
1225 | + |
|
1226 | + /** |
|
1227 | + * @return \OC\Encryption\File |
|
1228 | + */ |
|
1229 | + public function getEncryptionFilesHelper() { |
|
1230 | + return $this->query('EncryptionFileHelper'); |
|
1231 | + } |
|
1232 | + |
|
1233 | + /** |
|
1234 | + * @return \OCP\Encryption\Keys\IStorage |
|
1235 | + */ |
|
1236 | + public function getEncryptionKeyStorage() { |
|
1237 | + return $this->query('EncryptionKeyStorage'); |
|
1238 | + } |
|
1239 | + |
|
1240 | + /** |
|
1241 | + * The current request object holding all information about the request |
|
1242 | + * currently being processed is returned from this method. |
|
1243 | + * In case the current execution was not initiated by a web request null is returned |
|
1244 | + * |
|
1245 | + * @return \OCP\IRequest |
|
1246 | + */ |
|
1247 | + public function getRequest() { |
|
1248 | + return $this->query('Request'); |
|
1249 | + } |
|
1250 | + |
|
1251 | + /** |
|
1252 | + * Returns the preview manager which can create preview images for a given file |
|
1253 | + * |
|
1254 | + * @return \OCP\IPreview |
|
1255 | + */ |
|
1256 | + public function getPreviewManager() { |
|
1257 | + return $this->query('PreviewManager'); |
|
1258 | + } |
|
1259 | + |
|
1260 | + /** |
|
1261 | + * Returns the tag manager which can get and set tags for different object types |
|
1262 | + * |
|
1263 | + * @see \OCP\ITagManager::load() |
|
1264 | + * @return \OCP\ITagManager |
|
1265 | + */ |
|
1266 | + public function getTagManager() { |
|
1267 | + return $this->query('TagManager'); |
|
1268 | + } |
|
1269 | + |
|
1270 | + /** |
|
1271 | + * Returns the system-tag manager |
|
1272 | + * |
|
1273 | + * @return \OCP\SystemTag\ISystemTagManager |
|
1274 | + * |
|
1275 | + * @since 9.0.0 |
|
1276 | + */ |
|
1277 | + public function getSystemTagManager() { |
|
1278 | + return $this->query('SystemTagManager'); |
|
1279 | + } |
|
1280 | + |
|
1281 | + /** |
|
1282 | + * Returns the system-tag object mapper |
|
1283 | + * |
|
1284 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1285 | + * |
|
1286 | + * @since 9.0.0 |
|
1287 | + */ |
|
1288 | + public function getSystemTagObjectMapper() { |
|
1289 | + return $this->query('SystemTagObjectMapper'); |
|
1290 | + } |
|
1291 | + |
|
1292 | + /** |
|
1293 | + * Returns the avatar manager, used for avatar functionality |
|
1294 | + * |
|
1295 | + * @return \OCP\IAvatarManager |
|
1296 | + */ |
|
1297 | + public function getAvatarManager() { |
|
1298 | + return $this->query('AvatarManager'); |
|
1299 | + } |
|
1300 | + |
|
1301 | + /** |
|
1302 | + * Returns the root folder of ownCloud's data directory |
|
1303 | + * |
|
1304 | + * @return \OCP\Files\IRootFolder |
|
1305 | + */ |
|
1306 | + public function getRootFolder() { |
|
1307 | + return $this->query('LazyRootFolder'); |
|
1308 | + } |
|
1309 | + |
|
1310 | + /** |
|
1311 | + * Returns the root folder of ownCloud's data directory |
|
1312 | + * This is the lazy variant so this gets only initialized once it |
|
1313 | + * is actually used. |
|
1314 | + * |
|
1315 | + * @return \OCP\Files\IRootFolder |
|
1316 | + */ |
|
1317 | + public function getLazyRootFolder() { |
|
1318 | + return $this->query('LazyRootFolder'); |
|
1319 | + } |
|
1320 | + |
|
1321 | + /** |
|
1322 | + * Returns a view to ownCloud's files folder |
|
1323 | + * |
|
1324 | + * @param string $userId user ID |
|
1325 | + * @return \OCP\Files\Folder|null |
|
1326 | + */ |
|
1327 | + public function getUserFolder($userId = null) { |
|
1328 | + if ($userId === null) { |
|
1329 | + $user = $this->getUserSession()->getUser(); |
|
1330 | + if (!$user) { |
|
1331 | + return null; |
|
1332 | + } |
|
1333 | + $userId = $user->getUID(); |
|
1334 | + } |
|
1335 | + $root = $this->getRootFolder(); |
|
1336 | + return $root->getUserFolder($userId); |
|
1337 | + } |
|
1338 | + |
|
1339 | + /** |
|
1340 | + * Returns an app-specific view in ownClouds data directory |
|
1341 | + * |
|
1342 | + * @return \OCP\Files\Folder |
|
1343 | + * @deprecated since 9.2.0 use IAppData |
|
1344 | + */ |
|
1345 | + public function getAppFolder() { |
|
1346 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
1347 | + $root = $this->getRootFolder(); |
|
1348 | + if (!$root->nodeExists($dir)) { |
|
1349 | + $folder = $root->newFolder($dir); |
|
1350 | + } else { |
|
1351 | + $folder = $root->get($dir); |
|
1352 | + } |
|
1353 | + return $folder; |
|
1354 | + } |
|
1355 | + |
|
1356 | + /** |
|
1357 | + * @return \OC\User\Manager |
|
1358 | + */ |
|
1359 | + public function getUserManager() { |
|
1360 | + return $this->query('UserManager'); |
|
1361 | + } |
|
1362 | + |
|
1363 | + /** |
|
1364 | + * @return \OC\Group\Manager |
|
1365 | + */ |
|
1366 | + public function getGroupManager() { |
|
1367 | + return $this->query('GroupManager'); |
|
1368 | + } |
|
1369 | + |
|
1370 | + /** |
|
1371 | + * @return \OC\User\Session |
|
1372 | + */ |
|
1373 | + public function getUserSession() { |
|
1374 | + return $this->query('UserSession'); |
|
1375 | + } |
|
1376 | + |
|
1377 | + /** |
|
1378 | + * @return \OCP\ISession |
|
1379 | + */ |
|
1380 | + public function getSession() { |
|
1381 | + return $this->query('UserSession')->getSession(); |
|
1382 | + } |
|
1383 | + |
|
1384 | + /** |
|
1385 | + * @param \OCP\ISession $session |
|
1386 | + */ |
|
1387 | + public function setSession(\OCP\ISession $session) { |
|
1388 | + $this->query(SessionStorage::class)->setSession($session); |
|
1389 | + $this->query('UserSession')->setSession($session); |
|
1390 | + $this->query(Store::class)->setSession($session); |
|
1391 | + } |
|
1392 | + |
|
1393 | + /** |
|
1394 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1395 | + */ |
|
1396 | + public function getTwoFactorAuthManager() { |
|
1397 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1398 | + } |
|
1399 | + |
|
1400 | + /** |
|
1401 | + * @return \OC\NavigationManager |
|
1402 | + */ |
|
1403 | + public function getNavigationManager() { |
|
1404 | + return $this->query('NavigationManager'); |
|
1405 | + } |
|
1406 | + |
|
1407 | + /** |
|
1408 | + * @return \OCP\IConfig |
|
1409 | + */ |
|
1410 | + public function getConfig() { |
|
1411 | + return $this->query('AllConfig'); |
|
1412 | + } |
|
1413 | + |
|
1414 | + /** |
|
1415 | + * @return \OC\SystemConfig |
|
1416 | + */ |
|
1417 | + public function getSystemConfig() { |
|
1418 | + return $this->query('SystemConfig'); |
|
1419 | + } |
|
1420 | + |
|
1421 | + /** |
|
1422 | + * Returns the app config manager |
|
1423 | + * |
|
1424 | + * @return \OCP\IAppConfig |
|
1425 | + */ |
|
1426 | + public function getAppConfig() { |
|
1427 | + return $this->query('AppConfig'); |
|
1428 | + } |
|
1429 | + |
|
1430 | + /** |
|
1431 | + * @return \OCP\L10N\IFactory |
|
1432 | + */ |
|
1433 | + public function getL10NFactory() { |
|
1434 | + return $this->query('L10NFactory'); |
|
1435 | + } |
|
1436 | + |
|
1437 | + /** |
|
1438 | + * get an L10N instance |
|
1439 | + * |
|
1440 | + * @param string $app appid |
|
1441 | + * @param string $lang |
|
1442 | + * @return IL10N |
|
1443 | + */ |
|
1444 | + public function getL10N($app, $lang = null) { |
|
1445 | + return $this->getL10NFactory()->get($app, $lang); |
|
1446 | + } |
|
1447 | + |
|
1448 | + /** |
|
1449 | + * @return \OCP\IURLGenerator |
|
1450 | + */ |
|
1451 | + public function getURLGenerator() { |
|
1452 | + return $this->query('URLGenerator'); |
|
1453 | + } |
|
1454 | + |
|
1455 | + /** |
|
1456 | + * @return AppFetcher |
|
1457 | + */ |
|
1458 | + public function getAppFetcher() { |
|
1459 | + return $this->query(AppFetcher::class); |
|
1460 | + } |
|
1461 | + |
|
1462 | + /** |
|
1463 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1464 | + * getMemCacheFactory() instead. |
|
1465 | + * |
|
1466 | + * @return \OCP\ICache |
|
1467 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1468 | + */ |
|
1469 | + public function getCache() { |
|
1470 | + return $this->query('UserCache'); |
|
1471 | + } |
|
1472 | + |
|
1473 | + /** |
|
1474 | + * Returns an \OCP\CacheFactory instance |
|
1475 | + * |
|
1476 | + * @return \OCP\ICacheFactory |
|
1477 | + */ |
|
1478 | + public function getMemCacheFactory() { |
|
1479 | + return $this->query('MemCacheFactory'); |
|
1480 | + } |
|
1481 | + |
|
1482 | + /** |
|
1483 | + * Returns an \OC\RedisFactory instance |
|
1484 | + * |
|
1485 | + * @return \OC\RedisFactory |
|
1486 | + */ |
|
1487 | + public function getGetRedisFactory() { |
|
1488 | + return $this->query('RedisFactory'); |
|
1489 | + } |
|
1490 | + |
|
1491 | + |
|
1492 | + /** |
|
1493 | + * Returns the current session |
|
1494 | + * |
|
1495 | + * @return \OCP\IDBConnection |
|
1496 | + */ |
|
1497 | + public function getDatabaseConnection() { |
|
1498 | + return $this->query('DatabaseConnection'); |
|
1499 | + } |
|
1500 | + |
|
1501 | + /** |
|
1502 | + * Returns the activity manager |
|
1503 | + * |
|
1504 | + * @return \OCP\Activity\IManager |
|
1505 | + */ |
|
1506 | + public function getActivityManager() { |
|
1507 | + return $this->query('ActivityManager'); |
|
1508 | + } |
|
1509 | + |
|
1510 | + /** |
|
1511 | + * Returns an job list for controlling background jobs |
|
1512 | + * |
|
1513 | + * @return \OCP\BackgroundJob\IJobList |
|
1514 | + */ |
|
1515 | + public function getJobList() { |
|
1516 | + return $this->query('JobList'); |
|
1517 | + } |
|
1518 | + |
|
1519 | + /** |
|
1520 | + * Returns a logger instance |
|
1521 | + * |
|
1522 | + * @return \OCP\ILogger |
|
1523 | + */ |
|
1524 | + public function getLogger() { |
|
1525 | + return $this->query('Logger'); |
|
1526 | + } |
|
1527 | + |
|
1528 | + /** |
|
1529 | + * @return ILogFactory |
|
1530 | + * @throws \OCP\AppFramework\QueryException |
|
1531 | + */ |
|
1532 | + public function getLogFactory() { |
|
1533 | + return $this->query(ILogFactory::class); |
|
1534 | + } |
|
1535 | + |
|
1536 | + /** |
|
1537 | + * Returns a router for generating and matching urls |
|
1538 | + * |
|
1539 | + * @return \OCP\Route\IRouter |
|
1540 | + */ |
|
1541 | + public function getRouter() { |
|
1542 | + return $this->query('Router'); |
|
1543 | + } |
|
1544 | + |
|
1545 | + /** |
|
1546 | + * Returns a search instance |
|
1547 | + * |
|
1548 | + * @return \OCP\ISearch |
|
1549 | + */ |
|
1550 | + public function getSearch() { |
|
1551 | + return $this->query('Search'); |
|
1552 | + } |
|
1553 | + |
|
1554 | + /** |
|
1555 | + * Returns a SecureRandom instance |
|
1556 | + * |
|
1557 | + * @return \OCP\Security\ISecureRandom |
|
1558 | + */ |
|
1559 | + public function getSecureRandom() { |
|
1560 | + return $this->query('SecureRandom'); |
|
1561 | + } |
|
1562 | + |
|
1563 | + /** |
|
1564 | + * Returns a Crypto instance |
|
1565 | + * |
|
1566 | + * @return \OCP\Security\ICrypto |
|
1567 | + */ |
|
1568 | + public function getCrypto() { |
|
1569 | + return $this->query('Crypto'); |
|
1570 | + } |
|
1571 | + |
|
1572 | + /** |
|
1573 | + * Returns a Hasher instance |
|
1574 | + * |
|
1575 | + * @return \OCP\Security\IHasher |
|
1576 | + */ |
|
1577 | + public function getHasher() { |
|
1578 | + return $this->query('Hasher'); |
|
1579 | + } |
|
1580 | + |
|
1581 | + /** |
|
1582 | + * Returns a CredentialsManager instance |
|
1583 | + * |
|
1584 | + * @return \OCP\Security\ICredentialsManager |
|
1585 | + */ |
|
1586 | + public function getCredentialsManager() { |
|
1587 | + return $this->query('CredentialsManager'); |
|
1588 | + } |
|
1589 | + |
|
1590 | + /** |
|
1591 | + * Get the certificate manager for the user |
|
1592 | + * |
|
1593 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1594 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1595 | + */ |
|
1596 | + public function getCertificateManager($userId = '') { |
|
1597 | + if ($userId === '') { |
|
1598 | + $userSession = $this->getUserSession(); |
|
1599 | + $user = $userSession->getUser(); |
|
1600 | + if (is_null($user)) { |
|
1601 | + return null; |
|
1602 | + } |
|
1603 | + $userId = $user->getUID(); |
|
1604 | + } |
|
1605 | + return new CertificateManager( |
|
1606 | + $userId, |
|
1607 | + new View(), |
|
1608 | + $this->getConfig(), |
|
1609 | + $this->getLogger(), |
|
1610 | + $this->getSecureRandom() |
|
1611 | + ); |
|
1612 | + } |
|
1613 | + |
|
1614 | + /** |
|
1615 | + * Returns an instance of the HTTP client service |
|
1616 | + * |
|
1617 | + * @return \OCP\Http\Client\IClientService |
|
1618 | + */ |
|
1619 | + public function getHTTPClientService() { |
|
1620 | + return $this->query('HttpClientService'); |
|
1621 | + } |
|
1622 | + |
|
1623 | + /** |
|
1624 | + * Create a new event source |
|
1625 | + * |
|
1626 | + * @return \OCP\IEventSource |
|
1627 | + */ |
|
1628 | + public function createEventSource() { |
|
1629 | + return new \OC_EventSource(); |
|
1630 | + } |
|
1631 | + |
|
1632 | + /** |
|
1633 | + * Get the active event logger |
|
1634 | + * |
|
1635 | + * The returned logger only logs data when debug mode is enabled |
|
1636 | + * |
|
1637 | + * @return \OCP\Diagnostics\IEventLogger |
|
1638 | + */ |
|
1639 | + public function getEventLogger() { |
|
1640 | + return $this->query('EventLogger'); |
|
1641 | + } |
|
1642 | + |
|
1643 | + /** |
|
1644 | + * Get the active query logger |
|
1645 | + * |
|
1646 | + * The returned logger only logs data when debug mode is enabled |
|
1647 | + * |
|
1648 | + * @return \OCP\Diagnostics\IQueryLogger |
|
1649 | + */ |
|
1650 | + public function getQueryLogger() { |
|
1651 | + return $this->query('QueryLogger'); |
|
1652 | + } |
|
1653 | + |
|
1654 | + /** |
|
1655 | + * Get the manager for temporary files and folders |
|
1656 | + * |
|
1657 | + * @return \OCP\ITempManager |
|
1658 | + */ |
|
1659 | + public function getTempManager() { |
|
1660 | + return $this->query('TempManager'); |
|
1661 | + } |
|
1662 | + |
|
1663 | + /** |
|
1664 | + * Get the app manager |
|
1665 | + * |
|
1666 | + * @return \OCP\App\IAppManager |
|
1667 | + */ |
|
1668 | + public function getAppManager() { |
|
1669 | + return $this->query('AppManager'); |
|
1670 | + } |
|
1671 | + |
|
1672 | + /** |
|
1673 | + * Creates a new mailer |
|
1674 | + * |
|
1675 | + * @return \OCP\Mail\IMailer |
|
1676 | + */ |
|
1677 | + public function getMailer() { |
|
1678 | + return $this->query('Mailer'); |
|
1679 | + } |
|
1680 | + |
|
1681 | + /** |
|
1682 | + * Get the webroot |
|
1683 | + * |
|
1684 | + * @return string |
|
1685 | + */ |
|
1686 | + public function getWebRoot() { |
|
1687 | + return $this->webRoot; |
|
1688 | + } |
|
1689 | + |
|
1690 | + /** |
|
1691 | + * @return \OC\OCSClient |
|
1692 | + */ |
|
1693 | + public function getOcsClient() { |
|
1694 | + return $this->query('OcsClient'); |
|
1695 | + } |
|
1696 | + |
|
1697 | + /** |
|
1698 | + * @return \OCP\IDateTimeZone |
|
1699 | + */ |
|
1700 | + public function getDateTimeZone() { |
|
1701 | + return $this->query('DateTimeZone'); |
|
1702 | + } |
|
1703 | + |
|
1704 | + /** |
|
1705 | + * @return \OCP\IDateTimeFormatter |
|
1706 | + */ |
|
1707 | + public function getDateTimeFormatter() { |
|
1708 | + return $this->query('DateTimeFormatter'); |
|
1709 | + } |
|
1710 | + |
|
1711 | + /** |
|
1712 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
1713 | + */ |
|
1714 | + public function getMountProviderCollection() { |
|
1715 | + return $this->query('MountConfigManager'); |
|
1716 | + } |
|
1717 | + |
|
1718 | + /** |
|
1719 | + * Get the IniWrapper |
|
1720 | + * |
|
1721 | + * @return IniGetWrapper |
|
1722 | + */ |
|
1723 | + public function getIniWrapper() { |
|
1724 | + return $this->query('IniWrapper'); |
|
1725 | + } |
|
1726 | + |
|
1727 | + /** |
|
1728 | + * @return \OCP\Command\IBus |
|
1729 | + */ |
|
1730 | + public function getCommandBus() { |
|
1731 | + return $this->query('AsyncCommandBus'); |
|
1732 | + } |
|
1733 | + |
|
1734 | + /** |
|
1735 | + * Get the trusted domain helper |
|
1736 | + * |
|
1737 | + * @return TrustedDomainHelper |
|
1738 | + */ |
|
1739 | + public function getTrustedDomainHelper() { |
|
1740 | + return $this->query('TrustedDomainHelper'); |
|
1741 | + } |
|
1742 | + |
|
1743 | + /** |
|
1744 | + * Get the locking provider |
|
1745 | + * |
|
1746 | + * @return \OCP\Lock\ILockingProvider |
|
1747 | + * @since 8.1.0 |
|
1748 | + */ |
|
1749 | + public function getLockingProvider() { |
|
1750 | + return $this->query('LockingProvider'); |
|
1751 | + } |
|
1752 | + |
|
1753 | + /** |
|
1754 | + * @return \OCP\Files\Mount\IMountManager |
|
1755 | + **/ |
|
1756 | + function getMountManager() { |
|
1757 | + return $this->query('MountManager'); |
|
1758 | + } |
|
1759 | + |
|
1760 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
1761 | + function getUserMountCache() { |
|
1762 | + return $this->query('UserMountCache'); |
|
1763 | + } |
|
1764 | + |
|
1765 | + /** |
|
1766 | + * Get the MimeTypeDetector |
|
1767 | + * |
|
1768 | + * @return \OCP\Files\IMimeTypeDetector |
|
1769 | + */ |
|
1770 | + public function getMimeTypeDetector() { |
|
1771 | + return $this->query('MimeTypeDetector'); |
|
1772 | + } |
|
1773 | + |
|
1774 | + /** |
|
1775 | + * Get the MimeTypeLoader |
|
1776 | + * |
|
1777 | + * @return \OCP\Files\IMimeTypeLoader |
|
1778 | + */ |
|
1779 | + public function getMimeTypeLoader() { |
|
1780 | + return $this->query('MimeTypeLoader'); |
|
1781 | + } |
|
1782 | + |
|
1783 | + /** |
|
1784 | + * Get the manager of all the capabilities |
|
1785 | + * |
|
1786 | + * @return \OC\CapabilitiesManager |
|
1787 | + */ |
|
1788 | + public function getCapabilitiesManager() { |
|
1789 | + return $this->query('CapabilitiesManager'); |
|
1790 | + } |
|
1791 | + |
|
1792 | + /** |
|
1793 | + * Get the EventDispatcher |
|
1794 | + * |
|
1795 | + * @return EventDispatcherInterface |
|
1796 | + * @since 8.2.0 |
|
1797 | + */ |
|
1798 | + public function getEventDispatcher() { |
|
1799 | + return $this->query('EventDispatcher'); |
|
1800 | + } |
|
1801 | + |
|
1802 | + /** |
|
1803 | + * Get the Notification Manager |
|
1804 | + * |
|
1805 | + * @return \OCP\Notification\IManager |
|
1806 | + * @since 8.2.0 |
|
1807 | + */ |
|
1808 | + public function getNotificationManager() { |
|
1809 | + return $this->query('NotificationManager'); |
|
1810 | + } |
|
1811 | + |
|
1812 | + /** |
|
1813 | + * @return \OCP\Comments\ICommentsManager |
|
1814 | + */ |
|
1815 | + public function getCommentsManager() { |
|
1816 | + return $this->query('CommentsManager'); |
|
1817 | + } |
|
1818 | + |
|
1819 | + /** |
|
1820 | + * @return \OCA\Theming\ThemingDefaults |
|
1821 | + */ |
|
1822 | + public function getThemingDefaults() { |
|
1823 | + return $this->query('ThemingDefaults'); |
|
1824 | + } |
|
1825 | + |
|
1826 | + /** |
|
1827 | + * @return \OC\IntegrityCheck\Checker |
|
1828 | + */ |
|
1829 | + public function getIntegrityCodeChecker() { |
|
1830 | + return $this->query('IntegrityCodeChecker'); |
|
1831 | + } |
|
1832 | + |
|
1833 | + /** |
|
1834 | + * @return \OC\Session\CryptoWrapper |
|
1835 | + */ |
|
1836 | + public function getSessionCryptoWrapper() { |
|
1837 | + return $this->query('CryptoWrapper'); |
|
1838 | + } |
|
1839 | + |
|
1840 | + /** |
|
1841 | + * @return CsrfTokenManager |
|
1842 | + */ |
|
1843 | + public function getCsrfTokenManager() { |
|
1844 | + return $this->query('CsrfTokenManager'); |
|
1845 | + } |
|
1846 | + |
|
1847 | + /** |
|
1848 | + * @return Throttler |
|
1849 | + */ |
|
1850 | + public function getBruteForceThrottler() { |
|
1851 | + return $this->query('Throttler'); |
|
1852 | + } |
|
1853 | + |
|
1854 | + /** |
|
1855 | + * @return IContentSecurityPolicyManager |
|
1856 | + */ |
|
1857 | + public function getContentSecurityPolicyManager() { |
|
1858 | + return $this->query('ContentSecurityPolicyManager'); |
|
1859 | + } |
|
1860 | + |
|
1861 | + /** |
|
1862 | + * @return ContentSecurityPolicyNonceManager |
|
1863 | + */ |
|
1864 | + public function getContentSecurityPolicyNonceManager() { |
|
1865 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
1866 | + } |
|
1867 | + |
|
1868 | + /** |
|
1869 | + * Not a public API as of 8.2, wait for 9.0 |
|
1870 | + * |
|
1871 | + * @return \OCA\Files_External\Service\BackendService |
|
1872 | + */ |
|
1873 | + public function getStoragesBackendService() { |
|
1874 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1875 | + } |
|
1876 | + |
|
1877 | + /** |
|
1878 | + * Not a public API as of 8.2, wait for 9.0 |
|
1879 | + * |
|
1880 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1881 | + */ |
|
1882 | + public function getGlobalStoragesService() { |
|
1883 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1884 | + } |
|
1885 | + |
|
1886 | + /** |
|
1887 | + * Not a public API as of 8.2, wait for 9.0 |
|
1888 | + * |
|
1889 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1890 | + */ |
|
1891 | + public function getUserGlobalStoragesService() { |
|
1892 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1893 | + } |
|
1894 | + |
|
1895 | + /** |
|
1896 | + * Not a public API as of 8.2, wait for 9.0 |
|
1897 | + * |
|
1898 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
1899 | + */ |
|
1900 | + public function getUserStoragesService() { |
|
1901 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1902 | + } |
|
1903 | + |
|
1904 | + /** |
|
1905 | + * @return \OCP\Share\IManager |
|
1906 | + */ |
|
1907 | + public function getShareManager() { |
|
1908 | + return $this->query('ShareManager'); |
|
1909 | + } |
|
1910 | + |
|
1911 | + /** |
|
1912 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
1913 | + */ |
|
1914 | + public function getCollaboratorSearch() { |
|
1915 | + return $this->query('CollaboratorSearch'); |
|
1916 | + } |
|
1917 | + |
|
1918 | + /** |
|
1919 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
1920 | + */ |
|
1921 | + public function getAutoCompleteManager(){ |
|
1922 | + return $this->query(IManager::class); |
|
1923 | + } |
|
1924 | + |
|
1925 | + /** |
|
1926 | + * Returns the LDAP Provider |
|
1927 | + * |
|
1928 | + * @return \OCP\LDAP\ILDAPProvider |
|
1929 | + */ |
|
1930 | + public function getLDAPProvider() { |
|
1931 | + return $this->query('LDAPProvider'); |
|
1932 | + } |
|
1933 | + |
|
1934 | + /** |
|
1935 | + * @return \OCP\Settings\IManager |
|
1936 | + */ |
|
1937 | + public function getSettingsManager() { |
|
1938 | + return $this->query('SettingsManager'); |
|
1939 | + } |
|
1940 | + |
|
1941 | + /** |
|
1942 | + * @return \OCP\Files\IAppData |
|
1943 | + */ |
|
1944 | + public function getAppDataDir($app) { |
|
1945 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
1946 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1947 | + return $factory->get($app); |
|
1948 | + } |
|
1949 | + |
|
1950 | + /** |
|
1951 | + * @return \OCP\Lockdown\ILockdownManager |
|
1952 | + */ |
|
1953 | + public function getLockdownManager() { |
|
1954 | + return $this->query('LockdownManager'); |
|
1955 | + } |
|
1956 | + |
|
1957 | + /** |
|
1958 | + * @return \OCP\Federation\ICloudIdManager |
|
1959 | + */ |
|
1960 | + public function getCloudIdManager() { |
|
1961 | + return $this->query(ICloudIdManager::class); |
|
1962 | + } |
|
1963 | + |
|
1964 | + /** |
|
1965 | + * @return \OCP\Remote\Api\IApiFactory |
|
1966 | + */ |
|
1967 | + public function getRemoteApiFactory() { |
|
1968 | + return $this->query(IApiFactory::class); |
|
1969 | + } |
|
1970 | + |
|
1971 | + /** |
|
1972 | + * @return \OCP\Remote\IInstanceFactory |
|
1973 | + */ |
|
1974 | + public function getRemoteInstanceFactory() { |
|
1975 | + return $this->query(IInstanceFactory::class); |
|
1976 | + } |
|
1977 | 1977 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | /** |
6 | 6 | * @copyright 2018 Christoph Wurst <[email protected]> |
@@ -35,52 +35,52 @@ |
||
35 | 35 | */ |
36 | 36 | class ProviderUserAssignmentDao { |
37 | 37 | |
38 | - const TABLE_NAME = 'twofactor_providers'; |
|
38 | + const TABLE_NAME = 'twofactor_providers'; |
|
39 | 39 | |
40 | - /** @var IDBConnection */ |
|
41 | - private $conn; |
|
40 | + /** @var IDBConnection */ |
|
41 | + private $conn; |
|
42 | 42 | |
43 | - public function __construct(IDBConnection $dbConn) { |
|
44 | - $this->conn = $dbConn; |
|
45 | - } |
|
43 | + public function __construct(IDBConnection $dbConn) { |
|
44 | + $this->conn = $dbConn; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Get all assigned provider IDs for the given user ID |
|
49 | - * |
|
50 | - * @return string[] where the array key is the provider ID (string) and the |
|
51 | - * value is the enabled state (bool) |
|
52 | - */ |
|
53 | - public function getState(string $uid): array { |
|
54 | - $qb = $this->conn->getQueryBuilder(); |
|
47 | + /** |
|
48 | + * Get all assigned provider IDs for the given user ID |
|
49 | + * |
|
50 | + * @return string[] where the array key is the provider ID (string) and the |
|
51 | + * value is the enabled state (bool) |
|
52 | + */ |
|
53 | + public function getState(string $uid): array { |
|
54 | + $qb = $this->conn->getQueryBuilder(); |
|
55 | 55 | |
56 | - $query = $qb->select('provider_id', 'enabled') |
|
57 | - ->from(self::TABLE_NAME) |
|
58 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))); |
|
59 | - $result = $query->execute(); |
|
60 | - $providers = []; |
|
61 | - foreach ($result->fetchAll() as $row) { |
|
62 | - $providers[$row['provider_id']] = 1 === (int) $row['enabled']; |
|
63 | - } |
|
64 | - $result->closeCursor(); |
|
56 | + $query = $qb->select('provider_id', 'enabled') |
|
57 | + ->from(self::TABLE_NAME) |
|
58 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))); |
|
59 | + $result = $query->execute(); |
|
60 | + $providers = []; |
|
61 | + foreach ($result->fetchAll() as $row) { |
|
62 | + $providers[$row['provider_id']] = 1 === (int) $row['enabled']; |
|
63 | + } |
|
64 | + $result->closeCursor(); |
|
65 | 65 | |
66 | - return $providers; |
|
67 | - } |
|
66 | + return $providers; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Persist a new/updated (provider_id, uid, enabled) tuple |
|
71 | - */ |
|
72 | - public function persist(string $providerId, string $uid, int $enabled) { |
|
73 | - $qb = $this->conn->getQueryBuilder(); |
|
69 | + /** |
|
70 | + * Persist a new/updated (provider_id, uid, enabled) tuple |
|
71 | + */ |
|
72 | + public function persist(string $providerId, string $uid, int $enabled) { |
|
73 | + $qb = $this->conn->getQueryBuilder(); |
|
74 | 74 | |
75 | - // TODO: concurrency? What if (providerId, uid) private key is inserted |
|
76 | - // twice at the same time? |
|
77 | - $query = $qb->insert(self::TABLE_NAME)->values([ |
|
78 | - 'provider_id' => $qb->createNamedParameter($providerId), |
|
79 | - 'uid' => $qb->createNamedParameter($uid), |
|
80 | - 'enabled' => $qb->createNamedParameter($enabled, IQueryBuilder::PARAM_INT), |
|
81 | - ]); |
|
75 | + // TODO: concurrency? What if (providerId, uid) private key is inserted |
|
76 | + // twice at the same time? |
|
77 | + $query = $qb->insert(self::TABLE_NAME)->values([ |
|
78 | + 'provider_id' => $qb->createNamedParameter($providerId), |
|
79 | + 'uid' => $qb->createNamedParameter($uid), |
|
80 | + 'enabled' => $qb->createNamedParameter($enabled, IQueryBuilder::PARAM_INT), |
|
81 | + ]); |
|
82 | 82 | |
83 | - $query->execute(); |
|
84 | - } |
|
83 | + $query->execute(); |
|
84 | + } |
|
85 | 85 | |
86 | 86 | } |
@@ -34,55 +34,55 @@ |
||
34 | 34 | |
35 | 35 | class ProviderLoader { |
36 | 36 | |
37 | - const BACKUP_CODES_APP_ID = 'twofactor_backupcodes'; |
|
37 | + const BACKUP_CODES_APP_ID = 'twofactor_backupcodes'; |
|
38 | 38 | |
39 | - /** @var IAppManager */ |
|
40 | - private $appManager; |
|
39 | + /** @var IAppManager */ |
|
40 | + private $appManager; |
|
41 | 41 | |
42 | - public function __construct(IAppManager $appManager) { |
|
43 | - $this->appManager = $appManager; |
|
44 | - } |
|
42 | + public function __construct(IAppManager $appManager) { |
|
43 | + $this->appManager = $appManager; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Get the list of 2FA providers for the given user |
|
48 | - * |
|
49 | - * @return IProvider[] |
|
50 | - * @throws Exception |
|
51 | - */ |
|
52 | - public function getProviders(IUser $user): array { |
|
53 | - $allApps = $this->appManager->getEnabledAppsForUser($user); |
|
54 | - $providers = []; |
|
46 | + /** |
|
47 | + * Get the list of 2FA providers for the given user |
|
48 | + * |
|
49 | + * @return IProvider[] |
|
50 | + * @throws Exception |
|
51 | + */ |
|
52 | + public function getProviders(IUser $user): array { |
|
53 | + $allApps = $this->appManager->getEnabledAppsForUser($user); |
|
54 | + $providers = []; |
|
55 | 55 | |
56 | - foreach ($allApps as $appId) { |
|
57 | - $info = $this->appManager->getAppInfo($appId); |
|
58 | - if (isset($info['two-factor-providers'])) { |
|
59 | - /** @var string[] $providerClasses */ |
|
60 | - $providerClasses = $info['two-factor-providers']; |
|
61 | - foreach ($providerClasses as $class) { |
|
62 | - try { |
|
63 | - $this->loadTwoFactorApp($appId); |
|
64 | - $provider = OC::$server->query($class); |
|
65 | - $providers[$provider->getId()] = $provider; |
|
66 | - } catch (QueryException $exc) { |
|
67 | - // Provider class can not be resolved |
|
68 | - throw new Exception("Could not load two-factor auth provider $class"); |
|
69 | - } |
|
70 | - } |
|
71 | - } |
|
72 | - } |
|
56 | + foreach ($allApps as $appId) { |
|
57 | + $info = $this->appManager->getAppInfo($appId); |
|
58 | + if (isset($info['two-factor-providers'])) { |
|
59 | + /** @var string[] $providerClasses */ |
|
60 | + $providerClasses = $info['two-factor-providers']; |
|
61 | + foreach ($providerClasses as $class) { |
|
62 | + try { |
|
63 | + $this->loadTwoFactorApp($appId); |
|
64 | + $provider = OC::$server->query($class); |
|
65 | + $providers[$provider->getId()] = $provider; |
|
66 | + } catch (QueryException $exc) { |
|
67 | + // Provider class can not be resolved |
|
68 | + throw new Exception("Could not load two-factor auth provider $class"); |
|
69 | + } |
|
70 | + } |
|
71 | + } |
|
72 | + } |
|
73 | 73 | |
74 | - return $providers; |
|
75 | - } |
|
74 | + return $providers; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Load an app by ID if it has not been loaded yet |
|
79 | - * |
|
80 | - * @param string $appId |
|
81 | - */ |
|
82 | - protected function loadTwoFactorApp(string $appId) { |
|
83 | - if (!OC_App::isAppLoaded($appId)) { |
|
84 | - OC_App::loadApp($appId); |
|
85 | - } |
|
86 | - } |
|
77 | + /** |
|
78 | + * Load an app by ID if it has not been loaded yet |
|
79 | + * |
|
80 | + * @param string $appId |
|
81 | + */ |
|
82 | + protected function loadTwoFactorApp(string $appId) { |
|
83 | + if (!OC_App::isAppLoaded($appId)) { |
|
84 | + OC_App::loadApp($appId); |
|
85 | + } |
|
86 | + } |
|
87 | 87 | |
88 | 88 | } |
@@ -39,27 +39,27 @@ |
||
39 | 39 | */ |
40 | 40 | interface IRegistry { |
41 | 41 | |
42 | - /** |
|
43 | - * Get a key-value map of providers and their enabled/disabled state for |
|
44 | - * the given user. |
|
45 | - * |
|
46 | - * @since 14.0.0 |
|
47 | - * @return string[] where the array key is the provider ID (string) and the |
|
48 | - * value is the enabled state (bool) |
|
49 | - */ |
|
50 | - public function getProviderStates(IUser $user): array; |
|
42 | + /** |
|
43 | + * Get a key-value map of providers and their enabled/disabled state for |
|
44 | + * the given user. |
|
45 | + * |
|
46 | + * @since 14.0.0 |
|
47 | + * @return string[] where the array key is the provider ID (string) and the |
|
48 | + * value is the enabled state (bool) |
|
49 | + */ |
|
50 | + public function getProviderStates(IUser $user): array; |
|
51 | 51 | |
52 | - /** |
|
53 | - * Enable the given 2FA provider for the given user |
|
54 | - * |
|
55 | - * @since 14.0.0 |
|
56 | - */ |
|
57 | - public function enableProviderFor(IProvider $provider, IUser $user); |
|
52 | + /** |
|
53 | + * Enable the given 2FA provider for the given user |
|
54 | + * |
|
55 | + * @since 14.0.0 |
|
56 | + */ |
|
57 | + public function enableProviderFor(IProvider $provider, IUser $user); |
|
58 | 58 | |
59 | - /** |
|
60 | - * Disable the given 2FA provider for the given user |
|
61 | - * |
|
62 | - * @since 14.0.0 |
|
63 | - */ |
|
64 | - public function disableProviderFor(IProvider $provider, IUser $user); |
|
59 | + /** |
|
60 | + * Disable the given 2FA provider for the given user |
|
61 | + * |
|
62 | + * @since 14.0.0 |
|
63 | + */ |
|
64 | + public function disableProviderFor(IProvider $provider, IUser $user); |
|
65 | 65 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | /** |
6 | 6 | * @copyright 2018 Christoph Wurst <[email protected]> |