/** * @param string $configPrefix */ private function addAccess($configPrefix) { static $ocConfig; static $fs; static $log; static $avatarM; static $userMap; static $groupMap; static $db; static $coreUserManager; if (is_null($fs)) { $ocConfig = \OC::$server->getConfig(); $fs = new FilesystemHelper(); $log = new LogWrapper(); $avatarM = \OC::$server->getAvatarManager(); $db = \OC::$server->getDatabaseConnection(); $userMap = new UserMapping($db); $groupMap = new GroupMapping($db); $coreUserManager = \OC::$server->getUserManager(); } $userManager = new Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image(), $db, $coreUserManager); $connector = new Connection($this->ldap, $configPrefix); $access = new Access($connector, $this->ldap, $userManager); $access->setUserMapper($userMap); $access->setGroupMapper($groupMap); self::$accesses[$configPrefix] = $access; }
/** * Prepares the Access mock for getUsers tests * @param \OCA\User_LDAP\Access $access mock * @return void */ private function prepareAccessForGetUsers(&$access) { $access->expects($this->once())->method('escapeFilterPart')->will($this->returnCallback(function ($search) { return $search; })); $access->expects($this->any())->method('getFilterPartForUserSearch')->will($this->returnCallback(function ($search) { return $search; })); $access->expects($this->any())->method('combineFilterWithAnd')->will($this->returnCallback(function ($param) { return $param[2]; })); $access->expects($this->any())->method('fetchListOfUsers')->will($this->returnCallback(function ($search, $a, $l, $o) { $users = array('gunslinger', 'newyorker', 'ladyofshadows'); if (empty($search)) { $result = $users; } else { $result = array(); foreach ($users as $user) { if (stripos($user, $search) !== false) { $result[] = $user; } } } if (!is_null($l) || !is_null($o)) { $result = array_slice($result, $o, $l); } return $result; })); $access->expects($this->any())->method('ownCloudUserNames')->will($this->returnArgument(0)); }
/** * @return \OCA\User_LDAP\Group_LDAP|\OCA\User_LDAP\Group_Proxy */ private static function getGroupBE() { if (!is_null(self::$groupBE)) { return self::$groupBE; } $helper = new Helper(); $configPrefixes = $helper->getServerConfigurationPrefixes(true); $ldapWrapper = new LDAP(); if (count($configPrefixes) === 1) { //avoid the proxy when there is only one LDAP server configured $dbc = \OC::$server->getDatabaseConnection(); $userManager = new Manager(\OC::$server->getConfig(), new FilesystemHelper(), new LogWrapper(), \OC::$server->getAvatarManager(), new \OCP\Image(), $dbc, \OC::$server->getUserManager()); $connector = new Connection($ldapWrapper, $configPrefixes[0]); $ldapAccess = new Access($connector, $ldapWrapper, $userManager, $helper); $groupMapper = new GroupMapping($dbc); $userMapper = new UserMapping($dbc); $ldapAccess->setGroupMapper($groupMapper); $ldapAccess->setUserMapper($userMapper); self::$groupBE = new \OCA\User_LDAP\Group_LDAP($ldapAccess); } else { self::$groupBE = new \OCA\User_LDAP\Group_Proxy($configPrefixes, $ldapWrapper); } return self::$groupBE; }