dqg95034 2014-08-26 17:46
浏览 96
已采纳

zf2会话验证失败

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()){

  • 写回答

1条回答 默认 最新

  • dongqian0763 2015-03-31 15:34
    关注

    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...)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog