Автор: Fabien Potencier (fabien.potencier@symfony-project.com)
Пример #1
0
 /**
  * Adds a new User to the provider.
  *
  * @param AccountInterface $user A AccountInterface instance
  */
 public function createUser(AccountInterface $user)
 {
     if (isset($this->users[strtolower($user->getUsername())])) {
         throw new \LogicException('Another user with the same username already exist.');
     }
     $this->users[strtolower($user->getUsername())] = $user;
 }
 /**
  * {@inheritdoc}
  */
 protected function checkAuthentication(AccountInterface $account, UsernamePasswordToken $token)
 {
     if (!($presentedPassword = (string) $token->getCredentials())) {
         throw new BadCredentialsException('Bad credentials');
     }
     if (!$this->passwordEncoder->isPasswordValid($account->getPassword(), $presentedPassword, $account->getSalt())) {
         throw new BadCredentialsException('Bad credentials');
     }
 }
Пример #3
0
 /**
  * Constructor.
  *
  * @param string $username
  * @param string $key
  */
 public function __construct(AccountInterface $user, $key)
 {
     parent::__construct($user->getRoles());
     if (0 === strlen($key)) {
         throw new \InvalidArgumentException('$key cannot be empty.');
     }
     $this->user = $user;
     $this->key = $key;
     $this->setAuthenticated(true);
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function checkPostAuth(AccountInterface $account)
 {
     if (!$account instanceof AdvancedAccountInterface) {
         return;
     }
     if (!$account->isAccountNonLocked()) {
         throw new LockedException('User account is locked.', $account);
     }
     if (!$account->isEnabled()) {
         throw new DisabledException('User account is disabled.', $account);
     }
     if (!$account->isAccountNonExpired()) {
         throw new AccountExpiredException('User account has expired.', $account);
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function checkAuthentication(AccountInterface $account, UsernamePasswordToken $token)
 {
     $user = $token->getUser();
     if ($user instanceof AccountInterface) {
         if ($account->getPassword() !== $user->getPassword()) {
             throw new BadCredentialsException('The credentials were changed from another session.');
         }
     } else {
         if (!($presentedPassword = (string) $token->getCredentials())) {
             throw new BadCredentialsException('Bad credentials');
         }
         if (!$this->encoderFactory->getEncoder($account)->isPasswordValid($account->getPassword(), $presentedPassword, $account->getSalt())) {
             throw new BadCredentialsException('Bad credentials');
         }
     }
 }
Пример #6
0
    /**
     * Implementation of AccountInterface.
     *
     * @param AccountInterface $account
     * @return boolean
     */
    public function equals(AccountInterface $account)
    {
        if (!$account instanceof User) {
            return false;
        }

        if ($this->password !== $account->getPassword()) {
            return false;
        }
        if ($this->getSalt() !== $account->getSalt()) {
            return false;
        }
        if ($this->usernameCanonical !== $account->getUsernameCanonical()) {
            return false;
        }
        if ($this->isAccountNonExpired() !== $account->isAccountNonExpired()) {
            return false;
        }
        if (!$this->locked !== $account->isAccountNonLocked()) {
            return false;
        }
        if ($this->isCredentialsNonExpired() !== $account->isCredentialsNonExpired()) {
            return false;
        }
        if ($this->enabled !== $account->isEnabled()) {
            return false;
        }

        return true;
    }