[英]How can I get more debugging info about the Symfony2 security system?
通常,在請求處理期間,如何獲得有關Symfony2安全系統的各個組件所做出的決策的有用調試輸出? 我很樂意看到類似應用了哪些firewall和access_control語句以及原因的信息。 有哪些工具可以使人們更輕松地解決常年性的“為什么我再次被重定向到登錄表單”這個謎?
如果您需要詳細的調試信息,則可以使用Blackfire 。
如果還不夠,則可以使用WebProfilerBundle,它具有良好的調試信息。
如果那也不適合您,那么您可以創建自己的Data Collector Services。 數據收集器就像探查器擴展一樣,它們可以幫助您收集不同的數據,例如路由,調試信息或郵件數據。 您可以根據需要自定義它們。
請在此處檢查文檔
請檢查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;
}
}
這提供了有關防火牆的大量信息。 此捆綁軟件還包含SecurityDebugDataCollector和VotersCollector 。 因此,它可以提供有關所有安全組件的信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.