示例#1
0
 /**
  * Log a user in using the given adapter from the construct
  * @throws InvalidCredentialsException
  * @throws UnrecognisedAuthenticationResultException
  * @return boolean|throws
  */
 public function login()
 {
     $result = $this->adapter->getResult();
     if ($result === self::PHAVOUR_AUTH_SERVICE_SUCCESS) {
         $auth = Auth::getInstance();
         $auth->login($this->adapter->getIdentity());
         $auth->setRoles($this->adapter->getRoles());
         return true;
     } elseif ($result === self::PHAVOUR_AUTH_SERVICE_INVALID) {
         throw new InvalidCredentialsException('Invalid credentials exception');
     }
     throw new UnrecognisedAuthenticationResultException('Expected 1 or 2');
 }
示例#2
0
 public function testServiceValidCredentials()
 {
     $this->initLoggedOutSession();
     $adapter = new TestCaseAdapter();
     $adapter->setCredentials('*****@*****.**', 'password');
     $service = new Service($adapter);
     $result = $service->login();
     $this->assertTrue($result);
     $auth = Auth::getInstance();
     $identity = $auth->getIdentity();
     $roles = $auth->getRoles();
     $this->assertCount(2, $identity);
     $this->assertCount(2, $roles);
     $this->assertContains('admin', $roles);
 }
示例#3
0
 /**
  * Check if a route is allowed to access based on the ['allow']['roles'] key
  * @param array $route
  * @return array|boolean false
  */
 private function isAllowedByRole(array $route)
 {
     if (empty($route['allow']['roles'])) {
         return true;
     }
     // @codeCoverageIgnoreStart
     // @TODO This works but not in a unit test.
     if (null === $this->auth) {
         $this->auth = Auth::getInstance();
     }
     $roles = $route['allow']['roles'];
     $pieces = explode('|', $roles);
     foreach ($pieces as $piece) {
         if ($this->auth->hasRole($piece)) {
             return true;
         }
     }
     return false;
     // @codeCoverageIgnoreEnd
 }
示例#4
0
 public function testGetNoStorage()
 {
     $this->initLoggedInSession();
     $auth = Auth::getInstance();
     $auth->destroy();
     $this->assertFalse($auth->getStorage());
 }