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

查看:13
本文介绍了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 致命错误:未捕获的异常 'SymfonyComponentRoutingExceptionResourceNotFoundException'

PHP Fatal error: Uncaught exception 'SymfonyComponentRoutingExceptionResourceNotFoundException'

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

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天全站免登陆