/** * 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->service) { throw new Exception\RuntimeException('AuthenticationService must be set prior to validation'); } $this->service->setIdentity($identity); $this->service->setCredential($credential); $result = $this->service->authenticate(); 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; }