public function testGetMessageData()
 {
     $exception = new UsernameNotFoundException('Username could not be found.');
     $this->assertEquals(array('{{ username }}' => null), $exception->getMessageData());
     $exception->setUsername('username');
     $this->assertEquals(array('{{ username }}' => 'username'), $exception->getMessageData());
 }
 /**
  * @param string $username
  */
 private function hideUserNotFoundExceptions(UsernameNotFoundException $notFound, $username)
 {
     if ($this->hideUserNotFoundExceptions) {
         throw new BadCredentialsException('Bad credentials.', 0, $notFound);
     }
     $notFound->setUsername($username);
     throw $notFound;
 }
 /**
  * Loads the user for the given username.
  *
  * This method must throw UsernameNotFoundException if the user is not
  * found.
  *
  * @param string $username The username
  *
  * @return UserInterface
  *
  * @see UsernameNotFoundException
  *
  * @throws UsernameNotFoundException if the user is not found
  */
 public function loadUserByUsername($username)
 {
     if (!isset($this->users[$username])) {
         $exception = new UsernameNotFoundException(sprintf('User "%s" does not exist', $username));
         $exception->setUsername($username);
         throw $exception;
     }
     return $this->users[$username];
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function loadUserByUsername($username)
 {
     if (!isset($this->users[strtolower($username)])) {
         $ex = new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
         $ex->setUsername($username);
         throw $ex;
     }
     $user = $this->users[strtolower($username)];
     return new User($user->getUsername(), $user->getPassword(), $user->getRoles(), $user->isEnabled(), $user->isAccountNonExpired(), $user->isCredentialsNonExpired(), $user->isAccountNonLocked());
 }
Example #5
0
 public function loadUserByUsername($username)
 {
     if (isset($this->users[$username])) {
         $user = ['username' => $username, 'roles' => null, 'email' => null, 'password' => null, 'salt' => null, 'person_name' => null, 'person_guid' => null];
         return array_merge($user, $this->users[$username]);
     }
     $ex = new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
     $ex->setUsername($username);
     throw $ex;
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function loadUserByUsername($username)
 {
     $user = $this->em->getRepository('SecurityBundle:ApiUser')->findOneBy(array('username' => $username));
     if (is_null($user)) {
         $exception = new UsernameNotFoundException();
         $exception->setUsername($username);
         throw $exception;
     }
     return $user;
 }
 /**
  * Load User by username
  * @param string $username
  * @return UserInterface
  * @throws UsernameNotFoundException
  */
 public function loadUserByUsername($username)
 {
     $user = $this->em->getRepository($this->userClass)->findOneBy(array_merge($this->additionalCriteria, array($this->usernameColumn => $username)));
     if (!$user) {
         $ex = new UsernameNotFoundException(sprintf(self::NOT_FOUND, $username));
         $ex->setUsername($username);
         throw $ex;
     }
     return $user;
 }
Example #8
0
 /**
  * {{@inheritdoc}}
  */
 public function loadUserByUsername($username)
 {
     /** @var \Model\User $user */
     $user = $this->entityManager->getRepository('Model\\User')->findOneBy(array('username' => $username));
     if (is_null($user)) {
         $exception = new UsernameNotFoundException();
         $exception->setUsername($username);
         throw $exception;
     }
     return $user;
 }
 /**
  * {@inheritDoc}
  */
 public function loadUserByUsername($username)
 {
     $user = $this->ldapManager->findUserByUsername($username);
     if (empty($user)) {
         $this->logInfo("User {$username} not found on ldap");
         $ex = new UsernameNotFoundException(sprintf('User "%s" not found', $username));
         $ex->setUsername($username);
         throw $ex;
     } else {
         $this->logInfo("User {$username} found on ldap");
     }
     return $user;
 }
Example #10
0
 /**
  * Used for Authentification Security
  *
  * {@inheritdoc} @see UserProviderInterface::loadUserByUsername()
  * @param string $username
  *
  * @throws UsernameNotFoundException
  *
  * @return Ambigous <\Doctrine\ORM\mixed, mixed, \Doctrine\ORM\Internal\Hydration\mixed,
  *         \Doctrine\DBAL\Driver\Statement, \Doctrine\Common\Cache\mixed>
  */
 public function loadUserByUsername($username)
 {
     $qb = $this->createQueryBuilder('u')->where('u.username = :username')->andWhere('u.lockout = :lockout')->setParameter('username', $username)->setParameter('lockout', User::LOCKOUT_UNLOCKED);
     $query = $qb->getQuery();
     try {
         $user = $query->getSingleResult();
     } catch (NoResultException $e) {
         $exp = new UsernameNotFoundException(sprintf('Unable to find an active User identified by "%s".', $username), 0, $e);
         $exp->setUsername($username);
         throw $exp;
     }
     return $user;
 }
Example #11
0
 /**
  * This function is called when user logs into cas. checks if user exists, if not then creates one (non-PHPdoc)
  *
  * @param String $username
  *
  * @see \Symfony\Component\Security\Core\User\UserProviderInterface::loadUserByUsername()
  *
  * @return mixed|UserInterface
  */
 public function loadUserByUsername($username)
 {
     $q = $this->createQueryBuilder('u')->where('u.username = :username')->setParameter('username', $username)->getQuery();
     //->useResultCache(true, 3600);
     try {
         // The Query::getSingleResult() method throws an exception
         // if there is no record matching the criteria.
         $user = $q->getSingleResult();
     } catch (NoResultException $e) {
         $ex = new UsernameNotFoundException();
         $ex->setUsername($username);
         throw $ex;
     }
     return $user;
 }
 /**
  * {@inheritDoc}
  */
 public function refreshUser(UserInterface $user)
 {
     $supportedUserFound = false;
     foreach ($this->providers as $provider) {
         try {
             return $provider->refreshUser($user);
         } catch (UnsupportedUserException $unsupported) {
             // try next one
         } catch (UsernameNotFoundException $notFound) {
             $supportedUserFound = true;
             // try next one
         }
     }
     if ($supportedUserFound) {
         $ex = new UsernameNotFoundException(sprintf('There is no user with name "%s".', $user->getUsername()));
         $ex->setUsername($user->getUsername());
         throw $ex;
     } else {
         throw new UnsupportedUserException(sprintf('The account "%s" is not supported.', get_class($user)));
     }
 }
Example #13
0
    public function loadUserByUsername($username)
    {
        $sql = <<<EOT
SELECT 
  id,username,email,salt,password,roles, 
  person_guid, account_name as person_name
FROM users
WHERE username = ? OR email = ?;
EOT;
        $stmt = $this->db->executeQuery($sql, [$username, $username]);
        $rows = $stmt->fetchAll();
        if (count($rows) != 1) {
            $ex = new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
            $ex->setUsername($username);
            throw $ex;
        }
        $user = $rows[0];
        $user['roles'] = unserialize($user['roles']);
        if (count($user['roles']) < 1) {
            $user['roles'] = ['ROLE_USER'];
        }
        return $user;
    }
 /**
  * Returns the user by given username.
  *
  * @param string $username The username.
  *
  * @return User
  *
  * @throws UsernameNotFoundException If user whose given username does not exist.
  */
 private function getUser($username)
 {
     if (!isset($this->users[strtolower($username)])) {
         $ex = new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
         $ex->setUsername($username);
         throw $ex;
     }
     return $this->users[strtolower($username)];
 }
 public function unserialize($str)
 {
     list($this->accessToken, $this->resourceOwnerName, $parentData) = unserialize($str);
     parent::unserialize($parentData);
 }
 /**
  * @param $username
  */
 protected function raiseUserNotFoundException($username)
 {
     $ex = new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
     $ex->setUsername($username);
     throw $ex;
 }