Example #1
0
 /**
  * Returns a LDAP user.
  *
  * @param string $dn
  * @return array
  */
 protected static function getLdapUser($dn = NULL)
 {
     // Restricting the list of returned attributes sometimes makes the ldap_search() method issue a PHP warning:
     //     Warning: ldap_search(): Array initialization wrong
     // so we just ask for every attribute ("TRUE" below)!
     if (TRUE || Configuration::hasExtendedMapping(static::$config['users']['mapping'])) {
         $attributes = array();
     } else {
         // Currently never called ever again due to the warning found sometimes (see above)
         $attributes = Configuration::getLdapAttributes(static::$config['users']['mapping']);
         if (strpos(static::$config['groups']['filter'], '{USERUID}') !== FALSE) {
             $attributes[] = 'uid';
             $attributes = array_unique($attributes);
         }
     }
     $users = Ldap::getInstance()->search($dn, str_replace('{USERNAME}', '*', static::$config['users']['filter']), $attributes);
     $user = is_array($users[0]) ? $users[0] : NULL;
     static::getLogger()->debug(sprintf('Retrieving LDAP user from DN "%s"', $dn), $user);
     return $user;
 }
Example #2
0
    /**
     * @test
     */
    public function mappingWithTypoScriptIsExtended()
    {
        $mapping = <<<EOT
\t\t\tname = <sn>, <givenName>
\t\t\tname.wrap = |
EOT;
        $mapping = Configuration::parseMapping($mapping);
        $result = Configuration::hasExtendedMapping($mapping);
        $this->assertTrue($result);
    }
Example #3
0
 /**
  * Fetches all possible LDAP/AD users for a given configuration and context.
  *
  * @param bool $partial TRUE to fetch remaining entries when a partial result set was returned
  * @return array
  */
 public function fetchLdapUsers($partial = FALSE)
 {
     // Get the users from LDAP/AD server
     $ldapUsers = array();
     if (!empty($this->configuration['users']['basedn'])) {
         if (!$partial) {
             $filter = Configuration::replaceFilterMarkers($this->configuration['users']['filter']);
             if (Configuration::hasExtendedMapping($this->configuration['users']['mapping'])) {
                 // Fetch all attributes so that hooks may do whatever they want on any LDAP attribute
                 $attributes = array();
             } else {
                 // Optimize the LDAP call by retrieving only attributes in use for the mapping
                 $attributes = Configuration::getLdapAttributes($this->configuration['users']['mapping']);
             }
             $ldapUsers = Ldap::getInstance()->search($this->configuration['users']['basedn'], $filter, $attributes);
         } else {
             $ldapUsers = Ldap::getInstance()->searchNext();
         }
         unset($ldapUsers['count']);
     }
     return $ldapUsers;
 }