@@ -104,11 +104,11 @@ discard block |
||
104 | 104 | } |
105 | 105 | |
106 | 106 | $user = $this->access->userManager->get($uid); |
107 | - if(!$user instanceof User) { |
|
107 | + if (!$user instanceof User) { |
|
108 | 108 | return false; |
109 | 109 | } |
110 | 110 | $imageData = $user->getAvatarImage(); |
111 | - if($imageData === false) { |
|
111 | + if ($imageData === false) { |
|
112 | 112 | return true; |
113 | 113 | } |
114 | 114 | return !$user->updateAvatar(true); |
@@ -123,14 +123,14 @@ discard block |
||
123 | 123 | public function loginName2UserName($loginName) { |
124 | 124 | $cacheKey = 'loginName2UserName-'.$loginName; |
125 | 125 | $username = $this->access->connection->getFromCache($cacheKey); |
126 | - if(!is_null($username)) { |
|
126 | + if (!is_null($username)) { |
|
127 | 127 | return $username; |
128 | 128 | } |
129 | 129 | |
130 | 130 | try { |
131 | 131 | $ldapRecord = $this->getLDAPUserByLoginName($loginName); |
132 | 132 | $user = $this->access->userManager->get($ldapRecord['dn'][0]); |
133 | - if($user instanceof OfflineUser) { |
|
133 | + if ($user instanceof OfflineUser) { |
|
134 | 134 | // this path is not really possible, however get() is documented |
135 | 135 | // to return User or OfflineUser so we are very defensive here. |
136 | 136 | $this->access->connection->writeToCache($cacheKey, false); |
@@ -166,9 +166,9 @@ discard block |
||
166 | 166 | //find out dn of the user name |
167 | 167 | $attrs = $this->access->userManager->getAttributes(); |
168 | 168 | $users = $this->access->fetchUsersByLoginName($loginName, $attrs); |
169 | - if(count($users) < 1) { |
|
170 | - throw new NotOnLDAP('No user available for the given login name on ' . |
|
171 | - $this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort); |
|
169 | + if (count($users) < 1) { |
|
170 | + throw new NotOnLDAP('No user available for the given login name on '. |
|
171 | + $this->access->connection->ldapHost.':'.$this->access->connection->ldapPort); |
|
172 | 172 | } |
173 | 173 | return $users[0]; |
174 | 174 | } |
@@ -183,8 +183,8 @@ discard block |
||
183 | 183 | public function checkPassword($uid, $password) { |
184 | 184 | try { |
185 | 185 | $ldapRecord = $this->getLDAPUserByLoginName($uid); |
186 | - } catch(NotOnLDAP $e) { |
|
187 | - if($this->ocConfig->getSystemValue('loglevel', ILogger::WARN) === ILogger::DEBUG) { |
|
186 | + } catch (NotOnLDAP $e) { |
|
187 | + if ($this->ocConfig->getSystemValue('loglevel', ILogger::WARN) === ILogger::DEBUG) { |
|
188 | 188 | \OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']); |
189 | 189 | } |
190 | 190 | return false; |
@@ -192,16 +192,16 @@ discard block |
||
192 | 192 | $dn = $ldapRecord['dn'][0]; |
193 | 193 | $user = $this->access->userManager->get($dn); |
194 | 194 | |
195 | - if(!$user instanceof User) { |
|
195 | + if (!$user instanceof User) { |
|
196 | 196 | Util::writeLog('user_ldap', |
197 | - 'LDAP Login: Could not get user object for DN ' . $dn . |
|
197 | + 'LDAP Login: Could not get user object for DN '.$dn. |
|
198 | 198 | '. Maybe the LDAP entry has no set display name attribute?', |
199 | 199 | ILogger::WARN); |
200 | 200 | return false; |
201 | 201 | } |
202 | - if($user->getUsername() !== false) { |
|
202 | + if ($user->getUsername() !== false) { |
|
203 | 203 | //are the credentials OK? |
204 | - if(!$this->access->areCredentialsValid($dn, $password)) { |
|
204 | + if (!$this->access->areCredentialsValid($dn, $password)) { |
|
205 | 205 | return false; |
206 | 206 | } |
207 | 207 | |
@@ -228,14 +228,14 @@ discard block |
||
228 | 228 | |
229 | 229 | $user = $this->access->userManager->get($uid); |
230 | 230 | |
231 | - if(!$user instanceof User) { |
|
232 | - throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid . |
|
231 | + if (!$user instanceof User) { |
|
232 | + throw new \Exception('LDAP setPassword: Could not get user object for uid '.$uid. |
|
233 | 233 | '. Maybe the LDAP entry has no set display name attribute?'); |
234 | 234 | } |
235 | - if($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) { |
|
235 | + if ($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) { |
|
236 | 236 | $ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN; |
237 | 237 | $turnOnPasswordChange = $this->access->connection->turnOnPasswordChange; |
238 | - if (!empty($ldapDefaultPPolicyDN) && ((int)$turnOnPasswordChange === 1)) { |
|
238 | + if (!empty($ldapDefaultPPolicyDN) && ((int) $turnOnPasswordChange === 1)) { |
|
239 | 239 | //remove last password expiry warning if any |
240 | 240 | $notification = $this->notificationManager->createNotification(); |
241 | 241 | $notification->setApp('user_ldap') |
@@ -264,18 +264,18 @@ discard block |
||
264 | 264 | |
265 | 265 | //check if users are cached, if so return |
266 | 266 | $ldap_users = $this->access->connection->getFromCache($cachekey); |
267 | - if(!is_null($ldap_users)) { |
|
267 | + if (!is_null($ldap_users)) { |
|
268 | 268 | return $ldap_users; |
269 | 269 | } |
270 | 270 | |
271 | 271 | // if we'd pass -1 to LDAP search, we'd end up in a Protocol |
272 | 272 | // error. With a limit of 0, we get 0 results. So we pass null. |
273 | - if($limit <= 0) { |
|
273 | + if ($limit <= 0) { |
|
274 | 274 | $limit = null; |
275 | 275 | } |
276 | 276 | $filter = $this->access->combineFilterWithAnd(array( |
277 | 277 | $this->access->connection->ldapUserFilter, |
278 | - $this->access->connection->ldapUserDisplayName . '=*', |
|
278 | + $this->access->connection->ldapUserDisplayName.'=*', |
|
279 | 279 | $this->access->getFilterPartForUserSearch($search) |
280 | 280 | )); |
281 | 281 | |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | $this->access->userManager->getAttributes(true), |
289 | 289 | $limit, $offset); |
290 | 290 | $ldap_users = $this->access->nextcloudUserNames($ldap_users); |
291 | - Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', ILogger::DEBUG); |
|
291 | + Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users).' Users found', ILogger::DEBUG); |
|
292 | 292 | |
293 | 293 | $this->access->connection->writeToCache($cachekey, $ldap_users); |
294 | 294 | return $ldap_users; |
@@ -304,19 +304,19 @@ discard block |
||
304 | 304 | * @throws \OC\ServerNotAvailableException |
305 | 305 | */ |
306 | 306 | public function userExistsOnLDAP($user) { |
307 | - if(is_string($user)) { |
|
307 | + if (is_string($user)) { |
|
308 | 308 | $user = $this->access->userManager->get($user); |
309 | 309 | } |
310 | - if(is_null($user)) { |
|
310 | + if (is_null($user)) { |
|
311 | 311 | return false; |
312 | 312 | } |
313 | 313 | |
314 | 314 | $dn = $user->getDN(); |
315 | 315 | //check if user really still exists by reading its entry |
316 | - if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) { |
|
316 | + if (!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) { |
|
317 | 317 | $lcr = $this->access->connection->getConnectionResource(); |
318 | - if(is_null($lcr)) { |
|
319 | - throw new \Exception('No LDAP Connection to server ' . $this->access->connection->ldapHost); |
|
318 | + if (is_null($lcr)) { |
|
319 | + throw new \Exception('No LDAP Connection to server '.$this->access->connection->ldapHost); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | try { |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | } |
339 | 339 | } |
340 | 340 | |
341 | - if($user instanceof OfflineUser) { |
|
341 | + if ($user instanceof OfflineUser) { |
|
342 | 342 | $user->unmark(); |
343 | 343 | } |
344 | 344 | |
@@ -353,18 +353,18 @@ discard block |
||
353 | 353 | */ |
354 | 354 | public function userExists($uid) { |
355 | 355 | $userExists = $this->access->connection->getFromCache('userExists'.$uid); |
356 | - if(!is_null($userExists)) { |
|
357 | - return (bool)$userExists; |
|
356 | + if (!is_null($userExists)) { |
|
357 | + return (bool) $userExists; |
|
358 | 358 | } |
359 | 359 | //getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking. |
360 | 360 | $user = $this->access->userManager->get($uid); |
361 | 361 | |
362 | - if(is_null($user)) { |
|
362 | + if (is_null($user)) { |
|
363 | 363 | Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '. |
364 | 364 | $this->access->connection->ldapHost, ILogger::DEBUG); |
365 | 365 | $this->access->connection->writeToCache('userExists'.$uid, false); |
366 | 366 | return false; |
367 | - } else if($user instanceof OfflineUser) { |
|
367 | + } else if ($user instanceof OfflineUser) { |
|
368 | 368 | //express check for users marked as deleted. Returning true is |
369 | 369 | //necessary for cleanup |
370 | 370 | return true; |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | |
373 | 373 | $result = $this->userExistsOnLDAP($user); |
374 | 374 | $this->access->connection->writeToCache('userExists'.$uid, $result); |
375 | - if($result === true) { |
|
375 | + if ($result === true) { |
|
376 | 376 | $user->update(); |
377 | 377 | } |
378 | 378 | return $result; |
@@ -390,13 +390,13 @@ discard block |
||
390 | 390 | } |
391 | 391 | |
392 | 392 | $marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0); |
393 | - if((int)$marked === 0) { |
|
393 | + if ((int) $marked === 0) { |
|
394 | 394 | \OC::$server->getLogger()->notice( |
395 | - 'User '.$uid . ' is not marked as deleted, not cleaning up.', |
|
395 | + 'User '.$uid.' is not marked as deleted, not cleaning up.', |
|
396 | 396 | array('app' => 'user_ldap')); |
397 | 397 | return false; |
398 | 398 | } |
399 | - \OC::$server->getLogger()->info('Cleaning up after user ' . $uid, |
|
399 | + \OC::$server->getLogger()->info('Cleaning up after user '.$uid, |
|
400 | 400 | array('app' => 'user_ldap')); |
401 | 401 | |
402 | 402 | $this->access->getUserMapper()->unmap($uid); // we don't emit unassign signals here, since it is implicit to delete signals fired from core |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | */ |
415 | 415 | public function getHome($uid) { |
416 | 416 | // user Exists check required as it is not done in user proxy! |
417 | - if(!$this->userExists($uid)) { |
|
417 | + if (!$this->userExists($uid)) { |
|
418 | 418 | return false; |
419 | 419 | } |
420 | 420 | |
@@ -424,22 +424,22 @@ discard block |
||
424 | 424 | |
425 | 425 | $cacheKey = 'getHome'.$uid; |
426 | 426 | $path = $this->access->connection->getFromCache($cacheKey); |
427 | - if(!is_null($path)) { |
|
427 | + if (!is_null($path)) { |
|
428 | 428 | return $path; |
429 | 429 | } |
430 | 430 | |
431 | 431 | // early return path if it is a deleted user |
432 | 432 | $user = $this->access->userManager->get($uid); |
433 | - if($user instanceof OfflineUser) { |
|
434 | - if($this->currentUserInDeletionProcess !== null |
|
433 | + if ($user instanceof OfflineUser) { |
|
434 | + if ($this->currentUserInDeletionProcess !== null |
|
435 | 435 | && $this->currentUserInDeletionProcess === $user->getOCName() |
436 | 436 | ) { |
437 | 437 | return $user->getHomePath(); |
438 | 438 | } else { |
439 | - throw new NoUserException($uid . ' is not a valid user anymore'); |
|
439 | + throw new NoUserException($uid.' is not a valid user anymore'); |
|
440 | 440 | } |
441 | 441 | } else if ($user === null) { |
442 | - throw new NoUserException($uid . ' is not a valid user anymore'); |
|
442 | + throw new NoUserException($uid.' is not a valid user anymore'); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | $path = $user->getHomePath(); |
@@ -458,12 +458,12 @@ discard block |
||
458 | 458 | return $this->userPluginManager->getDisplayName($uid); |
459 | 459 | } |
460 | 460 | |
461 | - if(!$this->userExists($uid)) { |
|
461 | + if (!$this->userExists($uid)) { |
|
462 | 462 | return false; |
463 | 463 | } |
464 | 464 | |
465 | 465 | $cacheKey = 'getDisplayName'.$uid; |
466 | - if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { |
|
466 | + if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { |
|
467 | 467 | return $displayName; |
468 | 468 | } |
469 | 469 | |
@@ -480,10 +480,10 @@ discard block |
||
480 | 480 | $this->access->username2dn($uid), |
481 | 481 | $this->access->connection->ldapUserDisplayName); |
482 | 482 | |
483 | - if($displayName && (count($displayName) > 0)) { |
|
483 | + if ($displayName && (count($displayName) > 0)) { |
|
484 | 484 | $displayName = $displayName[0]; |
485 | 485 | |
486 | - if (is_array($displayName2)){ |
|
486 | + if (is_array($displayName2)) { |
|
487 | 487 | $displayName2 = count($displayName2) > 0 ? $displayName2[0] : ''; |
488 | 488 | } |
489 | 489 | |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | */ |
526 | 526 | public function getDisplayNames($search = '', $limit = null, $offset = null) { |
527 | 527 | $cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset; |
528 | - if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) { |
|
528 | + if (!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) { |
|
529 | 529 | return $displayNames; |
530 | 530 | } |
531 | 531 | |
@@ -547,12 +547,12 @@ discard block |
||
547 | 547 | * compared with \OC\User\Backend::CREATE_USER etc. |
548 | 548 | */ |
549 | 549 | public function implementsActions($actions) { |
550 | - return (bool)((Backend::CHECK_PASSWORD |
|
550 | + return (bool) ((Backend::CHECK_PASSWORD |
|
551 | 551 | | Backend::GET_HOME |
552 | 552 | | Backend::GET_DISPLAYNAME |
553 | 553 | | Backend::PROVIDE_AVATAR |
554 | 554 | | Backend::COUNT_USERS |
555 | - | (((int)$this->access->connection->turnOnPasswordChange === 1)? Backend::SET_PASSWORD :0) |
|
555 | + | (((int) $this->access->connection->turnOnPasswordChange === 1) ? Backend::SET_PASSWORD : 0) |
|
556 | 556 | | $this->userPluginManager->getImplementedActions()) |
557 | 557 | & $actions); |
558 | 558 | } |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | |
577 | 577 | $filter = $this->access->getFilterForUserCount(); |
578 | 578 | $cacheKey = 'countUsers-'.$filter; |
579 | - if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { |
|
579 | + if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { |
|
580 | 580 | return $entries; |
581 | 581 | } |
582 | 582 | $entries = $this->access->countUsers($filter); |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | * Backend name to be shown in user management |
589 | 589 | * @return string the name of the backend to be shown |
590 | 590 | */ |
591 | - public function getBackendName(){ |
|
591 | + public function getBackendName() { |
|
592 | 592 | return 'LDAP'; |
593 | 593 | } |
594 | 594 |
@@ -153,17 +153,17 @@ discard block |
||
153 | 153 | * @return null |
154 | 154 | */ |
155 | 155 | public function update() { |
156 | - if(is_null($this->dn)) { |
|
156 | + if (is_null($this->dn)) { |
|
157 | 157 | return null; |
158 | 158 | } |
159 | 159 | |
160 | 160 | $hasLoggedIn = $this->config->getUserValue($this->uid, 'user_ldap', |
161 | 161 | self::USER_PREFKEY_FIRSTLOGIN, 0); |
162 | 162 | |
163 | - if($this->needsRefresh()) { |
|
163 | + if ($this->needsRefresh()) { |
|
164 | 164 | $this->updateEmail(); |
165 | 165 | $this->updateQuota(); |
166 | - if($hasLoggedIn !== 0) { |
|
166 | + if ($hasLoggedIn !== 0) { |
|
167 | 167 | //we do not need to try it, when the user has not been logged in |
168 | 168 | //before, because the file system will not be ready. |
169 | 169 | $this->updateAvatar(); |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | $this->markRefreshTime(); |
183 | 183 | //Quota |
184 | 184 | $attr = strtolower($this->connection->ldapQuotaAttribute); |
185 | - if(isset($ldapEntry[$attr])) { |
|
185 | + if (isset($ldapEntry[$attr])) { |
|
186 | 186 | $this->updateQuota($ldapEntry[$attr][0]); |
187 | 187 | } else { |
188 | 188 | if ($this->connection->ldapQuotaDefault !== '') { |
@@ -194,12 +194,12 @@ discard block |
||
194 | 194 | //displayName |
195 | 195 | $displayName = $displayName2 = ''; |
196 | 196 | $attr = strtolower($this->connection->ldapUserDisplayName); |
197 | - if(isset($ldapEntry[$attr])) { |
|
198 | - $displayName = (string)$ldapEntry[$attr][0]; |
|
197 | + if (isset($ldapEntry[$attr])) { |
|
198 | + $displayName = (string) $ldapEntry[$attr][0]; |
|
199 | 199 | } |
200 | 200 | $attr = strtolower($this->connection->ldapUserDisplayName2); |
201 | - if(isset($ldapEntry[$attr])) { |
|
202 | - $displayName2 = (string)$ldapEntry[$attr][0]; |
|
201 | + if (isset($ldapEntry[$attr])) { |
|
202 | + $displayName2 = (string) $ldapEntry[$attr][0]; |
|
203 | 203 | } |
204 | 204 | if ($displayName !== '') { |
205 | 205 | $this->composeAndStoreDisplayName($displayName); |
@@ -215,22 +215,22 @@ discard block |
||
215 | 215 | //email must be stored after displayname, because it would cause a user |
216 | 216 | //change event that will trigger fetching the display name again |
217 | 217 | $attr = strtolower($this->connection->ldapEmailAttribute); |
218 | - if(isset($ldapEntry[$attr])) { |
|
218 | + if (isset($ldapEntry[$attr])) { |
|
219 | 219 | $this->updateEmail($ldapEntry[$attr][0]); |
220 | 220 | } |
221 | 221 | unset($attr); |
222 | 222 | |
223 | 223 | // LDAP Username, needed for s2s sharing |
224 | - if(isset($ldapEntry['uid'])) { |
|
224 | + if (isset($ldapEntry['uid'])) { |
|
225 | 225 | $this->storeLDAPUserName($ldapEntry['uid'][0]); |
226 | - } else if(isset($ldapEntry['samaccountname'])) { |
|
226 | + } else if (isset($ldapEntry['samaccountname'])) { |
|
227 | 227 | $this->storeLDAPUserName($ldapEntry['samaccountname'][0]); |
228 | 228 | } |
229 | 229 | |
230 | 230 | //homePath |
231 | - if(strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) { |
|
231 | + if (strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) { |
|
232 | 232 | $attr = strtolower(substr($this->connection->homeFolderNamingRule, strlen('attr:'))); |
233 | - if(isset($ldapEntry[$attr])) { |
|
233 | + if (isset($ldapEntry[$attr])) { |
|
234 | 234 | $this->access->cacheUserHome( |
235 | 235 | $this->getUsername(), $this->getHomePath($ldapEntry[$attr][0])); |
236 | 236 | } |
@@ -239,15 +239,15 @@ discard block |
||
239 | 239 | //memberOf groups |
240 | 240 | $cacheKey = 'getMemberOf'.$this->getUsername(); |
241 | 241 | $groups = false; |
242 | - if(isset($ldapEntry['memberof'])) { |
|
242 | + if (isset($ldapEntry['memberof'])) { |
|
243 | 243 | $groups = $ldapEntry['memberof']; |
244 | 244 | } |
245 | 245 | $this->connection->writeToCache($cacheKey, $groups); |
246 | 246 | |
247 | 247 | //Avatar |
248 | 248 | $attrs = array('jpegphoto', 'thumbnailphoto'); |
249 | - foreach ($attrs as $attr) { |
|
250 | - if(isset($ldapEntry[$attr])) { |
|
249 | + foreach ($attrs as $attr) { |
|
250 | + if (isset($ldapEntry[$attr])) { |
|
251 | 251 | $this->avatarImage = $ldapEntry[$attr][0]; |
252 | 252 | // the call to the method that saves the avatar in the file |
253 | 253 | // system must be postponed after the login. It is to ensure |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * @throws \Exception |
283 | 283 | */ |
284 | 284 | public function getHomePath($valueFromLDAP = null) { |
285 | - $path = (string)$valueFromLDAP; |
|
285 | + $path = (string) $valueFromLDAP; |
|
286 | 286 | $attr = null; |
287 | 287 | |
288 | 288 | if (is_null($valueFromLDAP) |
@@ -300,12 +300,12 @@ discard block |
||
300 | 300 | if ($path !== '') { |
301 | 301 | //if attribute's value is an absolute path take this, otherwise append it to data dir |
302 | 302 | //check for / at the beginning or pattern c:\ resp. c:/ |
303 | - if( '/' !== $path[0] |
|
303 | + if ('/' !== $path[0] |
|
304 | 304 | && !(3 < strlen($path) && ctype_alpha($path[0]) |
305 | 305 | && $path[1] === ':' && ('\\' === $path[2] || '/' === $path[2])) |
306 | 306 | ) { |
307 | 307 | $path = $this->config->getSystemValue('datadirectory', |
308 | - \OC::$SERVERROOT.'/data' ) . '/' . $path; |
|
308 | + \OC::$SERVERROOT.'/data').'/'.$path; |
|
309 | 309 | } |
310 | 310 | //we need it to store it in the DB as well in case a user gets |
311 | 311 | //deleted so we can clean up afterwards |
@@ -315,11 +315,11 @@ discard block |
||
315 | 315 | return $path; |
316 | 316 | } |
317 | 317 | |
318 | - if( !is_null($attr) |
|
318 | + if (!is_null($attr) |
|
319 | 319 | && $this->config->getAppValue('user_ldap', 'enforce_home_folder_naming_rule', true) |
320 | 320 | ) { |
321 | 321 | // a naming rule attribute is defined, but it doesn't exist for that LDAP user |
322 | - throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: ' . $this->getUsername()); |
|
322 | + throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: '.$this->getUsername()); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | //false will apply default behaviour as defined and done by OC_User |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | public function getMemberOfGroups() { |
331 | 331 | $cacheKey = 'getMemberOf'.$this->getUsername(); |
332 | 332 | $memberOfGroups = $this->connection->getFromCache($cacheKey); |
333 | - if(!is_null($memberOfGroups)) { |
|
333 | + if (!is_null($memberOfGroups)) { |
|
334 | 334 | return $memberOfGroups; |
335 | 335 | } |
336 | 336 | $groupDNs = $this->access->readAttribute($this->getDN(), 'memberOf'); |
@@ -343,15 +343,15 @@ discard block |
||
343 | 343 | * @return string data (provided by LDAP) | false |
344 | 344 | */ |
345 | 345 | public function getAvatarImage() { |
346 | - if(!is_null($this->avatarImage)) { |
|
346 | + if (!is_null($this->avatarImage)) { |
|
347 | 347 | return $this->avatarImage; |
348 | 348 | } |
349 | 349 | |
350 | 350 | $this->avatarImage = false; |
351 | 351 | $attributes = array('jpegPhoto', 'thumbnailPhoto'); |
352 | - foreach($attributes as $attribute) { |
|
352 | + foreach ($attributes as $attribute) { |
|
353 | 353 | $result = $this->access->readAttribute($this->dn, $attribute); |
354 | - if($result !== false && is_array($result) && isset($result[0])) { |
|
354 | + if ($result !== false && is_array($result) && isset($result[0])) { |
|
355 | 355 | $this->avatarImage = $result[0]; |
356 | 356 | break; |
357 | 357 | } |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | $lastChecked = $this->config->getUserValue($this->uid, 'user_ldap', |
389 | 389 | self::USER_PREFKEY_LASTREFRESH, 0); |
390 | 390 | |
391 | - if((time() - (int)$lastChecked) < (int)$this->config->getAppValue('user_ldap', 'updateAttributesInterval', 86400)) { |
|
391 | + if ((time() - (int) $lastChecked) < (int) $this->config->getAppValue('user_ldap', 'updateAttributesInterval', 86400)) { |
|
392 | 392 | return false; |
393 | 393 | } |
394 | 394 | return true; |
@@ -413,9 +413,9 @@ discard block |
||
413 | 413 | * @returns string the effective display name |
414 | 414 | */ |
415 | 415 | public function composeAndStoreDisplayName($displayName, $displayName2 = '') { |
416 | - $displayName2 = (string)$displayName2; |
|
417 | - if($displayName2 !== '') { |
|
418 | - $displayName .= ' (' . $displayName2 . ')'; |
|
416 | + $displayName2 = (string) $displayName2; |
|
417 | + if ($displayName2 !== '') { |
|
418 | + $displayName .= ' ('.$displayName2.')'; |
|
419 | 419 | } |
420 | 420 | $this->store('displayName', $displayName); |
421 | 421 | return $displayName; |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | * @return bool |
438 | 438 | */ |
439 | 439 | private function wasRefreshed($feature) { |
440 | - if(isset($this->refreshedFeatures[$feature])) { |
|
440 | + if (isset($this->refreshedFeatures[$feature])) { |
|
441 | 441 | return true; |
442 | 442 | } |
443 | 443 | $this->refreshedFeatures[$feature] = 1; |
@@ -450,23 +450,23 @@ discard block |
||
450 | 450 | * @return null |
451 | 451 | */ |
452 | 452 | public function updateEmail($valueFromLDAP = null) { |
453 | - if($this->wasRefreshed('email')) { |
|
453 | + if ($this->wasRefreshed('email')) { |
|
454 | 454 | return; |
455 | 455 | } |
456 | - $email = (string)$valueFromLDAP; |
|
457 | - if(is_null($valueFromLDAP)) { |
|
456 | + $email = (string) $valueFromLDAP; |
|
457 | + if (is_null($valueFromLDAP)) { |
|
458 | 458 | $emailAttribute = $this->connection->ldapEmailAttribute; |
459 | 459 | if ($emailAttribute !== '') { |
460 | 460 | $aEmail = $this->access->readAttribute($this->dn, $emailAttribute); |
461 | - if(is_array($aEmail) && (count($aEmail) > 0)) { |
|
462 | - $email = (string)$aEmail[0]; |
|
461 | + if (is_array($aEmail) && (count($aEmail) > 0)) { |
|
462 | + $email = (string) $aEmail[0]; |
|
463 | 463 | } |
464 | 464 | } |
465 | 465 | } |
466 | 466 | if ($email !== '') { |
467 | 467 | $user = $this->userManager->get($this->uid); |
468 | 468 | if (!is_null($user)) { |
469 | - $currentEmail = (string)$user->getEMailAddress(); |
|
469 | + $currentEmail = (string) $user->getEMailAddress(); |
|
470 | 470 | if ($currentEmail !== $email) { |
471 | 471 | $user->setEMailAddress($email); |
472 | 472 | } |
@@ -495,35 +495,35 @@ discard block |
||
495 | 495 | * @return null |
496 | 496 | */ |
497 | 497 | public function updateQuota($valueFromLDAP = null) { |
498 | - if($this->wasRefreshed('quota')) { |
|
498 | + if ($this->wasRefreshed('quota')) { |
|
499 | 499 | return; |
500 | 500 | } |
501 | 501 | |
502 | 502 | $quotaAttribute = $this->connection->ldapQuotaAttribute; |
503 | 503 | $defaultQuota = $this->connection->ldapQuotaDefault; |
504 | - if($quotaAttribute === '' && $defaultQuota === '') { |
|
504 | + if ($quotaAttribute === '' && $defaultQuota === '') { |
|
505 | 505 | return; |
506 | 506 | } |
507 | 507 | |
508 | 508 | $quota = false; |
509 | - if(is_null($valueFromLDAP) && $quotaAttribute !== '') { |
|
509 | + if (is_null($valueFromLDAP) && $quotaAttribute !== '') { |
|
510 | 510 | $aQuota = $this->access->readAttribute($this->dn, $quotaAttribute); |
511 | - if($aQuota && (count($aQuota) > 0) && $this->verifyQuotaValue($aQuota[0])) { |
|
511 | + if ($aQuota && (count($aQuota) > 0) && $this->verifyQuotaValue($aQuota[0])) { |
|
512 | 512 | $quota = $aQuota[0]; |
513 | - } else if(is_array($aQuota) && isset($aQuota[0])) { |
|
514 | - $this->log->log('no suitable LDAP quota found for user ' . $this->uid . ': [' . $aQuota[0] . ']', ILogger::DEBUG); |
|
513 | + } else if (is_array($aQuota) && isset($aQuota[0])) { |
|
514 | + $this->log->log('no suitable LDAP quota found for user '.$this->uid.': ['.$aQuota[0].']', ILogger::DEBUG); |
|
515 | 515 | } |
516 | 516 | } else if ($this->verifyQuotaValue($valueFromLDAP)) { |
517 | 517 | $quota = $valueFromLDAP; |
518 | 518 | } else { |
519 | - $this->log->log('no suitable LDAP quota found for user ' . $this->uid . ': [' . $valueFromLDAP . ']', ILogger::DEBUG); |
|
519 | + $this->log->log('no suitable LDAP quota found for user '.$this->uid.': ['.$valueFromLDAP.']', ILogger::DEBUG); |
|
520 | 520 | } |
521 | 521 | |
522 | 522 | if ($quota === false && $this->verifyQuotaValue($defaultQuota)) { |
523 | 523 | // quota not found using the LDAP attribute (or not parseable). Try the default quota |
524 | 524 | $quota = $defaultQuota; |
525 | - } else if($quota === false) { |
|
526 | - $this->log->log('no suitable default quota found for user ' . $this->uid . ': [' . $defaultQuota . ']', ILogger::DEBUG); |
|
525 | + } else if ($quota === false) { |
|
526 | + $this->log->log('no suitable default quota found for user '.$this->uid.': ['.$defaultQuota.']', ILogger::DEBUG); |
|
527 | 527 | return; |
528 | 528 | } |
529 | 529 | |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | if ($targetUser instanceof IUser) { |
532 | 532 | $targetUser->setQuota($quota); |
533 | 533 | } else { |
534 | - $this->log->log('trying to set a quota for user ' . $this->uid . ' but the user is missing', ILogger::INFO); |
|
534 | + $this->log->log('trying to set a quota for user '.$this->uid.' but the user is missing', ILogger::INFO); |
|
535 | 535 | } |
536 | 536 | } |
537 | 537 | |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | * @param array $params |
546 | 546 | */ |
547 | 547 | public function updateAvatarPostLogin($params) { |
548 | - if(isset($params['uid']) && $params['uid'] === $this->getUsername()) { |
|
548 | + if (isset($params['uid']) && $params['uid'] === $this->getUsername()) { |
|
549 | 549 | $this->updateAvatar(); |
550 | 550 | } |
551 | 551 | } |
@@ -555,15 +555,15 @@ discard block |
||
555 | 555 | * @return bool |
556 | 556 | */ |
557 | 557 | public function updateAvatar($force = false) { |
558 | - if(!$force && $this->wasRefreshed('avatar')) { |
|
558 | + if (!$force && $this->wasRefreshed('avatar')) { |
|
559 | 559 | return false; |
560 | 560 | } |
561 | 561 | $avatarImage = $this->getAvatarImage(); |
562 | - if($avatarImage === false) { |
|
562 | + if ($avatarImage === false) { |
|
563 | 563 | //not set, nothing left to do; |
564 | 564 | return false; |
565 | 565 | } |
566 | - if(!$this->image->loadFromBase64(base64_encode($avatarImage))) { |
|
566 | + if (!$this->image->loadFromBase64(base64_encode($avatarImage))) { |
|
567 | 567 | return false; |
568 | 568 | } |
569 | 569 | return $this->setOwnCloudAvatar(); |
@@ -574,18 +574,18 @@ discard block |
||
574 | 574 | * @return bool |
575 | 575 | */ |
576 | 576 | private function setOwnCloudAvatar() { |
577 | - if(!$this->image->valid()) { |
|
577 | + if (!$this->image->valid()) { |
|
578 | 578 | $this->log->log('jpegPhoto data invalid for '.$this->dn, ILogger::ERROR); |
579 | 579 | return false; |
580 | 580 | } |
581 | 581 | //make sure it is a square and not bigger than 128x128 |
582 | 582 | $size = min(array($this->image->width(), $this->image->height(), 128)); |
583 | - if(!$this->image->centerCrop($size)) { |
|
583 | + if (!$this->image->centerCrop($size)) { |
|
584 | 584 | $this->log->log('croping image for avatar failed for '.$this->dn, ILogger::ERROR); |
585 | 585 | return false; |
586 | 586 | } |
587 | 587 | |
588 | - if(!$this->fs->isLoaded()) { |
|
588 | + if (!$this->fs->isLoaded()) { |
|
589 | 589 | $this->fs->setup($this->uid); |
590 | 590 | } |
591 | 591 | |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | return true; |
596 | 596 | } catch (\Exception $e) { |
597 | 597 | \OC::$server->getLogger()->logException($e, [ |
598 | - 'message' => 'Could not set avatar for ' . $this->dn, |
|
598 | + 'message' => 'Could not set avatar for '.$this->dn, |
|
599 | 599 | 'level' => ILogger::INFO, |
600 | 600 | 'app' => 'user_ldap', |
601 | 601 | ]); |
@@ -610,18 +610,18 @@ discard block |
||
610 | 610 | */ |
611 | 611 | public function handlePasswordExpiry($params) { |
612 | 612 | $ppolicyDN = $this->connection->ldapDefaultPPolicyDN; |
613 | - if (empty($ppolicyDN) || ((int)$this->connection->turnOnPasswordChange !== 1)) { |
|
614 | - return;//password expiry handling disabled |
|
613 | + if (empty($ppolicyDN) || ((int) $this->connection->turnOnPasswordChange !== 1)) { |
|
614 | + return; //password expiry handling disabled |
|
615 | 615 | } |
616 | 616 | $uid = $params['uid']; |
617 | - if(isset($uid) && $uid === $this->getUsername()) { |
|
617 | + if (isset($uid) && $uid === $this->getUsername()) { |
|
618 | 618 | //retrieve relevant user attributes |
619 | 619 | $result = $this->access->search('objectclass=*', array($this->dn), ['pwdpolicysubentry', 'pwdgraceusetime', 'pwdreset', 'pwdchangedtime']); |
620 | 620 | |
621 | - if(array_key_exists('pwdpolicysubentry', $result[0])) { |
|
621 | + if (array_key_exists('pwdpolicysubentry', $result[0])) { |
|
622 | 622 | $pwdPolicySubentry = $result[0]['pwdpolicysubentry']; |
623 | - if($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)){ |
|
624 | - $ppolicyDN = $pwdPolicySubentry[0];//custom ppolicy DN |
|
623 | + if ($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)) { |
|
624 | + $ppolicyDN = $pwdPolicySubentry[0]; //custom ppolicy DN |
|
625 | 625 | } |
626 | 626 | } |
627 | 627 | |
@@ -630,9 +630,9 @@ discard block |
||
630 | 630 | $pwdChangedTime = array_key_exists('pwdchangedtime', $result[0]) ? $result[0]['pwdchangedtime'] : null; |
631 | 631 | |
632 | 632 | //retrieve relevant password policy attributes |
633 | - $cacheKey = 'ppolicyAttributes' . $ppolicyDN; |
|
633 | + $cacheKey = 'ppolicyAttributes'.$ppolicyDN; |
|
634 | 634 | $result = $this->connection->getFromCache($cacheKey); |
635 | - if(is_null($result)) { |
|
635 | + if (is_null($result)) { |
|
636 | 636 | $result = $this->access->search('objectclass=*', array($ppolicyDN), ['pwdgraceauthnlimit', 'pwdmaxage', 'pwdexpirewarning']); |
637 | 637 | $this->connection->writeToCache($cacheKey, $result); |
638 | 638 | } |
@@ -643,10 +643,10 @@ discard block |
||
643 | 643 | |
644 | 644 | //handle grace login |
645 | 645 | $pwdGraceUseTimeCount = count($pwdGraceUseTime); |
646 | - if($pwdGraceUseTime && $pwdGraceUseTimeCount > 0) { //was this a grace login? |
|
647 | - if($pwdGraceAuthNLimit |
|
646 | + if ($pwdGraceUseTime && $pwdGraceUseTimeCount > 0) { //was this a grace login? |
|
647 | + if ($pwdGraceAuthNLimit |
|
648 | 648 | && (count($pwdGraceAuthNLimit) > 0) |
649 | - &&($pwdGraceUseTimeCount < (int)$pwdGraceAuthNLimit[0])) { //at least one more grace login available? |
|
649 | + &&($pwdGraceUseTimeCount < (int) $pwdGraceAuthNLimit[0])) { //at least one more grace login available? |
|
650 | 650 | $this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true'); |
651 | 651 | header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute( |
652 | 652 | 'user_ldap.renewPassword.showRenewPasswordForm', array('user' => $uid))); |
@@ -657,24 +657,24 @@ discard block |
||
657 | 657 | exit(); |
658 | 658 | } |
659 | 659 | //handle pwdReset attribute |
660 | - if($pwdReset && (count($pwdReset) > 0) && $pwdReset[0] === 'TRUE') { //user must change his password |
|
660 | + if ($pwdReset && (count($pwdReset) > 0) && $pwdReset[0] === 'TRUE') { //user must change his password |
|
661 | 661 | $this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true'); |
662 | 662 | header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute( |
663 | 663 | 'user_ldap.renewPassword.showRenewPasswordForm', array('user' => $uid))); |
664 | 664 | exit(); |
665 | 665 | } |
666 | 666 | //handle password expiry warning |
667 | - if($pwdChangedTime && (count($pwdChangedTime) > 0)) { |
|
668 | - if($pwdMaxAge && (count($pwdMaxAge) > 0) |
|
667 | + if ($pwdChangedTime && (count($pwdChangedTime) > 0)) { |
|
668 | + if ($pwdMaxAge && (count($pwdMaxAge) > 0) |
|
669 | 669 | && $pwdExpireWarning && (count($pwdExpireWarning) > 0)) { |
670 | - $pwdMaxAgeInt = (int)$pwdMaxAge[0]; |
|
671 | - $pwdExpireWarningInt = (int)$pwdExpireWarning[0]; |
|
672 | - if($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0){ |
|
670 | + $pwdMaxAgeInt = (int) $pwdMaxAge[0]; |
|
671 | + $pwdExpireWarningInt = (int) $pwdExpireWarning[0]; |
|
672 | + if ($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0) { |
|
673 | 673 | $pwdChangedTimeDt = \DateTime::createFromFormat('YmdHisZ', $pwdChangedTime[0]); |
674 | 674 | $pwdChangedTimeDt->add(new \DateInterval('PT'.$pwdMaxAgeInt.'S')); |
675 | 675 | $currentDateTime = new \DateTime(); |
676 | 676 | $secondsToExpiry = $pwdChangedTimeDt->getTimestamp() - $currentDateTime->getTimestamp(); |
677 | - if($secondsToExpiry <= $pwdExpireWarningInt) { |
|
677 | + if ($secondsToExpiry <= $pwdExpireWarningInt) { |
|
678 | 678 | //remove last password expiry warning if any |
679 | 679 | $notification = $this->notificationManager->createNotification(); |
680 | 680 | $notification->setApp('user_ldap') |