Esempio n. 1
0
 /**
  * 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;
 }
Esempio n. 2
0
 /**
  * Sets the parent groups for a given TYPO3 user group record.
  *
  * @param array $ldapParentGroups
  * @param string $fieldParent
  * @param int $childUid
  * @param int $pid
  * @param string $mode
  * @return void
  * @throws \Causal\IgLdapSsoAuth\Exception\InvalidUserGroupTableException
  */
 protected function setParentGroup(array $ldapParentGroups, $fieldParent, $childUid, $pid, $mode)
 {
     $subGroupList = array();
     if ($mode === 'be') {
         $table = 'be_groups';
         $config = Configuration::getBackendConfiguration();
     } else {
         $table = 'fe_groups';
         $config = Configuration::getFrontendConfiguration();
     }
     foreach ($ldapParentGroups as $parentDn) {
         $typo3ParentGroup = Typo3GroupRepository::fetch($table, FALSE, $pid, $parentDn);
         if (is_array($typo3ParentGroup[0])) {
             if (!empty($typo3ParentGroup[0]['subgroup'])) {
                 $subGroupList = GeneralUtility::trimExplode(',', $typo3ParentGroup[0]['subgroup']);
             }
             $subGroupList[] = $childUid;
             $subGroupList = array_unique($subGroupList);
             $typo3ParentGroup[0]['subgroup'] = implode(',', $subGroupList);
             Typo3GroupRepository::update($table, $typo3ParentGroup[0]);
         } else {
             $filter = '(&' . Configuration::replaceFilterMarkers($config['groups']['filter']) . '&(distinguishedName=' . $parentDn . '))';
             $attributes = Configuration::getLdapAttributes($config['groups']['mapping']);
             $ldapGroups = Ldap::getInstance()->search($config['groups']['basedn'], $filter, $attributes);
             unset($ldapGroups['count']);
             if (count($ldapGroups) > 0) {
                 $pid = Configuration::getPid($config['groups']['mapping']);
                 // 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]
                 $typo3Groups = Authentication::getTypo3Groups($ldapGroups, $table, $pid);
                 foreach ($ldapGroups as $index => $ldapGroup) {
                     $typo3Group = Authentication::merge($ldapGroup, $typo3Groups[$index], $config['groups']['mapping']);
                     $typo3Group['subgroup'] = $childUid;
                     $typo3Group = Typo3GroupRepository::add($table, $typo3Group);
                     if (is_array($ldapGroup[$fieldParent])) {
                         unset($ldapGroup[$fieldParent]['count']);
                         $this->setParentGroup($ldapGroup[$fieldParent], $fieldParent, $typo3Group['uid'], $pid, $mode);
                     }
                 }
             }
         }
     }
 }