sfDoctrineGuardPlugin在验证后会忘记凭据

时间:2011-02-09 19:07:50

标签: php symfony1 sfdoctrineguard

我正在寻找身份验证问题的解决方案。我在去年5月才找到一个人(在symfony-users Google小组中)有同样的问题(在底部#2)。据我所知,没有解决方案被列入清单。

在我的Mac OS X开发环境中,sfDoctrineGuardPlugin工作正常。当我尝试访问安全页面时,我被重定向到登录。当我输入有效凭证时,我会被重定向回最初请求的页面。

在DreamHost的测试环境中,它无法正常工作。当我尝试访问安全页面时,我被重定向到登录。当我输入有效凭据时,我会被重定向回最初请求的页面,但是symfony失去了我的身份验证状态,并且(重新)将我重新引导回登录状态,并重新启动表单。 (相反,如果我输入无效凭据,则会在登录页面上收到错误消息,并且用户名仍然填写。)

在每个环境中,symfony都会验证我的凭据是否有效以及我是否具有“管理员”权限,但是一旦重定向到我请求的页面,测试就会忘记这些凭据。

apache错误日志中没有任何有趣的内容。

开发日志摘要:

Feb 09 10:05:51 symfony [info] {sfPatternRouting} Match route "report" (/report.:sf_format) for /report with parameters array (  'module' => 'report',  'action' => 'index',  'sf_format' => 'html',)
Feb 09 10:05:52 symfony [info] {sfFilterChain} Executing filter "sfRenderingFilter"
Feb 09 10:05:52 symfony [info] {sfFilterChain} Executing filter "sfGuardRememberMeFilter"
Feb 09 10:05:52 symfony [info] {sfFilterChain} Executing filter "sfBasicSecurityFilter"
Feb 09 10:05:52 symfony [info] {sfBasicSecurityFilter} Action "report/index" requires authentication, forwarding to "sfGuardAuth/signin"
Feb 09 10:05:52 symfony [info] {sfFilterChain} Executing filter "sfRenderingFilter"
Feb 09 10:05:52 symfony [info] {sfFilterChain} Executing filter "sfGuardRememberMeFilter"
Feb 09 10:05:52 symfony [info] {sfFilterChain} Executing filter "sfExecutionFilter"
Feb 09 10:05:52 symfony [info] {sfGuardAuthActions} Call "sfGuardAuthActions->executeSignin()"
Feb 09 10:05:52 symfony [info] {sfPHPView} Render "/Library/WebServer/WebSites/Documents/plugins/sfDoctrineGuardPlugin/modules/sfGuardAuth/templates/signinSuccess.php"
Feb 09 10:05:52 symfony [info] {sfPartialView} Render "/Library/WebServer/WebSites/Documents/plugins/sfDoctrineGuardPlugin/modules/sfGuardAuth/templates/_signin_form.php"
Feb 09 10:05:52 symfony [info] {sfPHPView} Decorate content with "/Library/WebServer/WebSites/Documents/apps/backend/templates/layout.php"
Feb 09 10:05:52 symfony [info] {sfPHPView} Render "/Library/WebServer/WebSites/Documents/apps/backend/templates/layout.php"
Feb 09 10:05:52 symfony [info] {sfWebResponse} Send status "HTTP/1.1 401 Unauthorized"
Feb 09 10:05:52 symfony [info] {sfWebResponse} Send header "Content-Type: text/html; charset=utf-8"
Feb 09 10:05:52 symfony [info] {sfWebDebugLogger} Configuration 12.62 ms (12)
Feb 09 10:05:52 symfony [info] {sfWebDebugLogger} Factories 58.15 ms (1)
Feb 09 10:05:52 symfony [info] {sfWebDebugLogger} Action "sfGuardAuth/signin" 6.18 ms (1)
Feb 09 10:05:52 symfony [info] {sfWebDebugLogger} View "Success" for "sfGuardAuth/signin" 13.92 ms (1)
Feb 09 10:05:52 symfony [info] {sfWebDebugLogger} Partial "sfGuardAuth/_signin_form" 4.84 ms (1)
Feb 09 10:05:52 symfony [info] {sfWebResponse} Send content (53797 o)
Feb 09 10:06:04 symfony [info] {sfPatternRouting} Match route "sf_guard_signin" (/login) for /login with parameters array (  'module' => 'sfGuardAuth',  'action' => 'signin',)
Feb 09 10:06:04 symfony [info] {sfGuardSecurityUser} User is authenticated
Feb 09 10:06:04 symfony [info] {sfGuardSecurityUser} Add credential(s) "admin"
Feb 09 10:06:04 symfony [info] {sfFrontWebController} Redirect to "http://localhost/backend_dev.php/"
Feb 09 10:06:04 symfony [info] {sfWebResponse} Send status "HTTP/1.1 302 Found"
Feb 09 10:06:04 symfony [info] {sfWebResponse} Send header "Location: http:/localhost/backend_dev.php/"
Feb 09 10:06:04 symfony [info] {sfWebResponse} Send header "Content-Type: text/html; charset=utf-8"
Feb 09 10:06:04 symfony [info] {sfWebDebugLogger} Configuration 1.30 ms (8)
Feb 09 10:06:04 symfony [info] {sfWebDebugLogger} Factories 58.35 ms (1)
Feb 09 10:06:04 symfony [info] {sfWebDebugLogger} Action "sfGuardAuth/signin" 217.06 ms (1)
Feb 09 10:06:04 symfony [info] {sfWebDebugLogger} Database (Doctrine) 0.03 ms (5)
Feb 09 10:06:04 symfony [info] {sfWebResponse} Send content (123 o)
Feb 09 10:06:04 symfony [info] {sfPatternRouting} Match route "homepage" (/) for / with parameters array (  'module' => 'report',  'action' => 'index',)
Feb 09 10:06:04 symfony [info] {sfFilterChain} Executing filter "sfRenderingFilter"
Feb 09 10:06:04 symfony [info] {sfFilterChain} Executing filter "sfGuardRememberMeFilter"
Feb 09 10:06:04 symfony [info] {sfFilterChain} Executing filter "sfBasicSecurityFilter"
Feb 09 10:06:04 symfony [info] {sfFilterChain} Executing filter "sfExecutionFilter"
Feb 09 10:06:04 symfony [info] {reportActions} Call "reportActions->executeIndex()"
Feb 09 10:06:04 symfony [info] {sfPHPView} Render "/Library/WebServer/WebSites/Documents/apps/backend/modules/report/templates/indexSuccess.php"
Feb 09 10:06:05 symfony [info] {main} Call "navigation->executeNavMenu()"
Feb 09 10:06:05 symfony [info] {sfWebResponse} Send status "HTTP/1.1 200 OK"
Feb 09 10:06:05 symfony [info] {sfWebResponse} Send header "Content-Type: text/html; charset=utf-8"
Feb 09 10:06:05 symfony [info] {sfWebDebugLogger} Configuration 1.93 ms (10)
Feb 09 10:06:05 symfony [info] {sfWebDebugLogger} Factories 60.49 ms (1)
Feb 09 10:06:05 symfony [info] {sfWebDebugLogger} Action "report/index" 66.68 ms (1)
Feb 09 10:06:05 symfony [info] {sfWebDebugLogger} Database (Doctrine) 0.02 ms (3)
Feb 09 10:06:05 symfony [info] {sfWebDebugLogger} View "Success" for "report/index" 454.39 ms (1)
Feb 09 10:06:05 symfony [info] {sfWebDebugLogger} Component "navigation/navMenu" 0.17 ms (1)
Feb 09 10:06:05 symfony [info] {sfWebDebugLogger} Partial "navigation/_navMenu" 19.78 ms (1)
Feb 09 10:06:05 symfony [info] {sfWebResponse} Send content (164075 o)

测试日志摘录:

Feb 09 06:21:36 symfony [info] {sfPatternRouting} Match route "report" (/report.:sf_format) for /report with parameters array (  'module' => 'report',  'action' => 'index',  'sf_format' => 'html',)
Feb 09 06:21:36 symfony [info] {sfFilterChain} Executing filter "sfRenderingFilter"
Feb 09 06:21:36 symfony [info] {sfFilterChain} Executing filter "sfGuardRememberMeFilter"
Feb 09 06:21:36 symfony [info] {sfFilterChain} Executing filter "sfBasicSecurityFilter"
Feb 09 06:21:36 symfony [info] {sfBasicSecurityFilter} Action "report/index" requires authentication, forwarding to "sfGuardAuth/signin"
Feb 09 06:21:36 symfony [info] {sfFilterChain} Executing filter "sfRenderingFilter"
Feb 09 06:21:36 symfony [info] {sfFilterChain} Executing filter "sfGuardRememberMeFilter"
Feb 09 06:21:36 symfony [info] {sfFilterChain} Executing filter "sfExecutionFilter"
Feb 09 06:21:36 symfony [info] {sfGuardAuthActions} Call "sfGuardAuthActions->executeSignin()"
Feb 09 06:21:36 symfony [info] {sfPHPView} Render "/home/username/test.example.com/project/plugins/sfDoctrineGuardPlugin/modules/sfGuardAuth/templates/signinSuccess.php"
Feb 09 06:21:36 symfony [info] {sfPartialView} Render "/home/username/test.example.com/project/plugins/sfDoctrineGuardPlugin/modules/sfGuardAuth/templates/_signin_form.php"
Feb 09 06:21:36 symfony [info] {sfPHPView} Decorate content with "/home/username/test.example.com/project/apps/backend/templates/layout.php"
Feb 09 06:21:36 symfony [info] {sfPHPView} Render "/home/username/test.example.com/project/apps/backend/templates/layout.php"
Feb 09 06:21:36 symfony [info] {sfWebDebugLogger} Configuration 822.85 ms (12)
Feb 09 06:21:36 symfony [info] {sfWebDebugLogger} Factories 343.18 ms (1)
Feb 09 06:21:36 symfony [info] {sfWebDebugLogger} Action "sfGuardAuth/signin" 7.63 ms (1)
Feb 09 06:21:36 symfony [info] {sfWebDebugLogger} View "Success" for "sfGuardAuth/signin" 19.09 ms (1)
Feb 09 06:21:36 symfony [info] {sfWebDebugLogger} Partial "sfGuardAuth/_signin_form" 4.44 ms (1)
Feb 09 06:21:36 symfony [info] {sfWebResponse} Send content (52356 o)
Feb 09 06:21:45 symfony [info] {sfPatternRouting} Match route "sf_guard_signin" (/login) for /login with parameters array (  'module' => 'sfGuardAuth',  'action' => 'signin',)
Feb 09 06:21:45 symfony [info] {sfGuardSecurityUser} User is authenticated
Feb 09 06:21:45 symfony [info] {sfGuardSecurityUser} Add credential(s) "admin"
Feb 09 06:21:45 symfony [info] {sfFrontWebController} Redirect to "http://test.rippil.com/backend_dev.php/"
Feb 09 06:21:45 symfony [info] {sfWebDebugLogger} Configuration 21.18 ms (8)
Feb 09 06:21:45 symfony [info] {sfWebDebugLogger} Factories 162.69 ms (1)
Feb 09 06:21:45 symfony [info] {sfWebDebugLogger} Action "sfGuardAuth/signin" 233.96 ms (1)
Feb 09 06:21:45 symfony [info] {sfWebDebugLogger} Database (Doctrine) 0.03 ms (7)
Feb 09 06:21:45 symfony [info] {sfWebResponse} Send content (118 o)
Feb 09 06:21:46 symfony [info] {sfPatternRouting} Match route "homepage" (/) for / with parameters array (  'module' => 'reporttt',  'action' => 'index',)
Feb 09 06:21:46 symfony [info] {sfFilterChain} Executing filter "sfRenderingFilter"
Feb 09 06:21:46 symfony [info] {sfFilterChain} Executing filter "sfGuardRememberMeFilter"
Feb 09 06:21:46 symfony [info] {sfFilterChain} Executing filter "sfBasicSecurityFilter"
Feb 09 06:21:46 symfony [info] {sfBasicSecurityFilter} Action "report/index" requires authentication, forwarding to "sfGuardAuth/signin"
Feb 09 06:21:46 symfony [info] {sfFilterChain} Executing filter "sfRenderingFilter"
Feb 09 06:21:46 symfony [info] {sfFilterChain} Executing filter "sfGuardRememberMeFilter"
Feb 09 06:21:46 symfony [info] {sfFilterChain} Executing filter "sfExecutionFilter"
Feb 09 06:21:46 symfony [info] {sfGuardAuthActions} Call "sfGuardAuthActions->executeSignin()"
Feb 09 06:21:46 symfony [info] {sfPHPView} Render "/home/username/test.example.com/project/plugins/sfDoctrineGuardPlugin/modules/sfGuardAuth/templates/signinSuccess.php"
Feb 09 06:21:46 symfony [info] {sfPartialView} Render "/home/username/test.example.com/project/plugins/sfDoctrineGuardPlugin/modules/sfGuardAuth/templates/_signin_form.php"
Feb 09 06:21:46 symfony [info] {sfPHPView} Decorate content with "/home/username/test.example.com/project/apps/backend/templates/layout.php"
Feb 09 06:21:46 symfony [info] {sfPHPView} Render "/home/username/test.example.com/project/apps/backend/templates/layout.php"
Feb 09 06:21:46 symfony [info] {sfWebDebugLogger} Configuration 13.92 ms (12)
Feb 09 06:21:46 symfony [info] {sfWebDebugLogger} Factories 251.75 ms (1)
Feb 09 06:21:46 symfony [info] {sfWebDebugLogger} Action "sfGuardAuth/signin" 31.00 ms (1)
Feb 09 06:21:46 symfony [info] {sfWebDebugLogger} View "Success" for "sfGuardAuth/signin" 57.79 ms (1)
Feb 09 06:21:46 symfony [info] {sfWebDebugLogger} Partial "sfGuardAuth/_signin_form" 8.09 ms (1)
Feb 09 06:21:46 symfony [info] {sfWebResponse} Send content (52428 o)

可能值得一提的是来自backend / templates / layout.php的这个片段,它解释了Dev中的导航/ _navMenu行,但不考虑测试:
<?php if ($sf_user->isAuthenticated()): ?>
    <?php include_component('navigation', 'navMenu'); ?>
    ...
 <?php endif ?>

symfony-users组中的相关帖子:

  

您应该检查symfony和apache的日志。

     

加布里埃尔

     

5月28日下午2:33,sdwdd写道:

     
    

嗨,全部。

         

Symfony 1.4安装有几个问题:
    1. [无关]
    2. sfGuard插件存在问题。
    它在开发环境中运行正常,但是在测试中     用户登录后的环境会丢失会话。用户     登录,但在页面重新加载后,身份验证会话     丢失。

         

安装是带有sfGuardPlugin的核心Symfony 1.4和一些     自定义模板。

         

有关于那些的想法吗?我觉得服务器有问题     配置,但不知道什么可能是错的(提出了memory_limit     到512Mb)。

         

谢谢,
    Serg

  

1 个答案:

答案 0 :(得分:0)

我在symfony-users Google小组提示后找到答案。

第一个提示:

  

这似乎是您服务器上的会话问题。如果未存储会话变量,则无法保存身份验证状态。您应该询问Dreamhost支持,以了解会话变量无效的原因。

     克里斯托夫| Stof

第二个提示:

  

这不是与symfony相关的建议   我经常发现Session问题是由suhosin模块引起的   附带许多基于Ubuntu的主机。尝试关闭会话加密   并看看它是否有帮助。我发现例如有时候文件   Root是加密的一部分,它可能并不总是按预期工作   HTH
  亲切的问候,
  Jochen Daum

事实证明我的托管 环境使用suhosin强化PHP这可能是导致的 问题。将suhosin添加到我的解决方案搜索中,我发现了这一点 oldforums.symfony-project.org:

  

Re:用户会话不会在Ubuntu服务器上保留[消息#100928是对消息#100918的回复]
  星期一,2010年6月14日19:33 dklanac
  这是我的最后一篇文章。我发现问题只出现在我的测试环境中。 sfSessionTestStorage没有设置我需要的cookie。我将其更改为sfSessionStorage并使用“test”后缀重命名我的cookie以防止生产cookie冲突,并且事情表现得恰当。这也可以解释为什么我能够在我的开发实例上看到正确的行为,因为它也使用常规的sfSessionStorage类。

我们为开发,测试,舞台和制作使用单独的子域名,所以我的 解决方案甚至更简单。我刚刚将sfSessionTestStorage更改为 apps / appname / config / factories.yml中的sfSessionStorage。我没想到 需要更改cookie名称。