定制认证成功处理程序

时间:2016-08-14 13:57:14

标签: php symfony silex

我尝试在用户登录我的网站时执行自定义操作/请求。

我发现主题非常接近How to implement a custom authentication success handler with Silex framework? 我实现了答案解决方案,适合我的配置和Silex v2:

Intent

DefaultAuthenticationFailureHandler.php

$app['security.authentication.success_handler.secured'] = function($app) {
    $handler = new Model\DefaultAuthenticationSuccessHandler(
        $app['security.http_utils'],
        $app['security.firewalls']['secured']['form']
    );
    $handler->setProviderKey('secured');

    return $handler;
};

$app['security.authentication.failure_handler.secured'] = function($app) {
    return new Model\DefaultAuthenticationFailureHandler(
        $app,
        $app['security.http_utils'],
        $app['security.firewalls']['secured']['form'],
        $app['logger']
    );
};

DefaultAuthenticationSuccessHandler.php

namespace Model;

use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationFailureHandler as BaseDefaultAuthenticationFailureHandler;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Exception\AuthenticationException;

class DefaultAuthenticationFailureHandler extends BaseDefaultAuthenticationFailureHandler
{
    public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
    {
        return parent::onAuthenticationFailure($request, $exception);
    }
}

但是当我登录网站时出现错误:

namespace Model;

use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler as BaseDefaultAuthenticationSuccessHandler;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;

class DefaultAuthenticationSuccessHandler extends BaseDefaultAuthenticationSuccessHandler
{
    public function onAuthenticationSuccess(Request $request, TokenInterface $token)
    {
        return parent::onAuthenticationSuccess($request, $token);
    }
}

所以似乎Silex没有找到类AuthenticationException,但我不知道为什么。也许问题来自其他地方......

感谢您的帮助

0 个答案:

没有答案