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 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划