如何获得有关Symfony2安全系统的更多调试信息?

时间:2015-01-08 19:32:27

标签: security symfony debugging

通常,如何在请求处理期间获得有关Symfony2安全系统的各个组件所做决策的有用调试输出?我很乐意看到应用了防火墙和access_control语句以及原因。有哪些工具可以更容易地解决常年“为什么我再次被重定向到登录表单”的神秘感?

1 个答案:

答案 0 :(得分:0)

如果您需要详细的调试信息,可以使用Blackfire

如果它不够,那么你可以使用WebProfilerBundle它有很好的调试信息。

如果这对您不起作用,那么您可以创建自己的Data Collector Services。 数据收集器就像分析器扩展,它们可以帮助您收集不同的数据,如路由,调试信息或邮件数据。您可以根据需要自定义它们。

请查看文档Here

请检查SecurityDebugBundle这将回答您的所有问题。 请谨慎使用,因为它需要不同的权限。

通过阅读其代码,您将了解数据收集器如何帮助您进行调试。

希望能帮助你。

这是来自SecurityDebugBundle的DataCollecotr:

class FirewallCollector
{
    const HAS_RESPONSE = SecurityDebugDataCollector::DENIED;
    private $securityContext;
    private $container;
    public function __construct(
        SecurityContextInterface $securityContext,
        Container $container
    ) {
        $this->securityContext = $securityContext;
        //Container dependency is a bad thing. This is to be refactored to a compiler pass
        //where all the firewall providers will be fetched
        $this->container = $container;
    }
    public function collect(Request $request, \Exception $exception)
    {
        $token = $this->securityContext->getToken();
        if (!method_exists($token, 'getProviderKey')) {
            return;
        }
        $providerKey = $token->getProviderKey();
        $map = $this->container->get('security.firewall.map.context.' . $providerKey);
        $firewallContext = $map->getContext();
        $event = new GetResponseEvent(
            new SimpleHttpKernel(),
            $request,
            HttpKernelInterface::MASTER_REQUEST
        );
        $firewalls = array();
        foreach ($firewallContext[0] as $i => $listener) {
            $firewalls[$i]= array('class' => get_class($listener), 'result' => SecurityDebugDataCollector::GRANTED);
            try {
                $listener->handle($event);
            } catch (AccessDeniedException $ade) {
                $firewalls[$i]['result'] = SecurityDebugDataCollector::DENIED;
                break;
            }
            if ($event->hasResponse()) {
                $firewalls[$i]['result'] = self::HAS_RESPONSE;
                break;
            }
        }
        return $firewalls;
    }
}

这提供了很多关于防火墙的信息。 此捆绑包还包含SecurityDebugDataCollectorVotersCollector。因此,它可以提供有关所有安全组件的信息。