Exemplo n.º 1
0
 /**
  * Method to initialise all the properties based on the parameters
  * specified in the plugin.
  *
  * @return  boolean  True on valid entries in the mapping list.
  *
  * @since   2.0
  */
 protected function doSetup()
 {
     static $done = null;
     if (is_null($done)) {
         // Assign class properties based on parameters from the plugin
         $this->sync_groups = (bool) $this->params->get('sync_groups', false);
         $this->addition = (bool) $this->params->get('addition', true);
         $this->removal = (int) $this->params->get('removal', self::YESDEFAULT);
         $this->unmanaged = array_map('intval', explode(';', $this->params->get('unmanaged')));
         $this->public_id = (int) $this->params->get('public_id');
         $this->dn_validate = $this->params->get('dn_validate', 1);
         $this->lookup_type = (int) $this->params->get('lookup_type', self::LOOKUP_FORWARD);
         $this->memberof_attribute = $this->params->get('memberof_attribute');
         $this->member_attribute = $this->params->get('member_attribute', 'member');
         $this->member_dn = $this->params->get('member_dn', 'dn');
         $this->recursion = (bool) $this->params->get('recursion', false);
         $this->dn_attribute = $this->params->get('dn_attribute', 'distinguishedName');
         $this->recursion_depth = (int) $this->params->get('recursion_depth', 0);
         $this->entries = array();
         $this->list = array();
         $list = preg_split('/\\r\\n|\\n|\\r/', $this->params->get('list'));
         // Loops around each mapping entry parameter
         foreach ($list as $item) {
             // Remove any accidental whitespace from the entry
             $item = trim($item);
             // Find the right most (outside of the distinguished name) to split groups
             if ($pos = strrpos($item, ':')) {
                 // Store distinguished name in a string and Joomla groups in an array
                 $entryDn = trim(substr($item, 0, $pos));
                 if ($entryGroups = array_map('intval', explode(',', substr($item, $pos + 1)))) {
                     // Store as a parameter for validation later
                     $this->list[$entryDn] = $entryGroups;
                 }
             }
         }
         // Get all the Joomla user groups
         $JUserGroups = SHUserHelper::getJUserGroups();
         $JUserGroupsKey = array_fill_keys($JUserGroups, '');
         /*
          * Process the map list parameter into validated entries.
          * Then ensure that there is atleast 1 valid entry to
          * proceed with the mapping process.
          */
         foreach ($this->list as $dn => $groups) {
             foreach ($groups as $key => $group) {
                 if (!isset($JUserGroupsKey[$group])) {
                     // This isn't a valid Joomla group
                     unset($this->list[$dn][$key]);
                     continue;
                 }
             }
             if (empty($this->list[$dn])) {
                 // This DN doesn't have any valid Joomla groups
                 unset($this->list[$dn]);
                 continue;
             }
             /*
              * Add the entry to a new mapping entry object then check if it is
              * valid. If so then we can assume this entry has no syntax errors.
              */
             $entry = new SHLdapMappingEntry($dn, $this->list[$dn], $this->dn_validate);
             if ($entry->isValid()) {
                 // Add as a valid entry
                 $this->entries[] = $entry;
                 // Add as a managed group
                 if ($this->removal === self::YES) {
                     /*
                      * Yes means we want to add only groups that are defined in the mapping list.
                      * Looping around dn group parameter list, ensuring its not already there and not in unmanaged.
                      */
                     $this->managed = array_merge($this->managed, array_diff(array_diff($this->list[$dn], $this->unmanaged), $this->managed));
                 }
             }
         }
         if ($this->removal === self::YESDEFAULT) {
             // Yesdefault means we want to add all Joomla groups to the managed pool
             $this->managed = array_diff($JUserGroups, $this->unmanaged);
         }
         $done = true;
         if (!count($this->entries)) {
             // No valid entries here
             SHLog::add(JText::_('PLG_LDAP_MAPPING_DEBUG_12006'), 12006, JLog::DEBUG, 'ldap');
             $done = false;
         }
     }
     return $done;
 }