AuthenticationSuccessHandler失败

时间:2015-05-26 11:30:31

标签: security symfony service handler

如果用户登录,我想调用AuthenticationSuccessHandler。 但是,如果我使用正确的密码尝试它,则会发生错误:

  

request.INFO:匹配路由“login_check”(参数:“_ control”:“AppBundle \ Controller \ SecurityController :: loginCheckAction”,“_ lute”:“login_check”)[] []   request.CRITICAL:未捕获PHP异常Symfony \ Component \ Debug \ Exception \ ContextErrorException:“可捕获致命错误:传递给Symfony \ Component \ Security \ Core \ Authentication \ Token \ UsernamePasswordToken :: __ construct()的参数4必须是类型数组,给出字符串,在第96行的/home/jail/home/users/requiem/rpg/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php中调用,并定义为“at / home / jail / home / users / requiem / rpg / vendor / symfony / symfony / src / Symfony / Component / Security / Core / Authentication / Token / UsernamePasswordToken.php line 36 {“exception”:“[object](Symfony \ Component) \ Debug \ Exception \ ContextErrorException(code:0):Catchable Fatal Error:Argument 4传递给Symfony \ Component \ Security \ Core \ Authentication \ Token \ UsernamePasswordToken :: __ construct()必须是数组类型,字符串给定,调用/家庭/监狱/家庭/用户/安魂曲/篮板/供应商/ symfony中/ symfony中/ src目录/ Symfony的/分量/安全/核心/认证/供应商/ U第96行的serAuthenticationProvider.php,定义于/home/jail/home/users/requiem/rpg/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php:36)“} []   security.DEBUG:在session [] []

中写入SecurityContext

我的档案:

security.yml

firewalls:
    secured_area:
        pattern: ^/
        anonymous: ~
        form_login:
            login_path: /login
            check_path: /login_check
            always_use_default_target_path: true
            default_target_path: /rpg/main
            username_parameter: _username
            password_parameter: _password
            success_handler: security.authentication.success_handler

services.yml

security.authentication.success_handler:
        class: AppBundle\Handler\AuthenticationSuccessHandler
        arguments: [@security.http_utils, @service_container, {}]
        tags:
            - { name: 'monolog.logger', channel: 'security'}

的src /的appbundle /处理器/ AuthenticationSuccessHandler

namespace AppBundle\Handler;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Router;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler;
use Symfony\Component\Security\Http\HttpUtils;

class AuthenticationSuccessHandler extends DefaultAuthenticationSuccessHandler{
protected $container;

public function __construct(HttpUtils $httpUtils, ContainerInterface $cont, array $options)
{
    parent::__construct($httpUtils, $options);
    $this->container=$cont;
}

public function onAuthenticationSuccess(\Symfony\Component\HttpFoundation\Request $request, \Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token)
{
    $user=$token->getUser();
    $user->setLogged(new \DateTime());

    $em=$this->container->get('doctrine.orm.entity_manager');

    $em->persist($user);
    $em->flush();

    return $this->httpUtils->createRedirectResponse($request, $this->determineTargetUrl($request));
}
}

0 个答案:

没有答案
相关问题