Example #1
0
 /**
  * Imports a given user to the TYPO3 database.
  *
  * @param array $user Local user information
  * @param array $ldapUser LDAP user information
  * @param string $restoreBehavior How to restore users (only for update)
  * @return array Modified user data
  * @throws ImportUsersException
  */
 public function import($user, $ldapUser, $restoreBehavior = 'both')
 {
     // Store the extra data for later restore and remove it
     if (isset($user['__extraData'])) {
         $extraData = $user['__extraData'];
         unset($user['__extraData']);
     }
     if (empty($user['uid'])) {
         // Set other necessary information for a new user
         // First make sure to be acting in the right context
         Configuration::setMode($this->context);
         $user['username'] = Typo3UserRepository::setUsername($user['username']);
         $user['password'] = Typo3UserRepository::setRandomPassword();
         $typo3Groups = Authentication::getUserGroups($ldapUser, $this->configuration, $this->groupTable);
         if ($typo3Groups === NULL) {
             // Required LDAP groups are missing: quit!
             return $user;
         }
         $user = Typo3UserRepository::setUserGroups($user, $typo3Groups);
         $user = Typo3UserRepository::add($this->userTable, $user);
         $this->usersAdded++;
     } else {
         // Restore user that may have been previously deleted or disabled, depending on chosen behavior
         // (default to both undelete and re-enable)
         switch ($restoreBehavior) {
             case 'enable':
                 $user[$GLOBALS['TCA'][$this->userTable]['ctrl']['enablecolumns']['disabled']] = 0;
                 break;
             case 'undelete':
                 $user[$GLOBALS['TCA'][$this->userTable]['ctrl']['delete']] = 0;
                 break;
             case 'nothing':
                 break;
             default:
                 $user[$GLOBALS['TCA'][$this->userTable]['ctrl']['enablecolumns']['disabled']] = 0;
                 $user[$GLOBALS['TCA'][$this->userTable]['ctrl']['delete']] = 0;
         }
         $typo3Groups = Authentication::getUserGroups($ldapUser, $this->configuration, $this->groupTable);
         $user = Typo3UserRepository::setUserGroups($user, $typo3Groups === NULL ? array() : $typo3Groups);
         $success = Typo3UserRepository::update($this->userTable, $user);
         if ($success) {
             $this->usersUpdated++;
         }
     }
     // Restore the extra data and trigger a signal
     if (isset($extraData)) {
         $user['__extraData'] = $extraData;
         // Hook for processing the extra data
         if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ig_ldap_sso_auth']['extraDataProcessing'])) {
             foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ig_ldap_sso_auth']['extraDataProcessing'] as $className) {
                 /** @var $postProcessor \Causal\IgLdapSsoAuth\Utility\ExtraDataProcessorInterface */
                 $postProcessor = GeneralUtility::getUserObj($className);
                 if ($postProcessor instanceof \Causal\IgLdapSsoAuth\Utility\ExtraDataProcessorInterface) {
                     $postProcessor->processExtraData($this->userTable, $user);
                 } else {
                     throw new ImportUsersException(sprintf('Invalid post-processing class %s. It must implement the \\Causal\\IgLdapSsoAuth\\Utility\\ExtraDataProcessorInterface interface', $className), 1414136057);
                 }
             }
         }
     }
     return $user;
 }