Example #1
0
 /**
  * Resolve user by identity
  *
  * @param  string      $identity
  * @param  string|null $realm
  * @param  string|null $password
  * @return \Zend\Authentication\Result
  */
 public function resolve($identity, $realm = null, $password = null)
 {
     foreach ($this->providers as $provider) {
         $result = $provider->resolve($identity, $realm, $password);
         if ($result->isValid()) {
             return $result;
         }
     }
     return Result::failureIdentityNotFound();
 }
Example #2
0
 /**
  * Resolve user by identity
  *
  * @param  string      $identity
  * @param  string|null $realm
  * @param  string|null $password
  * @return \Zend\Authentication\Result
  */
 public function resolve($identity, $realm = null, $password = null)
 {
     $qb = $this->connection->createQueryBuilder();
     $qb->select(['*'])->from($this->options['table_name'])->where($this->options['identity_column'] . ' = ' . $qb->createPositionalParameter($identity));
     $resultIdentities = $qb->execute()->fetchAll();
     if (count($resultIdentities) < 1) {
         return Result::failureIdentityNotFound();
     } else {
         if (false === $this->options['use_ambiguity_identity'] && count($resultIdentities) > 1) {
             return Result::failureIdentityAmbiguous();
         }
     }
     $users = [];
     foreach ($resultIdentities as $identity) {
         $users[] = new User($identity[$this->options['identity_column']], $identity[$this->options['credential_column']], isset($this->options['roles_column']) ? $identity[$this->options['roles_column']] : [], isset($this->options['salt_column']) ? $identity[$this->options['salt_column']] : null);
     }
     return Result::success($users);
 }
Example #3
0
 /**
  * Resolve user by identity
  *
  * @param  string      $identity
  * @param  string|null $realm
  * @param  string|null $password
  * @return \Zend\Authentication\Result
  * @throws \RuntimeException if cannot read passwords file
  */
 public function resolve($identity, $realm = null, $password = null)
 {
     set_error_handler([$this, 'handleError'], E_WARNING);
     $fp = fopen($this->file, 'r');
     restore_error_handler();
     if (!$fp) {
         throw new \RuntimeException('Unable to open password file: ' . $this->file . ' reason ' . $this->error->getMessage());
     }
     $matchedHash = null;
     while (($line = fgetcsv($fp, 512, ':')) !== false) {
         if ($line[0] !== $identity) {
             continue;
         }
         if (isset($line[2])) {
             if ($line[1] === $realm) {
                 $matchedHash = $line[2];
                 break;
             }
             continue;
         }
         $matchedHash = $line[1];
         break;
     }
     fclose($fp);
     if (empty($matchedHash)) {
         return Result::failureIdentityNotFound();
     }
     return Result::success([new User($identity, $matchedHash, $this->roles)]);
 }
Example #4
0
 /**
  * Resolve user by identity
  *
  * @param  string      $identity
  * @param  string|null $realm
  * @param  string|null $password
  * @return \Zend\Authentication\Result
  */
 public function resolve($identity, $realm = null, $password = null)
 {
     if (array_key_exists($identity = strtolower($identity), $this->users)) {
         return Result::success($this->users[$identity]);
     }
     return Result::failureIdentityNotFound();
 }