symfony2のセキュリティ設定を取得しようとしていますが、これまでのところ動作していますが、今はもっと魅力的なことをする必要があります。私は現在、PreAuthenticationを扱うすべてのものを使用しています(私はログインとセッション管理のために第三者コンポーネントを使用しています)。その部分はJMSセキュリティーバンドルと並行して機能しています。Symfony2のAccessDeniedHandlerInterfaceの使用
今、私は403を投げているユーザーを捕まえたいので、使用しているサードパーティコンポーネントのログインページに転送することができます。私の最善の策は、例外ハンドラを例外リスナに追加することです。私はAccessDeniedHandlerInterfaceを見ています。
- これは正しい方向ですか?
- このハンドラを例外リスナーに追加するにはどうすればよいですか?
編集: 私は同様のことをやった。私はkernel.exceptionイベントでプロンプトされるサービスを作成しました。
services:
kernel.listener.accessDenied:
class: Fully\Qualified\Namespace\Path\To\Class
tags:
- { name: kernel.event_listener, event: kernel.exception, method: onAccessDeniedException }
とクラス、それを自己::
<?php
namespace Fully\Qualified\Namespace\Path\To;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent,
Symfony\Component\HttpFoundation\Response,
Symfony\Component\Security\Core\Exception\AccessDeniedException;
class Class
{
public function onAccessDeniedException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
//Get the root cause of the exception.
while (null !== $exception->getPrevious()) {
$exception = $exception->getPrevious();
}
if ($exception instanceof AccessDeniedException) {
//Forward to third-party.
}
}
}