简体   繁体   English

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

[英]How can I get more debugging info about the Symfony2 security system?

In general, how can I get useful debugging output about the decisions made by the various components of the Symfony2 security system during request processing? 通常,在请求处理期间,如何获得有关Symfony2安全系统的各个组件所做出的决策的有用调试输出? I would love to see things like what firewall and access_control statements were applied and why. 我很乐意看到类似应用了哪些firewall和access_control语句以及原因的信息。 What tools are there to make it easier to address the perennial "Why did I get redirected to the login form again" mystery? 有哪些工具可以使人们更轻松地解决常年性的“为什么我再次被重定向到登录表单”这个谜?

You can use Blackfire if you need detailed debug information. 如果您需要详细的调试信息,则可以使用Blackfire

If its not sufficient then you can use WebProfilerBundle it has good debugging information. 如果还不够,则可以使用WebProfilerBundle,它具有良好的调试信息。

If that also not work for you then you can create your own Data Collector Services. 如果那也不适合您,那么您可以创建自己的Data Collector Services。 Data Collectors are just like profiler extensions and they can help you to collect different data like routes, debug information or mailer data also. 数据收集器就像探查器扩展一样,它们可以帮助您收集不同的数据,例如路由,调试信息或邮件数据。 You can customize them according to your need. 您可以根据需要自定义它们。

Please check the documentation Here 请在此处检查文档

Please check SecurityDebugBundle This will answer your all questions. 请检查SecurityDebugBundle,这将回答您的所有问题。 Use it carefully, as it requires different permissions. 请谨慎使用,因为它需要不同的权限。

By Reading its code you will understand how Data Collectors can help you out in debugging. 通过阅读其代码,您将了解数据收集器如何帮助您进行调试。

Hope that will help you. 希望对您有所帮助。

Here is the DataCollecotr from 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;
    }
}

This gives alot information on Firewall. 这提供了有关防火墙的大量信息。 This Bundle Also contains SecurityDebugDataCollector and VotersCollector . 此捆绑软件还包含SecurityDebugDataCollectorVotersCollector So it can give information on all security components. 因此,它可以提供有关所有安全组件的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM