如何在Symfony2中注册身份验证处理程序服务?

时间:2012-03-23 03:10:42

标签: symfony

我需要编写一个基本的身份验证处理程序。在我的onAuthenticationFailure中,仅用于测试,我是var-dumping $request。它应该使用不良凭证,但没有任何反应。

我猜我的src\Acme\TestBundle\resources\Config\services.yml

出了问题
services:
    authentication_handler:
        class: Acme\TestBundle\Handler\AuthenticationHandler

这是测试类,删除了使用语句以提高可读性:

namespace Acme\TestBundle\Handler;

class AuthenticationHandler implements AuthenticationSuccessHandlerInterface,
    AuthenticationFailureHandlerInterface, LogoutSuccessHandlerInterface
{

    function onAuthenticationSuccess(Request $request, TokenInterface $token)
    {
        $user = $token->getUser();
    }

    function onAuthenticationFailure(Request $request,
        AuthenticationException $exception)
    {
        var_dump($request);
        die();
    }

    public function onLogoutSuccess(Request $request)
    {
    }

}

1 个答案:

答案 0 :(得分:2)

您需要在security.yml文件中设置处理程序:

form_login:
    success_handler: authentication_handler
    failure_handler: authentication_handler
logout:
    success_handler: authentication_handler
相关问题