ZF-11694: Zend_Auth::clearIdentity() does not work with objects


I use an instance of Zend_Auth_Storage_Session as Zend_Auth storage adapter, in this way:

$auth = Zend_Auth::getInstance(); $auth->setStorage(new Zend_Auth_Storage_Session());

When I do user login I save in that storage adapter the row fetched in the database, in this way:

$auth = Zend_Auth::getInstance(); $adapter = new System_AuthAdapter($id, $password); $result = $auth->authenticate($adapter); if ($result->isValid()) { $result = $adapter->getResultRowObject(); $auth->getStorage()->write($result); }

I do logout in this way:

$auth = Zend_Auth::getInstance(); $auth->clearIdentity();

but I am still logged in the system and the storage adapter still have information fetched in the database.


I attempted to write a unit test to reproduce your case. The only difference is that i'm not using the database authentication adapter:

     * @group ZF-11694
    public function testClearIdentityWorksWithObjects()
        // Authenticate the user and confirm
        $adapter = new ZF11694_TestAuthAdapter('test','foobar');
        $result = $this->auth->authenticate($adapter);
        $this->assertEquals('ZF11694_User', get_class($result->getIdentity()));
        // Write identity to storage and confirm
        $this->assertEquals('ZF11694_User', get_class($this->auth->getIdentity()));
        // Now erase it and confirm
        $this->assertNotEquals('ZF11694_User', get_class($this->auth->getIdentity()));

This test passes. I've attached the full test suite changes in a patch file.

I'm now working on reproducing your error via a ZF test application which uses the database auth adapter.

I have created a simple ZF app (attached) to test {{Zend_Auth_Storage_Session}} + {{Zend_Auth_Adapter_DbTable}}, and could not reproduce the issue you are reporting. Could you please provide more information on your custom adapter,{{System_AuthAdapter}} - specifically what it returns via the {{getResultRowObject()}} method?

Previous patch (ZF-11694_test.patch) was FUBARed; it has now been replaced with the correct patch.