function testUserUpdateRealnameIfLdapDoesntMatch() { $user = new User4LDAPUserSync($this); $user->setReturnValue('getRealName', 'toto'); $user->setReturnValue('getEmail', 'toto'); $user->expectOnce('setRealName', array('foobar')); $user->expectNever('setEmail'); $lr = new LDAPResultTestVersion($this); $lr->setReturnValue('getCommonName', 'foobar'); $lr->setReturnValue('getEmail', 'toto'); $sync = new LDAP_UserSync(); $sync->sync($user, $lr); }
/** * Add (by name) new users into a user group. * * @param Array $userList List of user identifier (e.g. ldap login) * * @return void */ public function addListOfUsersToGroup($userList) { $ldapUserManager = new LDAP_UserManager($this->getLdap(), LDAP_UserSync::instance()); $userIds = $ldapUserManager->getUserIdsFromUserList($userList); foreach ($userIds as $userId) { $this->addUserToGroup($this->id, $userId); } }
/** * Instanciate the right LDAP_UserSync object * * Site can define its own implementation in /etc/codendi/plugins/ldap/site-content/en_US/synchronize_user.txt * * @return LDAP_UserSync */ public static function instance() { if (!isset(self::$instance)) { $syncClass = __CLASS__; // Allows site defined user update include_once $GLOBALS['Language']->getContent('synchronize_user', 'en_US', 'ldap'); self::$instance = new $syncClass(); } return self::$instance; }
/** * Return true if user is deleted from ldap server * * @param array $row * * @return Boolean * */ public function isUserDeletedFromLdap($row) { $ldap_query = $this->ldap->getLDAPParam('eduid') . '=' . $row['ldap_id']; $attributes = $this->user_sync->getSyncAttributes($this->ldap); $ldapSearch = false; foreach (split(';', $this->ldap->getLDAPParam('people_dn')) as $people_dn) { $ldapSearch = $this->ldap->search($people_dn, $ldap_query, LDAP::SCOPE_ONELEVEL, $attributes); if (count($ldapSearch) == 1 && $ldapSearch != false) { break; } } if ($this->ldap->getErrno() === LDAP::ERR_SUCCESS && $ldapSearch) { if (count($ldapSearch) == 0) { return true; } } return false; }
/** * Wrapper for LDAP_UserManager * * @return LDAP_UserManager */ protected function getLDAPUserManager() { if ($this->ldapUserManager === null) { $this->ldapUserManager = new LDAP_UserManager($this->ldap, LDAP_UserSync::instance()); } return $this->ldapUserManager; }
protected function getLdapUserSync() { return LDAP_UserSync::instance(); }
/** * Hook * * IN $params['codendiUserOnly'] * IN $params['limit'] * IN $params['searchToken'] * IN $params['validEmail'] * OUT $params['userList'] * OUT $params['pluginAnswered'] * * @param Array $params * * @return void */ function ajax_search_user($params) { if ($this->isLDAPUserManagementEnabled() && !$params['codendiUserOnly']) { $params['pluginAnswered'] = true; $validEmail = isset($params['validEmail']) ? $params['validEmail'] : false; $ldap = $this->getLdap(); $lri = $ldap->searchUserAsYouType($params['searchToken'], $params['limit'], $validEmail); $sync = LDAP_UserSync::instance(); foreach ($lri as $lr) { if ($lr->exist() && $lr->valid()) { $params['userList'][] = $sync->getCommonName($lr) . ' (' . $lr->getLogin() . ')'; } } if ($ldap->getErrno() == LDAP::ERR_SIZELIMIT) { $params['userList'][] = "<strong>...</strong>"; } } }
/** * Synchronize user account with LDAP informations * * @param User $user * @param LDAPResult $lr * @param String $password * @return Boolean */ function synchronizeUser(User $user, LDAPResult $lr, $password) { $user->setPassword($password); $sync = LDAP_UserSync::instance(); $sync->sync($user, $lr); // Perform DB update $userUpdated = $this->getUserManager()->updateDb($user); $ldapUpdated = true; $user_id = $this->getLdapLoginFromUserIds(array($user->getId()))->getRow(); if ($user_id['ldap_uid'] != $lr->getLogin()) { $ldapUpdated = $this->updateLdapUid($user, $lr->getLogin()); $this->triggerRenameOfUsers(); } return $userUpdated || $ldapUpdated; }
/** * Get the Codendi user id of the people in given LDAP group * * This method takes an LDAP group Distinguish Name * - Fetch all the members of the group * - Creates their Codendi account if it doesn't exist * - Return the Codendi id of people * * @param String $groupDn LDAP DN of the group. * * @return Array */ public function getLdapGroupMembersIds($groupDn) { $ldapUserManager = new LDAP_UserManager($this->getLdap(), LDAP_UserSync::instance()); $ldapGroupMembers = $this->getLdapGroupMembers($groupDn); $ldapGroupUserIds = $ldapUserManager->getUserIdsForLdapUser($ldapGroupMembers); return $ldapGroupUserIds; }