コード例 #1
0
 /**
  * Load thumbnail and save it's base64 in userdata
  * @param Manager $ldap
  * @param array $userData
  * @return string|false
  */
 public static function getThumbnail(Manager $ldap, array $userData)
 {
     $raw = $ldap->search(null, Utils::getUserLookup($userData['username']), true, array('thumbnailphoto'));
     if (!$raw->current() instanceof Node) {
         return false;
     }
     /** @var NodeAttribute[] $attrs */
     $attrs = $raw->current()->getAttributes();
     // Load user image
     if (empty($attrs['thumbnailPhoto']) !== true && $attrs['thumbnailPhoto']->getValues()) {
         $img = $attrs['thumbnailPhoto']->getValues();
         return 'data:image/jpg' . ';base64,' . base64_encode($img[0]);
     }
     return false;
 }
コード例 #2
0
 /**
  * Load data as per constructor instance
  *
  * @param Manager $ldap
  * @param array $userData
  * @return array
  */
 public function getUserInfo(Manager $ldap, array $userData)
 {
     // Load
     $raw = $ldap->search(NULL, Utils::getUserLookup($userData['username']), TRUE, array_keys($this->loadInfo));
     if (!$raw->current() instanceof Node) {
         return array();
     }
     $attributes = $raw->current()->getAttributes();
     // Post process & return
     $return = array();
     foreach ($attributes as $key => $value) {
         /** @var NodeAttribute $value */
         $newKey = $this->loadInfo[$key];
         if ($key == 'objectSid') {
             $return[$newKey] = array($this->getObjectSidFromBinary($value->getValues()[0]));
         } else {
             $return[$newKey] = $value->getValues();
         }
         if (count($return[$newKey]) === 1) {
             $return[$newKey] = reset($return[$newKey]);
         }
     }
     return $return;
 }
コード例 #3
0
 /**
  * Load memberOf for the current user - 1 LDAP query
  *
  * @param Manager $ldap
  * @param array $userData
  * @param array $allowedGroups
  * @return array (groupDn => groupName)
  */
 protected function getUserMemberOf(Manager $ldap, array $userData, array $allowedGroups)
 {
     $memberOf = array();
     $processed = array();
     $iterator = new \SplQueue();
     $iterator->setIteratorMode(\SplQueue::IT_MODE_DELETE);
     // Load membership
     $raw = $ldap->search(null, Utils::getUserLookup($userData['username']), true, array('memberof'));
     if (!$raw->current() instanceof Node) {
         return array();
     }
     $attrs = $raw->current()->getAttributes();
     if (!array_key_exists('memberOf', $attrs) || !$attrs['memberOf'] instanceof NodeAttribute) {
         return array();
     }
     // Post process all groups into memberOf array, put them into iterator for inheritance loading
     foreach ($attrs['memberOf'] as $groupDn) {
         $memberOf[$groupDn] = Utils::loadNameFromDn($groupDn);
         if (isset($processed[$groupDn])) {
             continue;
         }
         $iterator->enqueue($groupDn);
         $processed[$groupDn] = true;
     }
     // Loop iterator & load all inherits
     while (!$iterator->isEmpty()) {
         $groupDn = $iterator->dequeue();
         $inherits = $this->getGroupMemberOf($ldap, $groupDn);
         foreach ($inherits as $one) {
             /** @var Node $one */
             if (isset($processed[$one->getDn()])) {
                 continue;
             }
             $processed[$one->getDn()] = true;
             $iterator->enqueue($one->getDn());
             $memberOf[$one->getDn()] = Utils::loadNameFromDn($one->getDn());
         }
     }
     return $memberOf;
 }