@@ -69,10 +69,10 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function canChangeAvatar($uid) { |
71 | 71 | $user = $this->access->userManager->get($uid); |
72 | - if(!$user instanceof User) { |
|
72 | + if (!$user instanceof User) { |
|
73 | 73 | return false; |
74 | 74 | } |
75 | - if($user->getAvatarImage() === false) { |
|
75 | + if ($user->getAvatarImage() === false) { |
|
76 | 76 | return true; |
77 | 77 | } |
78 | 78 | |
@@ -88,14 +88,14 @@ discard block |
||
88 | 88 | public function loginName2UserName($loginName) { |
89 | 89 | $cacheKey = 'loginName2UserName-'.$loginName; |
90 | 90 | $username = $this->access->connection->getFromCache($cacheKey); |
91 | - if(!is_null($username)) { |
|
91 | + if (!is_null($username)) { |
|
92 | 92 | return $username; |
93 | 93 | } |
94 | 94 | |
95 | 95 | try { |
96 | 96 | $ldapRecord = $this->getLDAPUserByLoginName($loginName); |
97 | 97 | $user = $this->access->userManager->get($ldapRecord['dn'][0]); |
98 | - if($user instanceof OfflineUser) { |
|
98 | + if ($user instanceof OfflineUser) { |
|
99 | 99 | // this path is not really possible, however get() is documented |
100 | 100 | // to return User or OfflineUser so we are very defensive here. |
101 | 101 | $this->access->connection->writeToCache($cacheKey, false); |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | //find out dn of the user name |
132 | 132 | $attrs = $this->access->userManager->getAttributes(); |
133 | 133 | $users = $this->access->fetchUsersByLoginName($loginName, $attrs); |
134 | - if(count($users) < 1) { |
|
135 | - throw new NotOnLDAP('No user available for the given login name on ' . |
|
136 | - $this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort); |
|
134 | + if (count($users) < 1) { |
|
135 | + throw new NotOnLDAP('No user available for the given login name on '. |
|
136 | + $this->access->connection->ldapHost.':'.$this->access->connection->ldapPort); |
|
137 | 137 | } |
138 | 138 | return $users[0]; |
139 | 139 | } |
@@ -148,8 +148,8 @@ discard block |
||
148 | 148 | public function checkPassword($uid, $password) { |
149 | 149 | try { |
150 | 150 | $ldapRecord = $this->getLDAPUserByLoginName($uid); |
151 | - } catch(NotOnLDAP $e) { |
|
152 | - if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { |
|
151 | + } catch (NotOnLDAP $e) { |
|
152 | + if ($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { |
|
153 | 153 | \OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']); |
154 | 154 | } |
155 | 155 | return false; |
@@ -157,16 +157,16 @@ discard block |
||
157 | 157 | $dn = $ldapRecord['dn'][0]; |
158 | 158 | $user = $this->access->userManager->get($dn); |
159 | 159 | |
160 | - if(!$user instanceof User) { |
|
160 | + if (!$user instanceof User) { |
|
161 | 161 | Util::writeLog('user_ldap', |
162 | - 'LDAP Login: Could not get user object for DN ' . $dn . |
|
162 | + 'LDAP Login: Could not get user object for DN '.$dn. |
|
163 | 163 | '. Maybe the LDAP entry has no set display name attribute?', |
164 | 164 | Util::WARN); |
165 | 165 | return false; |
166 | 166 | } |
167 | - if($user->getUsername() !== false) { |
|
167 | + if ($user->getUsername() !== false) { |
|
168 | 168 | //are the credentials OK? |
169 | - if(!$this->access->areCredentialsValid($dn, $password)) { |
|
169 | + if (!$this->access->areCredentialsValid($dn, $password)) { |
|
170 | 170 | return false; |
171 | 171 | } |
172 | 172 | |
@@ -189,11 +189,11 @@ discard block |
||
189 | 189 | public function setPassword($uid, $password) { |
190 | 190 | $user = $this->access->userManager->get($uid); |
191 | 191 | |
192 | - if(!$user instanceof User) { |
|
193 | - throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid . |
|
192 | + if (!$user instanceof User) { |
|
193 | + throw new \Exception('LDAP setPassword: Could not get user object for uid '.$uid. |
|
194 | 194 | '. Maybe the LDAP entry has no set display name attribute?'); |
195 | 195 | } |
196 | - if($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) { |
|
196 | + if ($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) { |
|
197 | 197 | $ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN; |
198 | 198 | $turnOnPasswordChange = $this->access->connection->turnOnPasswordChange; |
199 | 199 | if (!empty($ldapDefaultPPolicyDN) && (intval($turnOnPasswordChange) === 1)) { |
@@ -225,18 +225,18 @@ discard block |
||
225 | 225 | |
226 | 226 | //check if users are cached, if so return |
227 | 227 | $ldap_users = $this->access->connection->getFromCache($cachekey); |
228 | - if(!is_null($ldap_users)) { |
|
228 | + if (!is_null($ldap_users)) { |
|
229 | 229 | return $ldap_users; |
230 | 230 | } |
231 | 231 | |
232 | 232 | // if we'd pass -1 to LDAP search, we'd end up in a Protocol |
233 | 233 | // error. With a limit of 0, we get 0 results. So we pass null. |
234 | - if($limit <= 0) { |
|
234 | + if ($limit <= 0) { |
|
235 | 235 | $limit = null; |
236 | 236 | } |
237 | 237 | $filter = $this->access->combineFilterWithAnd(array( |
238 | 238 | $this->access->connection->ldapUserFilter, |
239 | - $this->access->connection->ldapUserDisplayName . '=*', |
|
239 | + $this->access->connection->ldapUserDisplayName.'=*', |
|
240 | 240 | $this->access->getFilterPartForUserSearch($search) |
241 | 241 | )); |
242 | 242 | |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | $this->access->userManager->getAttributes(true), |
250 | 250 | $limit, $offset); |
251 | 251 | $ldap_users = $this->access->nextcloudUserNames($ldap_users); |
252 | - Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG); |
|
252 | + Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users).' Users found', Util::DEBUG); |
|
253 | 253 | |
254 | 254 | $this->access->connection->writeToCache($cachekey, $ldap_users); |
255 | 255 | return $ldap_users; |
@@ -265,29 +265,29 @@ discard block |
||
265 | 265 | * @throws \OC\ServerNotAvailableException |
266 | 266 | */ |
267 | 267 | public function userExistsOnLDAP($user) { |
268 | - if(is_string($user)) { |
|
268 | + if (is_string($user)) { |
|
269 | 269 | $user = $this->access->userManager->get($user); |
270 | 270 | } |
271 | - if(is_null($user)) { |
|
271 | + if (is_null($user)) { |
|
272 | 272 | return false; |
273 | 273 | } |
274 | 274 | |
275 | 275 | $dn = $user->getDN(); |
276 | 276 | //check if user really still exists by reading its entry |
277 | - if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) { |
|
277 | + if (!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) { |
|
278 | 278 | $lcr = $this->access->connection->getConnectionResource(); |
279 | - if(is_null($lcr)) { |
|
280 | - throw new \Exception('No LDAP Connection to server ' . $this->access->connection->ldapHost); |
|
279 | + if (is_null($lcr)) { |
|
280 | + throw new \Exception('No LDAP Connection to server '.$this->access->connection->ldapHost); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | try { |
284 | 284 | $uuid = $this->access->getUserMapper()->getUUIDByDN($dn); |
285 | - if(!$uuid) { |
|
285 | + if (!$uuid) { |
|
286 | 286 | return false; |
287 | 287 | } |
288 | 288 | $newDn = $this->access->getUserDnByUuid($uuid); |
289 | 289 | //check if renamed user is still valid by reapplying the ldap filter |
290 | - if(!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) { |
|
290 | + if (!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) { |
|
291 | 291 | return false; |
292 | 292 | } |
293 | 293 | $this->access->getUserMapper()->setDNbyUUID($newDn, $uuid); |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | } |
298 | 298 | } |
299 | 299 | |
300 | - if($user instanceof OfflineUser) { |
|
300 | + if ($user instanceof OfflineUser) { |
|
301 | 301 | $user->unmark(); |
302 | 302 | } |
303 | 303 | |
@@ -312,18 +312,18 @@ discard block |
||
312 | 312 | */ |
313 | 313 | public function userExists($uid) { |
314 | 314 | $userExists = $this->access->connection->getFromCache('userExists'.$uid); |
315 | - if(!is_null($userExists)) { |
|
316 | - return (bool)$userExists; |
|
315 | + if (!is_null($userExists)) { |
|
316 | + return (bool) $userExists; |
|
317 | 317 | } |
318 | 318 | //getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking. |
319 | 319 | $user = $this->access->userManager->get($uid); |
320 | 320 | |
321 | - if(is_null($user)) { |
|
321 | + if (is_null($user)) { |
|
322 | 322 | Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '. |
323 | 323 | $this->access->connection->ldapHost, Util::DEBUG); |
324 | 324 | $this->access->connection->writeToCache('userExists'.$uid, false); |
325 | 325 | return false; |
326 | - } else if($user instanceof OfflineUser) { |
|
326 | + } else if ($user instanceof OfflineUser) { |
|
327 | 327 | //express check for users marked as deleted. Returning true is |
328 | 328 | //necessary for cleanup |
329 | 329 | return true; |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | |
332 | 332 | $result = $this->userExistsOnLDAP($user); |
333 | 333 | $this->access->connection->writeToCache('userExists'.$uid, $result); |
334 | - if($result === true) { |
|
334 | + if ($result === true) { |
|
335 | 335 | $user->update(); |
336 | 336 | } |
337 | 337 | return $result; |
@@ -345,13 +345,13 @@ discard block |
||
345 | 345 | */ |
346 | 346 | public function deleteUser($uid) { |
347 | 347 | $marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0); |
348 | - if(intval($marked) === 0) { |
|
348 | + if (intval($marked) === 0) { |
|
349 | 349 | \OC::$server->getLogger()->notice( |
350 | - 'User '.$uid . ' is not marked as deleted, not cleaning up.', |
|
350 | + 'User '.$uid.' is not marked as deleted, not cleaning up.', |
|
351 | 351 | array('app' => 'user_ldap')); |
352 | 352 | return false; |
353 | 353 | } |
354 | - \OC::$server->getLogger()->info('Cleaning up after user ' . $uid, |
|
354 | + \OC::$server->getLogger()->info('Cleaning up after user '.$uid, |
|
355 | 355 | array('app' => 'user_ldap')); |
356 | 356 | |
357 | 357 | //Get Home Directory out of user preferences so we can return it later, |
@@ -370,22 +370,22 @@ discard block |
||
370 | 370 | */ |
371 | 371 | public function getHome($uid) { |
372 | 372 | // user Exists check required as it is not done in user proxy! |
373 | - if(!$this->userExists($uid)) { |
|
373 | + if (!$this->userExists($uid)) { |
|
374 | 374 | return false; |
375 | 375 | } |
376 | 376 | |
377 | 377 | $cacheKey = 'getHome'.$uid; |
378 | 378 | $path = $this->access->connection->getFromCache($cacheKey); |
379 | - if(!is_null($path)) { |
|
379 | + if (!is_null($path)) { |
|
380 | 380 | return $path; |
381 | 381 | } |
382 | 382 | |
383 | 383 | // early return path if it is a deleted user |
384 | 384 | $user = $this->access->userManager->get($uid); |
385 | - if($user instanceof OfflineUser) { |
|
385 | + if ($user instanceof OfflineUser) { |
|
386 | 386 | return $user->getHomePath(); |
387 | 387 | } else if ($user === null) { |
388 | - throw new NoUserException($uid . ' is not a valid user anymore'); |
|
388 | + throw new NoUserException($uid.' is not a valid user anymore'); |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | $path = $user->getHomePath(); |
@@ -400,12 +400,12 @@ discard block |
||
400 | 400 | * @return string|false display name |
401 | 401 | */ |
402 | 402 | public function getDisplayName($uid) { |
403 | - if(!$this->userExists($uid)) { |
|
403 | + if (!$this->userExists($uid)) { |
|
404 | 404 | return false; |
405 | 405 | } |
406 | 406 | |
407 | 407 | $cacheKey = 'getDisplayName'.$uid; |
408 | - if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { |
|
408 | + if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { |
|
409 | 409 | return $displayName; |
410 | 410 | } |
411 | 411 | |
@@ -422,10 +422,10 @@ discard block |
||
422 | 422 | $this->access->username2dn($uid), |
423 | 423 | $this->access->connection->ldapUserDisplayName); |
424 | 424 | |
425 | - if($displayName && (count($displayName) > 0)) { |
|
425 | + if ($displayName && (count($displayName) > 0)) { |
|
426 | 426 | $displayName = $displayName[0]; |
427 | 427 | |
428 | - if (is_array($displayName2)){ |
|
428 | + if (is_array($displayName2)) { |
|
429 | 429 | $displayName2 = count($displayName2) > 0 ? $displayName2[0] : ''; |
430 | 430 | } |
431 | 431 | |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | */ |
455 | 455 | public function getDisplayNames($search = '', $limit = null, $offset = null) { |
456 | 456 | $cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset; |
457 | - if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) { |
|
457 | + if (!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) { |
|
458 | 458 | return $displayNames; |
459 | 459 | } |
460 | 460 | |
@@ -476,12 +476,12 @@ discard block |
||
476 | 476 | * compared with OC_USER_BACKEND_CREATE_USER etc. |
477 | 477 | */ |
478 | 478 | public function implementsActions($actions) { |
479 | - return (bool)((Backend::CHECK_PASSWORD |
|
479 | + return (bool) ((Backend::CHECK_PASSWORD |
|
480 | 480 | | Backend::GET_HOME |
481 | 481 | | Backend::GET_DISPLAYNAME |
482 | 482 | | Backend::PROVIDE_AVATAR |
483 | 483 | | Backend::COUNT_USERS |
484 | - | ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0)) |
|
484 | + | ((intval($this->access->connection->turnOnPasswordChange) === 1) ? (Backend::SET_PASSWORD) : 0)) |
|
485 | 485 | & $actions); |
486 | 486 | } |
487 | 487 | |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | public function countUsers() { |
501 | 501 | $filter = $this->access->getFilterForUserCount(); |
502 | 502 | $cacheKey = 'countUsers-'.$filter; |
503 | - if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { |
|
503 | + if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { |
|
504 | 504 | return $entries; |
505 | 505 | } |
506 | 506 | $entries = $this->access->countUsers($filter); |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | * Backend name to be shown in user management |
513 | 513 | * @return string the name of the backend to be shown |
514 | 514 | */ |
515 | - public function getBackendName(){ |
|
515 | + public function getBackendName() { |
|
516 | 516 | return 'LDAP'; |
517 | 517 | } |
518 | 518 |