Silex Security success_handler [英] Silex Security success_handler
问题描述
如何为表单身份验证提供程序设置 success_handler(和 failure_handler)?
How i can set a success_handler (and failure_handler) for the form authentication provider?
Silex 使用此配置忽略我:
Silex ignores me with this config:
<?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'),
)
));
这是我的习惯(从未调用过)
And this my custom (never invoked)
$app['authentication_handler'] = $app->share(function ($app) {
return new \WebFactory\Security\AuthenticationHandler($app['url_generator']);
});
这是一个错误?
推荐答案
设置成功和失败处理程序的方式是定义一个名为 security.authentication.success_handler.$name
或 的服务security.authentication.failure_handler.$name
,其中$name
是防火墙的名称.
The way you set success and failure handlers is by defining a service called security.authentication.success_handler.$name
or security.authentication.failure_handler.$name
, where $name
is the name of the firewall.
例如:
$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();
});
然后安全服务提供者将按照约定检测处理程序.
The security service provider will then detect the handlers by convention.
这篇关于Silex Security success_handler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!