2012-08-08 70 views
17

我已经设置自定义错误页,显示该文件夹中的某些HTTP错误:的Symfony2中的404错误页面显示is_granted(“IS_AUTHENTICATED_FULLY”),引起ResourceNotFoundException

app/Resources/TwigBundle/views/Exception/ 

403页(error403.html.twig)的作品和显示器如预期。

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

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

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

错误被抛出通过执行一个auth检查为是或不是认证的用户显示某些菜单项:

{% if is_granted('IS_AUTHENTICATED_FULLY') %} 

如果我删除该检查并只允许显示所有菜单项,则页面按预期加载错误页面。再一次,403页面显示它应该使用的auth检查没有问题。

我被困在这一个。除了文件名外,这些页面完全相同。

+0

您正在使用哪个版本的Symfony? – j0k 2012-08-09 07:18:58

+0

最新最好的。 2.1-dev我相信 – Nick 2012-08-09 17:21:29

+2

我认为它会更好(因为-dev版本)在github上创建一个问题,symfony家伙真的有帮助:) – dmirkitanov 2012-08-09 18:52:38

回答

10

你不能在一个404页,使用is_granted自2.1:

它的升级文件中提到

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

+0

是的,他们在GitHub上收到多个问题帖后将它添加到文档中......我仍然不是这种处理方式的巨大粉丝。 – Nick 2012-10-05 17:25:29

+0

[Symfony 2.8捕获异常,而是返回false](https://github.com/symfony/symfony/pull/15953)。所以没有更多的错误,但可能不是你想要的行为。 – gapple 2015-11-20 00:44:55

2

我建议检查app.security.token更加严格,即使用户是匿名评估为true

如果您检查app.user将评估例外模板false,但即使在防火墙存在(=常规模板),但用户没有登录。这将防止 - 例如 - 显示登录按钮。

请参阅:https://github.com/symfony/symfony-docs/pull/2359