Passed
Push — master ( ba39d7...9af99a )
by Morris
12:25 queued 12s
created

OC_User::loginWithApache()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 33
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 20
nc 3
nop 1
dl 0
loc 33
rs 9.6
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Aldo "xoen" Giambelluca <[email protected]>
6
 * @author Andreas Fischer <[email protected]>
7
 * @author Arthur Schiwon <[email protected]>
8
 * @author Bartek Przybylski <[email protected]>
9
 * @author Björn Schießle <[email protected]>
10
 * @author Christoph Wurst <[email protected]>
11
 * @author Georg Ehrke <[email protected]>
12
 * @author Jakob Sack <[email protected]>
13
 * @author Jörn Friedrich Dreyer <[email protected]>
14
 * @author Lukas Reschke <[email protected]>
15
 * @author Morris Jobke <[email protected]>
16
 * @author Robin Appelman <[email protected]>
17
 * @author Robin McCorkell <[email protected]>
18
 * @author Roeland Jago Douma <[email protected]>
19
 * @author shkdee <[email protected]>
20
 * @author Thomas Müller <[email protected]>
21
 * @author Vincent Petry <[email protected]>
22
 *
23
 * @license AGPL-3.0
24
 *
25
 * This code is free software: you can redistribute it and/or modify
26
 * it under the terms of the GNU Affero General Public License, version 3,
27
 * as published by the Free Software Foundation.
28
 *
29
 * This program is distributed in the hope that it will be useful,
30
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32
 * GNU Affero General Public License for more details.
33
 *
34
 * You should have received a copy of the GNU Affero General Public License, version 3,
35
 * along with this program. If not, see <http://www.gnu.org/licenses/>
36
 *
37
 */
38
39
use OCP\ILogger;
40
41
/**
42
 * This class provides wrapper methods for user management. Multiple backends are
43
 * supported. User management operations are delegated to the configured backend for
44
 * execution.
45
 *
46
 * Note that &run is deprecated and won't work anymore.
47
 *
48
 * Hooks provided:
49
 *   pre_createUser(&run, uid, password)
50
 *   post_createUser(uid, password)
51
 *   pre_deleteUser(&run, uid)
52
 *   post_deleteUser(uid)
53
 *   pre_setPassword(&run, uid, password, recoveryPassword)
54
 *   post_setPassword(uid, password, recoveryPassword)
55
 *   pre_login(&run, uid, password)
56
 *   post_login(uid)
57
 *   logout()
58
 */
59
class OC_User {
60
	private static $_usedBackends = [];
61
62
	private static $_setupedBackends = [];
63
64
	// bool, stores if a user want to access a resource anonymously, e.g if they open a public link
65
	private static $incognitoMode = false;
66
67
	/**
68
	 * Adds the backend to the list of used backends
69
	 *
70
	 * @param string|\OCP\UserInterface $backend default: database The backend to use for user management
71
	 * @return bool
72
	 *
73
	 * Set the User Authentication Module
74
	 * @suppress PhanDeprecatedFunction
75
	 */
76
	public static function useBackend($backend = 'database') {
77
		if ($backend instanceof \OCP\UserInterface) {
78
			self::$_usedBackends[get_class($backend)] = $backend;
79
			\OC::$server->getUserManager()->registerBackend($backend);
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getUserManager() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

79
			/** @scrutinizer ignore-deprecated */ \OC::$server->getUserManager()->registerBackend($backend);
Loading history...
80
		} else {
81
			// You'll never know what happens
82
			if (null === $backend or !is_string($backend)) {
0 ignored issues
show
introduced by
The condition is_string($backend) is always true.
Loading history...
83
				$backend = 'database';
84
			}
85
86
			// Load backend
87
			switch ($backend) {
88
				case 'database':
89
				case 'mysql':
90
				case 'sqlite':
91
					\OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', ILogger::DEBUG);
0 ignored issues
show
Deprecated Code introduced by
The constant OCP\ILogger::DEBUG has been deprecated: 20.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

91
					\OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', /** @scrutinizer ignore-deprecated */ ILogger::DEBUG);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
92
					self::$_usedBackends[$backend] = new \OC\User\Database();
93
					\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getUserManager() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

93
					/** @scrutinizer ignore-deprecated */ \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
Loading history...
94
					break;
95
				case 'dummy':
96
					self::$_usedBackends[$backend] = new \Test\Util\User\Dummy();
0 ignored issues
show
Bug introduced by
The type Test\Util\User\Dummy was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
97
					\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getUserManager() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

97
					/** @scrutinizer ignore-deprecated */ \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
Loading history...
98
					break;
99
				default:
100
					\OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', ILogger::DEBUG);
0 ignored issues
show
Deprecated Code introduced by
The constant OCP\ILogger::DEBUG has been deprecated: 20.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

100
					\OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', /** @scrutinizer ignore-deprecated */ ILogger::DEBUG);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
101
					$className = 'OC_USER_' . strtoupper($backend);
102
					self::$_usedBackends[$backend] = new $className();
103
					\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getUserManager() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

103
					/** @scrutinizer ignore-deprecated */ \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
Loading history...
104
					break;
105
			}
106
		}
107
		return true;
108
	}
109
110
	/**
111
	 * remove all used backends
112
	 */
113
	public static function clearBackends() {
114
		self::$_usedBackends = [];
115
		\OC::$server->getUserManager()->clearBackends();
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getUserManager() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

115
		/** @scrutinizer ignore-deprecated */ \OC::$server->getUserManager()->clearBackends();
Loading history...
116
	}
117
118
	/**
119
	 * setup the configured backends in config.php
120
	 * @suppress PhanDeprecatedFunction
121
	 */
122
	public static function setupBackends() {
123
		OC_App::loadApps(['prelogin']);
124
		$backends = \OC::$server->getSystemConfig()->getValue('user_backends', []);
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getSystemConfig() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

124
		$backends = /** @scrutinizer ignore-deprecated */ \OC::$server->getSystemConfig()->getValue('user_backends', []);
Loading history...
125
		if (isset($backends['default']) && !$backends['default']) {
126
			// clear default backends
127
			self::clearBackends();
128
		}
129
		foreach ($backends as $i => $config) {
130
			if (!is_array($config)) {
131
				continue;
132
			}
133
			$class = $config['class'];
134
			$arguments = $config['arguments'];
135
			if (class_exists($class)) {
136
				if (array_search($i, self::$_setupedBackends) === false) {
137
					// make a reflection object
138
					$reflectionObj = new ReflectionClass($class);
139
140
					// use Reflection to create a new instance, using the $args
141
					$backend = $reflectionObj->newInstanceArgs($arguments);
142
					self::useBackend($backend);
143
					self::$_setupedBackends[] = $i;
144
				} else {
145
					\OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', ILogger::DEBUG);
0 ignored issues
show
Deprecated Code introduced by
The constant OCP\ILogger::DEBUG has been deprecated: 20.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

145
					\OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', /** @scrutinizer ignore-deprecated */ ILogger::DEBUG);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
146
				}
147
			} else {
148
				\OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', ILogger::ERROR);
0 ignored issues
show
Deprecated Code introduced by
The constant OCP\ILogger::ERROR has been deprecated: 20.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

148
				\OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', /** @scrutinizer ignore-deprecated */ ILogger::ERROR);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
149
			}
150
		}
151
	}
152
153
	/**
154
	 * Try to login a user, assuming authentication
155
	 * has already happened (e.g. via Single Sign On).
156
	 *
157
	 * Log in a user and regenerate a new session.
158
	 *
159
	 * @param \OCP\Authentication\IApacheBackend $backend
160
	 * @return bool
161
	 */
162
	public static function loginWithApache(\OCP\Authentication\IApacheBackend $backend) {
163
		$uid = $backend->getCurrentUserId();
164
		$run = true;
165
		OC_Hook::emit("OC_User", "pre_login", ["run" => &$run, "uid" => $uid, 'backend' => $backend]);
166
167
		if ($uid) {
168
			if (self::getUser() !== $uid) {
169
				self::setUserId($uid);
170
				$userSession = \OC::$server->getUserSession();
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getUserSession() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

170
				$userSession = /** @scrutinizer ignore-deprecated */ \OC::$server->getUserSession();
Loading history...
171
				$userSession->setLoginName($uid);
172
				$request = OC::$server->getRequest();
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getRequest() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

172
				$request = /** @scrutinizer ignore-deprecated */ OC::$server->getRequest();
Loading history...
173
				$userSession->createSessionToken($request, $uid, $uid);
174
				// setup the filesystem
175
				OC_Util::setupFS($uid);
176
				// first call the post_login hooks, the login-process needs to be
177
				// completed before we can safely create the users folder.
178
				// For example encryption needs to initialize the users keys first
179
				// before we can create the user folder with the skeleton files
180
				OC_Hook::emit(
181
					'OC_User',
182
					'post_login',
183
					[
184
						'uid' => $uid,
185
						'password' => '',
186
						'isTokenLogin' => false,
187
					]
188
				);
189
				//trigger creation of user home and /files folder
190
				\OC::$server->getUserFolder($uid);
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getUserFolder() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

190
				/** @scrutinizer ignore-deprecated */ \OC::$server->getUserFolder($uid);
Loading history...
191
			}
192
			return true;
193
		}
194
		return false;
195
	}
196
197
	/**
198
	 * Verify with Apache whether user is authenticated.
199
	 *
200
	 * @return boolean|null
201
	 *          true: authenticated
202
	 *          false: not authenticated
203
	 *          null: not handled / no backend available
204
	 */
205
	public static function handleApacheAuth() {
206
		$backend = self::findFirstActiveUsedBackend();
207
		if ($backend) {
208
			OC_App::loadApps();
209
210
			//setup extra user backends
211
			self::setupBackends();
212
			\OC::$server->getUserSession()->unsetMagicInCookie();
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getUserSession() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

212
			/** @scrutinizer ignore-deprecated */ \OC::$server->getUserSession()->unsetMagicInCookie();
Loading history...
213
214
			return self::loginWithApache($backend);
215
		}
216
217
		return null;
218
	}
219
220
221
	/**
222
	 * Sets user id for session and triggers emit
223
	 *
224
	 * @param string $uid
225
	 */
226
	public static function setUserId($uid) {
227
		$userSession = \OC::$server->getUserSession();
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getUserSession() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

227
		$userSession = /** @scrutinizer ignore-deprecated */ \OC::$server->getUserSession();
Loading history...
228
		$userManager = \OC::$server->getUserManager();
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getUserManager() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

228
		$userManager = /** @scrutinizer ignore-deprecated */ \OC::$server->getUserManager();
Loading history...
229
		if ($user = $userManager->get($uid)) {
230
			$userSession->setUser($user);
231
		} else {
232
			\OC::$server->getSession()->set('user_id', $uid);
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getSession() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

232
			/** @scrutinizer ignore-deprecated */ \OC::$server->getSession()->set('user_id', $uid);
Loading history...
233
		}
234
	}
235
236
	/**
237
	 * Check if the user is logged in, considers also the HTTP basic credentials
238
	 *
239
	 * @deprecated use \OC::$server->getUserSession()->isLoggedIn()
240
	 * @return bool
241
	 */
242
	public static function isLoggedIn() {
243
		return \OC::$server->getUserSession()->isLoggedIn();
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getUserSession() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

243
		return /** @scrutinizer ignore-deprecated */ \OC::$server->getUserSession()->isLoggedIn();
Loading history...
244
	}
245
246
	/**
247
	 * set incognito mode, e.g. if a user wants to open a public link
248
	 *
249
	 * @param bool $status
250
	 */
251
	public static function setIncognitoMode($status) {
252
		self::$incognitoMode = $status;
253
	}
254
255
	/**
256
	 * get incognito mode status
257
	 *
258
	 * @return bool
259
	 */
260
	public static function isIncognitoMode() {
261
		return self::$incognitoMode;
262
	}
263
264
	/**
265
	 * Returns the current logout URL valid for the currently logged-in user
266
	 *
267
	 * @param \OCP\IURLGenerator $urlGenerator
268
	 * @return string
269
	 */
270
	public static function getLogoutUrl(\OCP\IURLGenerator $urlGenerator) {
271
		$backend = self::findFirstActiveUsedBackend();
272
		if ($backend) {
273
			return $backend->getLogoutUrl();
274
		}
275
276
		$user = \OC::$server->getUserSession()->getUser();
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getUserSession() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

276
		$user = /** @scrutinizer ignore-deprecated */ \OC::$server->getUserSession()->getUser();
Loading history...
277
		if ($user instanceof \OCP\IUser) {
0 ignored issues
show
introduced by
$user is always a sub-type of OCP\IUser.
Loading history...
278
			$backend = $user->getBackend();
279
			if ($backend instanceof \OCP\User\Backend\ICustomLogout) {
280
				return $backend->getLogoutUrl();
281
			}
282
		}
283
284
		$logoutUrl = $urlGenerator->linkToRoute('core.login.logout');
285
		$logoutUrl .= '?requesttoken=' . urlencode(\OCP\Util::callRegister());
286
287
		return $logoutUrl;
288
	}
289
290
	/**
291
	 * Check if the user is an admin user
292
	 *
293
	 * @param string $uid uid of the admin
294
	 * @return bool
295
	 */
296
	public static function isAdminUser($uid) {
297
		$group = \OC::$server->getGroupManager()->get('admin');
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getGroupManager() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

297
		$group = /** @scrutinizer ignore-deprecated */ \OC::$server->getGroupManager()->get('admin');
Loading history...
298
		$user = \OC::$server->getUserManager()->get($uid);
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getUserManager() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

298
		$user = /** @scrutinizer ignore-deprecated */ \OC::$server->getUserManager()->get($uid);
Loading history...
299
		if ($group && $user && $group->inGroup($user) && self::$incognitoMode === false) {
300
			return true;
301
		}
302
		return false;
303
	}
304
305
306
	/**
307
	 * get the user id of the user currently logged in.
308
	 *
309
	 * @return string|bool uid or false
310
	 */
311
	public static function getUser() {
312
		$uid = \OC::$server->getSession() ? \OC::$server->getSession()->get('user_id') : null;
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getSession() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

312
		$uid = \OC::$server->getSession() ? /** @scrutinizer ignore-deprecated */ \OC::$server->getSession()->get('user_id') : null;
Loading history...
313
		if (!is_null($uid) && self::$incognitoMode === false) {
314
			return $uid;
315
		} else {
316
			return false;
317
		}
318
	}
319
320
	/**
321
	 * get the display name of the user currently logged in.
322
	 *
323
	 * @param string $uid
324
	 * @return string|bool uid or false
325
	 * @deprecated 8.1.0 fetch \OCP\IUser (has getDisplayName()) by using method
326
	 *                   get() of \OCP\IUserManager - \OC::$server->getUserManager()
327
	 */
328
	public static function getDisplayName($uid = null) {
329
		if ($uid) {
330
			$user = \OC::$server->getUserManager()->get($uid);
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getUserManager() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

330
			$user = /** @scrutinizer ignore-deprecated */ \OC::$server->getUserManager()->get($uid);
Loading history...
331
			if ($user) {
332
				return $user->getDisplayName();
333
			} else {
334
				return $uid;
335
			}
336
		} else {
337
			$user = \OC::$server->getUserSession()->getUser();
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getUserSession() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

337
			$user = /** @scrutinizer ignore-deprecated */ \OC::$server->getUserSession()->getUser();
Loading history...
338
			if ($user) {
0 ignored issues
show
introduced by
$user is of type OC\User\User, thus it always evaluated to true.
Loading history...
339
				return $user->getDisplayName();
340
			} else {
341
				return false;
342
			}
343
		}
344
	}
345
346
	/**
347
	 * Set password
348
	 *
349
	 * @param string $uid The username
350
	 * @param string $password The new password
351
	 * @param string $recoveryPassword for the encryption app to reset encryption keys
352
	 * @return bool
353
	 *
354
	 * Change the password of a user
355
	 */
356
	public static function setPassword($uid, $password, $recoveryPassword = null) {
357
		$user = \OC::$server->getUserManager()->get($uid);
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getUserManager() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

357
		$user = /** @scrutinizer ignore-deprecated */ \OC::$server->getUserManager()->get($uid);
Loading history...
358
		if ($user) {
359
			return $user->setPassword($password, $recoveryPassword);
360
		} else {
361
			return false;
362
		}
363
	}
364
365
	/**
366
	 * @param string $uid The username
367
	 * @return string
368
	 *
369
	 * returns the path to the users home directory
370
	 * @deprecated Use \OC::$server->getUserManager->getHome()
371
	 */
372
	public static function getHome($uid) {
373
		$user = \OC::$server->getUserManager()->get($uid);
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getUserManager() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

373
		$user = /** @scrutinizer ignore-deprecated */ \OC::$server->getUserManager()->get($uid);
Loading history...
374
		if ($user) {
375
			return $user->getHome();
376
		} else {
377
			return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid;
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getSystemConfig() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

377
			return /** @scrutinizer ignore-deprecated */ \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid;
Loading history...
378
		}
379
	}
380
381
	/**
382
	 * Get a list of all users display name
383
	 *
384
	 * @param string $search
385
	 * @param int $limit
386
	 * @param int $offset
387
	 * @return array associative array with all display names (value) and corresponding uids (key)
388
	 *
389
	 * Get a list of all display names and user ids.
390
	 * @deprecated Use \OC::$server->getUserManager->searchDisplayName($search, $limit, $offset) instead.
391
	 */
392
	public static function getDisplayNames($search = '', $limit = null, $offset = null) {
393
		$displayNames = [];
394
		$users = \OC::$server->getUserManager()->searchDisplayName($search, $limit, $offset);
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getUserManager() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

394
		$users = /** @scrutinizer ignore-deprecated */ \OC::$server->getUserManager()->searchDisplayName($search, $limit, $offset);
Loading history...
395
		foreach ($users as $user) {
396
			$displayNames[$user->getUID()] = $user->getDisplayName();
397
		}
398
		return $displayNames;
399
	}
400
401
	/**
402
	 * Returns the first active backend from self::$_usedBackends.
403
	 *
404
	 * @return OCP\Authentication\IApacheBackend|null if no backend active, otherwise OCP\Authentication\IApacheBackend
405
	 */
406
	private static function findFirstActiveUsedBackend() {
407
		foreach (self::$_usedBackends as $backend) {
408
			if ($backend instanceof OCP\Authentication\IApacheBackend) {
409
				if ($backend->isSessionActive()) {
410
					return $backend;
411
				}
412
			}
413
		}
414
415
		return null;
416
	}
417
}
418