Acelasi Eu
Acelasi Eu

Reputation: 914

zf2 session validation failed

I am using zf2, rbcomments, doctrine, zfcuser and samuser entity...I have a problem, before onbootstrap, my application throws "session validation failed" error. I do not use sessions anywhere except authentication (which is done by zfcuser, not manually). here is the call stack:

Additional information:
Zend\Session\Exception\RuntimeException
File:
C:\wamp\www\vendor\zendframework\zendframework\library\Zend\Session\SessionManager.php:111
Message:
Session validation failed
Stack trace:
#0 C:\wamp\www\vendor\zendframework\zendframework\library\Zend\Session\AbstractContainer.php(78): Zend\Session\SessionManager->start()
#1 C:\wamp\www\vendor\zendframework\zendframework\library\Zend\Authentication\Storage\Session.php(63): Zend\Session\AbstractContainer->__construct('Zend_Auth', NULL)
#2 C:\wamp\www\vendor\zf-commons\zfc-user\src\ZfcUser\Authentication\Storage\Db.php(116): Zend\Authentication\Storage\Session->__construct()
#3 C:\wamp\www\vendor\zf-commons\zfc-user\src\ZfcUser\Authentication\Storage\Db.php(42): ZfcUser\Authentication\Storage\Db->getStorage()
#4 C:\wamp\www\vendor\zendframework\zendframework\library\Zend\Authentication\AuthenticationService.php(134): ZfcUser\Authentication\Storage\Db->isEmpty()
#5 C:\wamp\www\vendor\zf-commons\zfc-user\src\ZfcUser\View\Helper\ZfcUserIdentity.php(23): Zend\Authentication\AuthenticationService->hasIdentity()
#6 [internal function]: ZfcUser\View\Helper\ZfcUserIdentity->__invoke()
#7 C:\wamp\www\vendor\zendframework\zendframework\library\Zend\View\Renderer\PhpRenderer.php(400): call_user_func_array(Object(ZfcUser\View\Helper\ZfcUserIdentity), Array)
#8 C:\wamp\www\module\Application\view\layout\layout.phtml(118): Zend\View\Renderer\PhpRenderer->__call('zfcUserIdentity', Array)
#9 C:\wamp\www\module\Application\view\layout\layout.phtml(118): Zend\View\Renderer\PhpRenderer->zfcUserIdentity()
#10 C:\wamp\www\vendor\zendframework\zendframework\library\Zend\View\Renderer\PhpRenderer.php(507): include('C:\\wamp\\www\\mod...')
#11 C:\wamp\www\vendor\zendframework\zendframework\library\Zend\View\View.php(205): Zend\View\Renderer\PhpRenderer->render(Object(Zend\View\Model\ViewModel))
#12 C:\wamp\www\vendor\zendframework\zendframework\library\Zend\Mvc\View\Http\DefaultRenderingStrategy.php(102): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#13 [internal function]: Zend\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Zend\Mvc\MvcEvent))
#14 C:\wamp\www\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#15 C:\wamp\www\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('render', Object(Zend\Mvc\MvcEvent), Array)
#16 C:\wamp\www\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(347): Zend\EventManager\EventManager->trigger('render', Object(Zend\Mvc\MvcEvent))
#17 C:\wamp\www\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(300): Zend\Mvc\Application->completeRequest(Object(Zend\Mvc\MvcEvent))
#18 C:\wamp\www\public\index.php(26): Zend\Mvc\Application->run()
#19 {main}

more info that could help (the only listener yet to be added):

public function onBootstrap(MvcEvent $mvcEvent)
{
    $zfcServiceEvents = $mvcEvent->getApplication()->getServiceManager()->get('zfcuser_user_service')->getEventManager();
    $zfcServiceEvents->attach('register', function($e) use($mvcEvent) {

        $app = $mvcEvent->getApplication();
        $sm = $app->getServiceManager();
        $user = $e->getParam('user');
        $entityManager = $sm->get('Doctrine\ORM\EntityManager');
        $roleRepo = $entityManager->getRepository('SamUser\Entity\Role');
        $defaultRole = $roleRepo->findOneBy(array('id'=>2));
        $user->addRole($defaultRole);
    });
}

I tried a few things (like printing the session in vendor, nothing seems wrong)...any ideas?

P.s. I suspect it has to do with the layout, where I am trying to see if user has identity by using if(!$this->zfcUserIdentity()){

Upvotes: 2

Views: 5283

Answers (1)

Derek Illchuk
Derek Illchuk

Reputation: 5658

This just happened to me when Google Chrome updated, changing its UserAgent string. Session validation notices, and throws the exception. Look in your config for ['session_manager']['validators'] and remove HttpUserAgent.

Your existing session still needs to be toasted by removing its cookie, then going forward this UserAgent check won't occur.

(What would be nice is to just quietly start a new session without the big explosion. I'm looking into it...)

Upvotes: 7

Related Questions