我需要编写一个基本的身份验证处理程序。在我的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)
{
}
}
答案 0 :(得分:2)
您需要在security.yml
文件中设置处理程序:
form_login:
success_handler: authentication_handler
failure_handler: authentication_handler
logout:
success_handler: authentication_handler