/** * Returns the LDAP user groups with information merged with local TYPO3 user groups. * * @param \Causal\IgLdapSsoAuth\Domain\Model\Configuration $configuration * @param string $mode * @return array */ protected function getAvailableUserGroups(\Causal\IgLdapSsoAuth\Domain\Model\Configuration $configuration, $mode) { $userGroups = array(); $config = $mode === 'be' ? Configuration::getBackendConfiguration() : Configuration::getFrontendConfiguration(); $ldapGroups = array(); if (!empty($config['groups']['basedn'])) { $filter = Configuration::replaceFilterMarkers($config['groups']['filter']); $attributes = Configuration::getLdapAttributes($config['groups']['mapping']); $ldapGroups = Ldap::getInstance()->search($config['groups']['basedn'], $filter, $attributes); unset($ldapGroups['count']); } // Populate an array of TYPO3 group records corresponding to the LDAP groups // If a given LDAP group has no associated group in TYPO3, a fresh record // will be created so that $ldapGroups[i] <=> $typo3Groups[i] $typo3GroupPid = Configuration::getPid($config['groups']['mapping']); $table = $mode === 'be' ? 'be_groups' : 'fe_groups'; $typo3Groups = Authentication::getTypo3Groups($ldapGroups, $table, $typo3GroupPid); foreach ($ldapGroups as $index => $ldapGroup) { $userGroup = Authentication::merge($ldapGroup, $typo3Groups[$index], $config['groups']['mapping']); // Attempt to free memory by unsetting fields which are unused in the view $keepKeys = array('uid', 'pid', 'deleted', 'title', 'tx_igldapssoauth_dn'); $keys = array_keys($userGroup); foreach ($keys as $key) { if (!in_array($key, $keepKeys)) { unset($userGroup[$key]); } } $userGroups[] = $userGroup; } return $userGroups; }