_storage) { /** * @see Zend_Auth_Storage_Session */ $this->setStorage(new Zend_Auth_Storage_Session()); } return $this->_storage; } /** * Sets the persistent storage handler * * @param Zend_Auth_Storage_Interface $storage * @return Zend_Auth Provides a fluent interface */ public function setStorage(Zend_Auth_Storage_Interface $storage) { $this->_storage = $storage; return $this; } /** * Authenticates against the supplied adapter * * @param Zend_Auth_Adapter_Interface $adapter * @return Zend_Auth_Result */ public function authenticate(Zend_Auth_Adapter_Interface $adapter) { $result = $adapter->authenticate(); /** * ZF-7546 - prevent multiple succesive calls from storing inconsistent results * Ensure storage has clean state */ if ($this->hasIdentity()) { $this->clearIdentity(); } if ($result->isValid()) { $this->getStorage()->write($result->getIdentity()); } return $result; } /** * Returns true if and only if an identity is available from storage * * @return boolean */ public function hasIdentity() { return !$this->getStorage()->isEmpty(); } /** * Returns the identity from storage or null if no identity is available * * @return mixed|null */ public function getIdentity() { $storage = $this->getStorage(); if ($storage->isEmpty()) { return null; } return $storage->read(); } /** * Clears the identity from persistent storage * * @return void */ public function clearIdentity() { $this->getStorage()->clear(); } }