Silex Security success_handler

Tes*_*ent 3 security silex

我如何为表单身份验证提供程序设置success_handler(和failure_handler)?

Silex用这个配置忽略了我:

<?php

use WebFactory\Security\UserProvider;

$app->register(new Silex\Provider\SecurityServiceProvider(), array(
    'security.firewalls' => array(
        'dev' => array(
            'pattern' => '^/(_(profiler|wdt)|css|images|js)/',
            'security' => false
        ),
        'default' => array(
            'pattern' => '^/.*$',
            'anonymous' => true,
            'form' => array(
                'login_path' => '/login',
                'check_path' => '/login_check',
                'success_handler' => 'authentication_handler', //<-- here
                'failure_handler' => 'authentication_handler', //<-- here
            ),
            'logout' => array('logout_path' => '/logout'),
            'users' => $app->share(function () use ($app) {
                        return new UserProvider($app['db']);
                    }),
        ),
    ),
    'security.access_rules' => array(
        array('^/login', 'IS_AUTHENTICATED_ANONYMOUSLY'),
        array('^/private$', 'ROLE_ADMIN'),
    ),
    'security.role_hierarchy' => array(
        'ROLE_SIMPLE_USER' => array('ROLE_USER'),
        'ROLE_ASSOCIATE' => array('ROLE_USER'),
    )
));
Run Code Online (Sandbox Code Playgroud)

这是我的习惯(从未被调用)

$app['authentication_handler'] = $app->share(function ($app) {
            return new \WebFactory\Security\AuthenticationHandler($app['url_generator']);
        });
Run Code Online (Sandbox Code Playgroud)

这是一个错误吗?

igo*_*orw 7

设置成功和失败处理程序的方法是定义一个名为security.authentication.success_handler.$name或的服务security.authentication.failure_handler.$name,$name防火墙的名称在哪里.

例如:

$app->register(new Silex\Provider\SecurityServiceProvider(), array(
    'security.firewalls' => array(
        'foo' => ...,
    ),
));

$app['security.authentication.success_handler.foo'] = $app->share(function ($app) {
    return new Your\Own\SuccessHandler();
});
Run Code Online (Sandbox Code Playgroud)

然后,安全服务提供程序将按惯例检测处理程序.