/**
  * This method attempts to validate that the record in the resultset is indeed a
  * record that matched the identity provided to this adapter.
  *
  * @param  object                              $identity
  * @throws Exception\UnexpectedValueException
  * @return AuthenticationResult
  */
 protected function validateIdentity($identity)
 {
     $credentialProperty = $this->options->getCredentialProperty();
     $getter = 'get' . ucfirst($credentialProperty);
     $documentCredential = null;
     if (method_exists($identity, $getter)) {
         $documentCredential = $identity->{$getter}();
     } elseif (property_exists($identity, $credentialProperty)) {
         $documentCredential = $identity->{$credentialProperty};
     } else {
         throw new Exception\UnexpectedValueException(sprintf('Property (%s) in (%s) is not accessible. You should implement %s::%s()', $credentialProperty, get_class($identity), get_class($identity), $getter));
     }
     $credentialValue = $this->credential;
     $callable = $this->options->getCredentialCallable();
     if ($callable) {
         $credentialValue = call_user_func($callable, $identity, $credentialValue);
     }
     if ($credentialValue !== true && $credentialValue !== $documentCredential) {
         $this->authenticationResultInfo['code'] = AuthenticationResult::FAILURE_CREDENTIAL_INVALID;
         $this->authenticationResultInfo['messages'][] = 'Supplied credential is invalid.';
         return $this->createAuthenticationResult();
     }
     $this->authenticationResultInfo['code'] = AuthenticationResult::SUCCESS;
     $this->authenticationResultInfo['identity'] = $identity;
     $this->authenticationResultInfo['messages'][] = 'Authentication successful.';
     return $this->createAuthenticationResult();
 }
 /**
  * @return void
  */
 public function clear()
 {
     $this->options->getStorage()->clear();
 }