@@ -68,13 +68,13 @@ discard block |
||
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | protected function registerHooks() { |
| 71 | - Util::connectHook('OC_User','pre_deleteUser', $this, 'preDeleteUser'); |
|
| 72 | - Util::connectHook('OC_User','post_deleteUser', $this, 'postDeleteUser'); |
|
| 71 | + Util::connectHook('OC_User', 'pre_deleteUser', $this, 'preDeleteUser'); |
|
| 72 | + Util::connectHook('OC_User', 'post_deleteUser', $this, 'postDeleteUser'); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | public function preDeleteUser(array $param) { |
| 76 | 76 | $user = $param[0]; |
| 77 | - if(!$user instanceof IUser) { |
|
| 77 | + if (!$user instanceof IUser) { |
|
| 78 | 78 | throw new \RuntimeException('IUser expected'); |
| 79 | 79 | } |
| 80 | 80 | $this->currentUserInDeletionProcess = $user->getUID(); |
@@ -91,10 +91,10 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | public function canChangeAvatar($uid) { |
| 93 | 93 | $user = $this->access->userManager->get($uid); |
| 94 | - if(!$user instanceof User) { |
|
| 94 | + if (!$user instanceof User) { |
|
| 95 | 95 | return false; |
| 96 | 96 | } |
| 97 | - if($user->getAvatarImage() === false) { |
|
| 97 | + if ($user->getAvatarImage() === false) { |
|
| 98 | 98 | return true; |
| 99 | 99 | } |
| 100 | 100 | |
@@ -110,14 +110,14 @@ discard block |
||
| 110 | 110 | public function loginName2UserName($loginName) { |
| 111 | 111 | $cacheKey = 'loginName2UserName-'.$loginName; |
| 112 | 112 | $username = $this->access->connection->getFromCache($cacheKey); |
| 113 | - if(!is_null($username)) { |
|
| 113 | + if (!is_null($username)) { |
|
| 114 | 114 | return $username; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | try { |
| 118 | 118 | $ldapRecord = $this->getLDAPUserByLoginName($loginName); |
| 119 | 119 | $user = $this->access->userManager->get($ldapRecord['dn'][0]); |
| 120 | - if($user instanceof OfflineUser) { |
|
| 120 | + if ($user instanceof OfflineUser) { |
|
| 121 | 121 | // this path is not really possible, however get() is documented |
| 122 | 122 | // to return User or OfflineUser so we are very defensive here. |
| 123 | 123 | $this->access->connection->writeToCache($cacheKey, false); |
@@ -153,9 +153,9 @@ discard block |
||
| 153 | 153 | //find out dn of the user name |
| 154 | 154 | $attrs = $this->access->userManager->getAttributes(); |
| 155 | 155 | $users = $this->access->fetchUsersByLoginName($loginName, $attrs); |
| 156 | - if(count($users) < 1) { |
|
| 157 | - throw new NotOnLDAP('No user available for the given login name on ' . |
|
| 158 | - $this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort); |
|
| 156 | + if (count($users) < 1) { |
|
| 157 | + throw new NotOnLDAP('No user available for the given login name on '. |
|
| 158 | + $this->access->connection->ldapHost.':'.$this->access->connection->ldapPort); |
|
| 159 | 159 | } |
| 160 | 160 | return $users[0]; |
| 161 | 161 | } |
@@ -170,8 +170,8 @@ discard block |
||
| 170 | 170 | public function checkPassword($uid, $password) { |
| 171 | 171 | try { |
| 172 | 172 | $ldapRecord = $this->getLDAPUserByLoginName($uid); |
| 173 | - } catch(NotOnLDAP $e) { |
|
| 174 | - if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { |
|
| 173 | + } catch (NotOnLDAP $e) { |
|
| 174 | + if ($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { |
|
| 175 | 175 | \OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']); |
| 176 | 176 | } |
| 177 | 177 | return false; |
@@ -179,16 +179,16 @@ discard block |
||
| 179 | 179 | $dn = $ldapRecord['dn'][0]; |
| 180 | 180 | $user = $this->access->userManager->get($dn); |
| 181 | 181 | |
| 182 | - if(!$user instanceof User) { |
|
| 182 | + if (!$user instanceof User) { |
|
| 183 | 183 | Util::writeLog('user_ldap', |
| 184 | - 'LDAP Login: Could not get user object for DN ' . $dn . |
|
| 184 | + 'LDAP Login: Could not get user object for DN '.$dn. |
|
| 185 | 185 | '. Maybe the LDAP entry has no set display name attribute?', |
| 186 | 186 | Util::WARN); |
| 187 | 187 | return false; |
| 188 | 188 | } |
| 189 | - if($user->getUsername() !== false) { |
|
| 189 | + if ($user->getUsername() !== false) { |
|
| 190 | 190 | //are the credentials OK? |
| 191 | - if(!$this->access->areCredentialsValid($dn, $password)) { |
|
| 191 | + if (!$this->access->areCredentialsValid($dn, $password)) { |
|
| 192 | 192 | return false; |
| 193 | 193 | } |
| 194 | 194 | |
@@ -211,11 +211,11 @@ discard block |
||
| 211 | 211 | public function setPassword($uid, $password) { |
| 212 | 212 | $user = $this->access->userManager->get($uid); |
| 213 | 213 | |
| 214 | - if(!$user instanceof User) { |
|
| 215 | - throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid . |
|
| 214 | + if (!$user instanceof User) { |
|
| 215 | + throw new \Exception('LDAP setPassword: Could not get user object for uid '.$uid. |
|
| 216 | 216 | '. Maybe the LDAP entry has no set display name attribute?'); |
| 217 | 217 | } |
| 218 | - if($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) { |
|
| 218 | + if ($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) { |
|
| 219 | 219 | $ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN; |
| 220 | 220 | $turnOnPasswordChange = $this->access->connection->turnOnPasswordChange; |
| 221 | 221 | if (!empty($ldapDefaultPPolicyDN) && (intval($turnOnPasswordChange) === 1)) { |
@@ -247,18 +247,18 @@ discard block |
||
| 247 | 247 | |
| 248 | 248 | //check if users are cached, if so return |
| 249 | 249 | $ldap_users = $this->access->connection->getFromCache($cachekey); |
| 250 | - if(!is_null($ldap_users)) { |
|
| 250 | + if (!is_null($ldap_users)) { |
|
| 251 | 251 | return $ldap_users; |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | // if we'd pass -1 to LDAP search, we'd end up in a Protocol |
| 255 | 255 | // error. With a limit of 0, we get 0 results. So we pass null. |
| 256 | - if($limit <= 0) { |
|
| 256 | + if ($limit <= 0) { |
|
| 257 | 257 | $limit = null; |
| 258 | 258 | } |
| 259 | 259 | $filter = $this->access->combineFilterWithAnd(array( |
| 260 | 260 | $this->access->connection->ldapUserFilter, |
| 261 | - $this->access->connection->ldapUserDisplayName . '=*', |
|
| 261 | + $this->access->connection->ldapUserDisplayName.'=*', |
|
| 262 | 262 | $this->access->getFilterPartForUserSearch($search) |
| 263 | 263 | )); |
| 264 | 264 | |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | $this->access->userManager->getAttributes(true), |
| 272 | 272 | $limit, $offset); |
| 273 | 273 | $ldap_users = $this->access->nextcloudUserNames($ldap_users); |
| 274 | - Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG); |
|
| 274 | + Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users).' Users found', Util::DEBUG); |
|
| 275 | 275 | |
| 276 | 276 | $this->access->connection->writeToCache($cachekey, $ldap_users); |
| 277 | 277 | return $ldap_users; |
@@ -287,29 +287,29 @@ discard block |
||
| 287 | 287 | * @throws \OC\ServerNotAvailableException |
| 288 | 288 | */ |
| 289 | 289 | public function userExistsOnLDAP($user) { |
| 290 | - if(is_string($user)) { |
|
| 290 | + if (is_string($user)) { |
|
| 291 | 291 | $user = $this->access->userManager->get($user); |
| 292 | 292 | } |
| 293 | - if(is_null($user)) { |
|
| 293 | + if (is_null($user)) { |
|
| 294 | 294 | return false; |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | $dn = $user->getDN(); |
| 298 | 298 | //check if user really still exists by reading its entry |
| 299 | - if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) { |
|
| 299 | + if (!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) { |
|
| 300 | 300 | $lcr = $this->access->connection->getConnectionResource(); |
| 301 | - if(is_null($lcr)) { |
|
| 302 | - throw new \Exception('No LDAP Connection to server ' . $this->access->connection->ldapHost); |
|
| 301 | + if (is_null($lcr)) { |
|
| 302 | + throw new \Exception('No LDAP Connection to server '.$this->access->connection->ldapHost); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | try { |
| 306 | 306 | $uuid = $this->access->getUserMapper()->getUUIDByDN($dn); |
| 307 | - if(!$uuid) { |
|
| 307 | + if (!$uuid) { |
|
| 308 | 308 | return false; |
| 309 | 309 | } |
| 310 | 310 | $newDn = $this->access->getUserDnByUuid($uuid); |
| 311 | 311 | //check if renamed user is still valid by reapplying the ldap filter |
| 312 | - if(!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) { |
|
| 312 | + if (!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) { |
|
| 313 | 313 | return false; |
| 314 | 314 | } |
| 315 | 315 | $this->access->getUserMapper()->setDNbyUUID($newDn, $uuid); |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | } |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - if($user instanceof OfflineUser) { |
|
| 322 | + if ($user instanceof OfflineUser) { |
|
| 323 | 323 | $user->unmark(); |
| 324 | 324 | } |
| 325 | 325 | |
@@ -334,18 +334,18 @@ discard block |
||
| 334 | 334 | */ |
| 335 | 335 | public function userExists($uid) { |
| 336 | 336 | $userExists = $this->access->connection->getFromCache('userExists'.$uid); |
| 337 | - if(!is_null($userExists)) { |
|
| 338 | - return (bool)$userExists; |
|
| 337 | + if (!is_null($userExists)) { |
|
| 338 | + return (bool) $userExists; |
|
| 339 | 339 | } |
| 340 | 340 | //getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking. |
| 341 | 341 | $user = $this->access->userManager->get($uid); |
| 342 | 342 | |
| 343 | - if(is_null($user)) { |
|
| 343 | + if (is_null($user)) { |
|
| 344 | 344 | Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '. |
| 345 | 345 | $this->access->connection->ldapHost, Util::DEBUG); |
| 346 | 346 | $this->access->connection->writeToCache('userExists'.$uid, false); |
| 347 | 347 | return false; |
| 348 | - } else if($user instanceof OfflineUser) { |
|
| 348 | + } else if ($user instanceof OfflineUser) { |
|
| 349 | 349 | //express check for users marked as deleted. Returning true is |
| 350 | 350 | //necessary for cleanup |
| 351 | 351 | return true; |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | |
| 354 | 354 | $result = $this->userExistsOnLDAP($user); |
| 355 | 355 | $this->access->connection->writeToCache('userExists'.$uid, $result); |
| 356 | - if($result === true) { |
|
| 356 | + if ($result === true) { |
|
| 357 | 357 | $user->update(); |
| 358 | 358 | } |
| 359 | 359 | return $result; |
@@ -367,13 +367,13 @@ discard block |
||
| 367 | 367 | */ |
| 368 | 368 | public function deleteUser($uid) { |
| 369 | 369 | $marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0); |
| 370 | - if(intval($marked) === 0) { |
|
| 370 | + if (intval($marked) === 0) { |
|
| 371 | 371 | \OC::$server->getLogger()->notice( |
| 372 | - 'User '.$uid . ' is not marked as deleted, not cleaning up.', |
|
| 372 | + 'User '.$uid.' is not marked as deleted, not cleaning up.', |
|
| 373 | 373 | array('app' => 'user_ldap')); |
| 374 | 374 | return false; |
| 375 | 375 | } |
| 376 | - \OC::$server->getLogger()->info('Cleaning up after user ' . $uid, |
|
| 376 | + \OC::$server->getLogger()->info('Cleaning up after user '.$uid, |
|
| 377 | 377 | array('app' => 'user_ldap')); |
| 378 | 378 | |
| 379 | 379 | //Get Home Directory out of user preferences so we can return it later, |
@@ -393,26 +393,26 @@ discard block |
||
| 393 | 393 | */ |
| 394 | 394 | public function getHome($uid) { |
| 395 | 395 | // user Exists check required as it is not done in user proxy! |
| 396 | - if(!$this->userExists($uid)) { |
|
| 396 | + if (!$this->userExists($uid)) { |
|
| 397 | 397 | return false; |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | $cacheKey = 'getHome'.$uid; |
| 401 | 401 | $path = $this->access->connection->getFromCache($cacheKey); |
| 402 | - if(!is_null($path)) { |
|
| 402 | + if (!is_null($path)) { |
|
| 403 | 403 | return $path; |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | // early return path if it is a deleted user |
| 407 | 407 | $user = $this->access->userManager->get($uid); |
| 408 | - if($user instanceof OfflineUser) { |
|
| 409 | - if($this->currentUserInDeletionProcess === $user->getUID()) { |
|
| 408 | + if ($user instanceof OfflineUser) { |
|
| 409 | + if ($this->currentUserInDeletionProcess === $user->getUID()) { |
|
| 410 | 410 | return $user->getHomePath(); |
| 411 | 411 | } else { |
| 412 | - throw new NoUserException($uid . ' is not a valid user anymore'); |
|
| 412 | + throw new NoUserException($uid.' is not a valid user anymore'); |
|
| 413 | 413 | } |
| 414 | 414 | } else if ($user === null) { |
| 415 | - throw new NoUserException($uid . ' is not a valid user anymore'); |
|
| 415 | + throw new NoUserException($uid.' is not a valid user anymore'); |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | $path = $user->getHomePath(); |
@@ -427,12 +427,12 @@ discard block |
||
| 427 | 427 | * @return string|false display name |
| 428 | 428 | */ |
| 429 | 429 | public function getDisplayName($uid) { |
| 430 | - if(!$this->userExists($uid)) { |
|
| 430 | + if (!$this->userExists($uid)) { |
|
| 431 | 431 | return false; |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | $cacheKey = 'getDisplayName'.$uid; |
| 435 | - if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { |
|
| 435 | + if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { |
|
| 436 | 436 | return $displayName; |
| 437 | 437 | } |
| 438 | 438 | |
@@ -449,10 +449,10 @@ discard block |
||
| 449 | 449 | $this->access->username2dn($uid), |
| 450 | 450 | $this->access->connection->ldapUserDisplayName); |
| 451 | 451 | |
| 452 | - if($displayName && (count($displayName) > 0)) { |
|
| 452 | + if ($displayName && (count($displayName) > 0)) { |
|
| 453 | 453 | $displayName = $displayName[0]; |
| 454 | 454 | |
| 455 | - if (is_array($displayName2)){ |
|
| 455 | + if (is_array($displayName2)) { |
|
| 456 | 456 | $displayName2 = count($displayName2) > 0 ? $displayName2[0] : ''; |
| 457 | 457 | } |
| 458 | 458 | |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | */ |
| 482 | 482 | public function getDisplayNames($search = '', $limit = null, $offset = null) { |
| 483 | 483 | $cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset; |
| 484 | - if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) { |
|
| 484 | + if (!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) { |
|
| 485 | 485 | return $displayNames; |
| 486 | 486 | } |
| 487 | 487 | |
@@ -503,12 +503,12 @@ discard block |
||
| 503 | 503 | * compared with OC_USER_BACKEND_CREATE_USER etc. |
| 504 | 504 | */ |
| 505 | 505 | public function implementsActions($actions) { |
| 506 | - return (bool)((Backend::CHECK_PASSWORD |
|
| 506 | + return (bool) ((Backend::CHECK_PASSWORD |
|
| 507 | 507 | | Backend::GET_HOME |
| 508 | 508 | | Backend::GET_DISPLAYNAME |
| 509 | 509 | | Backend::PROVIDE_AVATAR |
| 510 | 510 | | Backend::COUNT_USERS |
| 511 | - | ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0)) |
|
| 511 | + | ((intval($this->access->connection->turnOnPasswordChange) === 1) ? (Backend::SET_PASSWORD) : 0)) |
|
| 512 | 512 | & $actions); |
| 513 | 513 | } |
| 514 | 514 | |
@@ -527,7 +527,7 @@ discard block |
||
| 527 | 527 | public function countUsers() { |
| 528 | 528 | $filter = $this->access->getFilterForUserCount(); |
| 529 | 529 | $cacheKey = 'countUsers-'.$filter; |
| 530 | - if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { |
|
| 530 | + if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { |
|
| 531 | 531 | return $entries; |
| 532 | 532 | } |
| 533 | 533 | $entries = $this->access->countUsers($filter); |
@@ -539,7 +539,7 @@ discard block |
||
| 539 | 539 | * Backend name to be shown in user management |
| 540 | 540 | * @return string the name of the backend to be shown |
| 541 | 541 | */ |
| 542 | - public function getBackendName(){ |
|
| 542 | + public function getBackendName() { |
|
| 543 | 543 | return 'LDAP'; |
| 544 | 544 | } |
| 545 | 545 | |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | * @param $uid |
| 140 | 140 | */ |
| 141 | 141 | public function invalidate($uid) { |
| 142 | - if(!isset($this->usersByUid[$uid])) { |
|
| 142 | + if (!isset($this->usersByUid[$uid])) { |
|
| 143 | 143 | return; |
| 144 | 144 | } |
| 145 | 145 | $dn = $this->usersByUid[$uid]->getDN(); |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @return null |
| 154 | 154 | */ |
| 155 | 155 | private function checkAccess() { |
| 156 | - if(is_null($this->access)) { |
|
| 156 | + if (is_null($this->access)) { |
|
| 157 | 157 | throw new \Exception('LDAP Access instance must be set first'); |
| 158 | 158 | } |
| 159 | 159 | } |
@@ -173,18 +173,18 @@ discard block |
||
| 173 | 173 | $this->access->getConnection()->ldapUserDisplayName, |
| 174 | 174 | $this->access->getConnection()->ldapUserDisplayName2, |
| 175 | 175 | ); |
| 176 | - foreach($possible as $attr) { |
|
| 177 | - if(!is_null($attr)) { |
|
| 176 | + foreach ($possible as $attr) { |
|
| 177 | + if (!is_null($attr)) { |
|
| 178 | 178 | $attributes[] = $attr; |
| 179 | 179 | } |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | $homeRule = $this->access->getConnection()->homeFolderNamingRule; |
| 183 | - if(strpos($homeRule, 'attr:') === 0) { |
|
| 183 | + if (strpos($homeRule, 'attr:') === 0) { |
|
| 184 | 184 | $attributes[] = substr($homeRule, strlen('attr:')); |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - if(!$minimal) { |
|
| 187 | + if (!$minimal) { |
|
| 188 | 188 | // attributes that are not really important but may come with big |
| 189 | 189 | // payload. |
| 190 | 190 | $attributes = array_merge($attributes, array( |
@@ -227,11 +227,11 @@ discard block |
||
| 227 | 227 | */ |
| 228 | 228 | protected function createInstancyByUserName($id) { |
| 229 | 229 | //most likely a uid. Check whether it is a deleted user |
| 230 | - if($this->isDeletedUser($id)) { |
|
| 230 | + if ($this->isDeletedUser($id)) { |
|
| 231 | 231 | return $this->getDeletedUser($id); |
| 232 | 232 | } |
| 233 | 233 | $dn = $this->access->username2dn($id); |
| 234 | - if($dn !== false) { |
|
| 234 | + if ($dn !== false) { |
|
| 235 | 235 | return $this->createAndCache($dn, $id); |
| 236 | 236 | } |
| 237 | 237 | return null; |
@@ -245,15 +245,15 @@ discard block |
||
| 245 | 245 | */ |
| 246 | 246 | public function get($id) { |
| 247 | 247 | $this->checkAccess(); |
| 248 | - if(isset($this->usersByDN[$id])) { |
|
| 248 | + if (isset($this->usersByDN[$id])) { |
|
| 249 | 249 | return $this->usersByDN[$id]; |
| 250 | - } else if(isset($this->usersByUid[$id])) { |
|
| 250 | + } else if (isset($this->usersByUid[$id])) { |
|
| 251 | 251 | return $this->usersByUid[$id]; |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - if($this->access->stringResemblesDN($id) ) { |
|
| 254 | + if ($this->access->stringResemblesDN($id)) { |
|
| 255 | 255 | $uid = $this->access->dn2username($id); |
| 256 | - if($uid !== false) { |
|
| 256 | + if ($uid !== false) { |
|
| 257 | 257 | return $this->createAndCache($id, $uid); |
| 258 | 258 | } |
| 259 | 259 | } |