/** * * @return Result */ public function authenticate() { $result = $this->doAuthentication(); if (!$result->isValid() && !is_null($this->successor)) { $this->successor->setIdentity($this->getIdentity()); $this->successor->setCredential($this->getCredential()); return $this->successor->authenticate(); } return $result; }
/** * * @return Result */ public function authenticate() { $this->adapter->setIdentity($this->identity); $this->adapter->setCredential($this->credential); $result = $this->adapter->authenticate(); if ($this->hasIdentity()) { $this->clearIdentity(); } if ($result->isValid()) { $this->storage->write($result->getIdentity()); $this->triggerAuthenticationSuccessEvent($result); } else { $this->triggerAuthenticationFailureEvent($result); } return $result; }
/** * Is Valid * * @param mixed $value * @param array $context * @return bool */ public function isValid($value = null, $context = null) { if ($value !== null) { $this->setCredential($value); } if ($context !== null && array_key_exists($this->identity, $context)) { $identity = $context[$this->identity]; } else { $identity = $this->identity; } if (!$this->identity) { throw new Exception\RuntimeException('Identity must be set prior to validation'); } if ($context !== null && array_key_exists($this->credential, $context)) { $credential = $context[$this->credential]; } else { $credential = $this->credential; } if (!$this->adapter) { throw new Exception\RuntimeException('Adapter must be set prior to validation'); } $this->adapter->setIdentity($identity); $this->adapter->setCredential($credential); if (!$this->service) { throw new Exception\RuntimeException('AuthenticationService must be set prior to validation'); } $result = $this->service->authenticate($this->adapter); if ($result->getCode() != Result::SUCCESS) { switch ($result->getCode()) { case Result::FAILURE_IDENTITY_NOT_FOUND: $this->error(self::IDENTITY_NOT_FOUND); break; case Result::FAILURE_CREDENTIAL_INVALID: $this->error(self::CREDENTIAL_INVALID); break; case Result::FAILURE_IDENTITY_AMBIGUOUS: $this->error(self::IDENTITY_AMBIGUOUS); break; case Result::FAILURE_UNCATEGORIZED: $this->error(self::UNCATEGORIZED); break; default: $this->error(self::GENERAL); } return false; } return true; }