/** * Get the user from user provided for the given instance of Login object. * * @param Login $login Instance of Login object. * * @return AbstractUser * @throws UserNotFoundException */ public function getUser(Login $login) { $user = new User(); $user->setParams($this->params); $user->populate($login->getUsername(), $login->getPassword(), []); return $user; }
/** * Get the user from user provided for the given instance of Login object. * * @param Login $login Instance of Login object. * * @return UserAbstract * @throws UserNotFoundException */ public function getUser(Login $login) { if (self::$returnLoginObject) { $user = new UserMock(); $user->populate($login->getUsername(), $login->getPassword(), ['ROLE_MOCK'], false); return $user; } return false; }
/** * Get the user from user provided for the given instance of Login object. * NOTE: The method gets the users based on his username only, password is not verified, this is part of * the authentication process. * * @param Login $login Instance of Login object. * * @return UserAbstract * @throws UserNotFoundException */ public function getUser(Login $login) { $username = $login->getUsername(); if (!isset($this->users[$username]) || !$this->isArray($this->users[$username])) { throw new UserNotFoundException('User "' . $username . '" was not found.'); } $userData = $this->users[$username]; $user = new User(); $user->populate($username, $userData['password'], $userData['roles'], false); return $user; }
/** * This method verifies the credentials of current user with the credentials provided from the Login object. * * @param Login $login * @param Firewall $firewall * * @return bool Return true if credentials are valid, otherwise return false. */ public function authenticate(Login $login, Firewall $firewall) { $user = call_user_func_array([$this->entity, 'findOne'], [[$this->username => $login->getUsername()]]); if ($user) { if ($firewall->verifyPasswordHash($login->getPassword(), $user[$this->password])) { if (isset($user[$this->role])) { $role = $user[$this->role]; } else { $role = $this->role; } $role = new Role($role); $this->setRoles([$role]); return true; } } return false; }
/** * This method verifies the credentials of current user with the credentials provided from the Login object. * * @param Login $login * @param Firewall $firewall * * @return bool Return true if credentials are valid, otherwise return false. */ public function authenticate(Login $login, Firewall $firewall) { $entityInstance = new $this->entity(); $user = $entityInstance->find([$this->username => $login->getUsername()]); if ($user && isset($user[0])) { $user = $user[0]; if ($firewall->verifyPasswordHash($login->getPassword(), $user[$this->password])) { if (isset($user[$this->role])) { $role = $user[$this->role]; } else { $role = $this->role; } $role = new Role($role); $this->setRoles([$role]); return true; } } return false; }
public function testGetUsername() { $login = new Login('username', 'password', true); $this->assertSame('username', $login->getUsername()); }