/** * Returns TYPO3 groups associated to $ldapGroups or create * fresh records if they don't exist yet. * * @param array $ldapGroups * @param string $table * @param int|NULL $pid * @return array */ public static function getTypo3Groups(array $ldapGroups = array(), $table = NULL, $pid = NULL) { if (count($ldapGroups) === 0) { // Early return return array(); } $typo3Groups = array(); foreach ($ldapGroups as $ldapGroup) { $existingTypo3Groups = Typo3GroupRepository::fetch($table, 0, $pid, $ldapGroup['dn']); if (count($existingTypo3Groups) > 0) { $typo3Group = $existingTypo3Groups[0]; } else { $typo3Group = Typo3GroupRepository::create($table); $typo3Group['pid'] = (int) $pid; $typo3Group['crdate'] = $GLOBALS['EXEC_TIME']; $typo3Group['tstamp'] = $GLOBALS['EXEC_TIME']; } $typo3Groups[] = $typo3Group; } return $typo3Groups; }
/** * Actual search action using AJAX. * * @param \Causal\IgLdapSsoAuth\Domain\Model\Configuration $configuration * @param string $type * @param bool $firstEntry * @param bool $showStatus * @param string $baseDn * @param string $filter * @return void */ public function searchAjaxAction(\Causal\IgLdapSsoAuth\Domain\Model\Configuration $configuration = NULL, $type, $firstEntry, $showStatus, $baseDn, $filter) { list($mode, $key) = explode('_', $type, 2); Configuration::initialize($mode, $configuration); $config = $mode === 'be' ? Configuration::getBackendConfiguration() : Configuration::getFrontendConfiguration(); try { $success = $this->ldap->connect(Configuration::getLdapConfiguration()); } catch (\Exception $e) { $success = FALSE; } if ($showStatus) { $this->view->assign('status', $this->ldap->getStatus()); } if ($success) { $filter = Configuration::replaceFilterMarkers($filter); if ($firstEntry) { $attributes = array(); } else { $attributes = Configuration::getLdapAttributes($config[$key]['mapping']); if (strpos($config[$key]['filter'], '{USERUID}') !== FALSE) { $attributes[] = 'uid'; $attributes = array_unique($attributes); } } $resultset = $this->ldap->search($baseDn, $filter, $attributes, $firstEntry, 100); // With PHP 5.4 and above this could be renamed as // ksort_recursive($result, SORT_NATURAL) if (is_array($resultset)) { $this->uksort_recursive($resultset, 'strnatcmp'); } $this->view->assign('resultset', $resultset); if ($firstEntry && is_array($resultset) && count($resultset) > 1) { if ($key === 'users') { $mapping = $config['users']['mapping']; $blankTypo3Record = Typo3UserRepository::create($type); } else { $mapping = $config['groups']['mapping']; $blankTypo3Record = Typo3GroupRepository::create($type); } $preview = Authentication::merge($resultset, $blankTypo3Record, $mapping, TRUE); // Remove empty lines $keys = array_keys($preview); foreach ($keys as $key) { if (empty($preview[$key])) { unset($preview[$key]); } } $this->view->assign('preview', $preview); } } $this->returnAjax(array('success' => $success, 'html' => $this->view->render())); }