0
當symfony2中的防火牆決定重定向到登錄時,我嘗試攔截。防火牆重定向事件
我的目標是跟蹤應該被稱爲,並保持它的URL(會話,甚至餅乾)每當一個全成登錄情況(所以即使用戶寄存器和第一遵循雙選入)。所以我需要當前稱爲url(不只是路徑)和請求(爲了寫入會話/ cookie)。
我嘗試瀏覽symfony2代碼,但找不到任何東西。它在文檔中也沒有提到任何相關內容。
任何人有任何想法嗎?
當symfony2中的防火牆決定重定向到登錄時,我嘗試攔截。防火牆重定向事件
我的目標是跟蹤應該被稱爲,並保持它的URL(會話,甚至餅乾)每當一個全成登錄情況(所以即使用戶寄存器和第一遵循雙選入)。所以我需要當前稱爲url(不只是路徑)和請求(爲了寫入會話/ cookie)。
我嘗試瀏覽symfony2代碼,但找不到任何東西。它在文檔中也沒有提到任何相關內容。
任何人有任何想法嗎?
我找到了解決方案,我在kernel.exception
上聽。 當拋出異常時,我檢查它是否是AccessDeniedException
的一個實例並對它做出反應。
這是我的服務定義:
whatever_bundle.event_listener.exception_listener:
class: WhateverBundle\EventListener\ExceptionListener
tags:
- { name: kernel.event_listener, event: kernel.exception, priority: 1 }
這是監聽器類:
<?php
namespace WhateverBundle\EventListener;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
class ExceptionListener
{
public function onKernelException(GetResponseForExceptionEvent $event)
{
if ($event->getException() instanceof AccessDeniedException) {
doTheThingsYouWantToDoInThisCase();
}
}
}