Пример #1
0
 /**
  * @param string $username
  * @param string $password
  *
  * @return UserModel|null
  */
 public function getUserInfo($username, $password = null)
 {
     $user = $this->_ldap->search()->where('samaccountname', '=', $username)->first();
     if (!$user) {
         return;
     }
     return $this->mapDataToUserModel($user, $password);
 }
 /**
  * Queries the LDAP/AD server for information on the user.
  *
  * @param  $userName    The name of the user to get information for.
  * @return Adldap User  The user information.
  */
 private function getLDAPUserInfo($username)
 {
     $adldap = false;
     $adResults = false;
     try {
         $ldapQuery = $this->ldapConfig['user_filter'];
         if (strpos($ldapQuery, self::USER_TOKEN)) {
             $ldapQuery = str_replace(self::USER_TOKEN, $username, $ldapQuery);
         } else {
             throw new \Exception("Invalid AD/LDAP query filter, check the configuration of 'LDAP_USER_FILTER'.");
         }
         $ldapFields = [$this->ldapConfig['first_name_field'], $this->ldapConfig['last_name_field'], $this->ldapConfig['email_field'], 'useraccountcontrol'];
         // Build connection info.
         $ldapConOp = $this->GetLDAPConnectionOptions();
         //            // Set LDAP debug log level - useful in DEV, dangerous in PROD!!
         //            ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
         // Connect to AD/LDAP
         $adldap = new Adldap($ldapConOp);
         $adResults = $adldap->search()->select($ldapFields)->query($ldapQuery);
         if (isset($adResults) && is_array($adResults) && isset($adResults[0])) {
             $adResults = $adResults[0];
         }
         if (!$adResults) {
             $this->handleLDAPError($adldap);
         }
     } catch (\Exception $ex) {
         Log::error('Exception retrieving user information: ' . $ex->getMessage());
         Log::error($ex->getTraceAsString());
     }
     // Close connection.
     if (isset($adldap)) {
         unset($adldap);
     }
     return $adResults;
 }