Symfony2 is_granted('IS_AUTHENTICATED_FULLY') 404错误页面显示,导致ResourceNotFoundException [英] Symfony2 is_granted('IS_AUTHENTICATED_FULLY') during 404 error page display, causing ResourceNotFoundException

查看:43
本文介绍了Symfony2 is_granted('IS_AUTHENTICATED_FULLY') 404错误页面显示,导致ResourceNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了自定义错误页面以显示文件夹中的某些 HTTP 错误:

I have setup custom error pages to display for certain HTTP errors in the folder:

app/Resources/TwigBundle/views/Exception/

403 页面 (error403.html.twig) 按预期工作和显示.

The 403 page (error403.html.twig) works and displays as expected.

500 页 (error500.html.twig) 按预期工作和显示.

The 500 page (error500.html.twig) works and displays as expected.

404 页面 (error404.html.twig) 抛出 500 服务器错误:

The 404 page (error404.html.twig) throws a 500 server error:

PHP 致命错误:未捕获的异常 'Symfony\Component\Routing\Exception\ResourceNotFoundException'

PHP Fatal error: Uncaught exception 'Symfony\Component\Routing\Exception\ResourceNotFoundException'

通过执行身份验证检查为已通过或未通过身份验证的用户显示某些菜单项会引发错误:

The error is being thrown by doing an auth check to display certain menu items for users that are or aren't authenticated:

{% if is_granted('IS_AUTHENTICATED_FULLY') %}

如果我删除该检查并只允许显示所有菜单项,则页面会按预期加载错误页面.同样,403 页面按原样显示,并且可以毫无问题地使用身份验证检查.

If I remove that check and just allow all menu items to display, the page loads the error page as expected. Again, the 403 page displays as it should and utilizes the auth checks without a problem.

我被这个问题困住了.除了文件名之外,页面完全相同.

I'm stuck on this one. The pages are EXACTLY the same, apart from the filename.

推荐答案

从 2.1 开始,您不能在 404 页面中使用 is_granted:

You can't use the is_granted in a 404 page since 2.1:

升级文件中有提到

防火墙侦听器现在在路由器侦听器之后注册.这意味着特定的防火墙 URL(如/login_check 和/logout)现在必须在您的路由配置中定义正确的路由.此外,如果您有自定义 404 错误页面,请确保您没有在其上使用任何与安全相关的功能,例如 is_granted.

The Firewall listener is now registered after the Router listener. This means that specific Firewall URLs (like /login_check and /logout) must now have proper routes defined in your routing configuration. Also, if you have a custom 404 error page, make sure that you do not use any security related features such as is_granted on it.

见:https://github.com/symfony/symfony/blob/master/UPGRADE-2.1.md#security

这篇关于Symfony2 is_granted('IS_AUTHENTICATED_FULLY') 404错误页面显示,导致ResourceNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆