在4.1中,当用户想要访问有安全性的页面时(例如@ security (“has_role(‘ROLE_ADMIN’)”)),用户将被重定向到登录页面。起作用了。我没有错误500。
但是在我的log /var/log/prod.log中,我有一些错误:
[2018-06-06 09:30:47] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Security\Core\Exception\AccessDeniedException: "Access Denied." at /var/www/website/vendor/symfony/security/Http/Firewall/AccessListener.php line 68 {"exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException(code: 403): Access Denied. at /var/www/website/vendor/symfony/security/Http/Firewall/AccessListener.php:68)"} []
[2018-06-06 09:30:47] security.DEBUG: Access denied, the user is not fully authenticated; redirecting to authentication entry point. {"exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException(code: 403): Access Denied. at /var/www/website/vendor/symfony/security/Http/Firewall/AccessListener.php:68)"} []
[2018-06-06 09:30:47] security.DEBUG: Calling Authentication entry point. [] []
我不明白为什么我会有严重错误。
发布于 2018-06-07 04:27:07
Symfony框架定义了一个Symfony\Component\HttpKernel\EventListener\ExceptionListener
,它为方法logKernelException
订阅了优先级非常高的2048的KernelEvents::EXCEPTION
(参见https://github.com/symfony/http-kernel/blob/master/EventListener/ExceptionListener.php#L93):
public static function getSubscribedEvents()
{
return array(
KernelEvents::EXCEPTION => array(
array('logKernelException', 2048),
array('onKernelException', -128),
),
);
}
因此抛出的AccessDeniedException
首先由这个logKernelException
方法处理,该方法以CRITICAL级别记录它(请参阅https://github.com/symfony/http-kernel/blob/master/EventListener/ExceptionListener.php#L109):
protected function logException(\Exception $exception, $message)
{
if (null !== $this->logger) {
if (!$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500) {
$this->logger->critical($message, array('exception' => $exception));
} else {
$this->logger->error($message, array('exception' => $exception));
}
}
}
在此步骤中,AccessDeniedException
已登录到request通道。这与请求作用域完全相关:原始请求失败,因为没有执行身份验证...
然后,Symfony\Component\Security\Http\Firewall\ExceptionListener
,侦听KernelEvents::EXCEPTION
,但只处理与身份验证相关的任务(请参阅https://github.com/symfony/security/blob/master/Http/Firewall/ExceptionListener.php#L87)继续执行任务,以便重定向到身份验证起点……
https://stackoverflow.com/questions/50714864
复制相似问题