我需要设置我的silex防火墙,如:
www.mysite.com/* => access to all users
www.mysite.com/admin/* => access to only logged in users
我使用此设置,但它无法正常工作:
$app->register(new SecurityServiceProvider(), array(
'security.firewalls' => array(
'secure' => [
'pattern' => '^/.*$',
'anonymous' => true,
'form' => array(
'login_path' => '/admin/login',
'check_path' => '/admin/auth'
),
'logout' => array(
'logout_path' => '/admin/logout'
),
'users' => $app->share(function() use ($app) {
return new AuthenticationSuccessHandler($app['db']);
}),
]
),
'security.access_rules' => array(
array('^/admin$', 'ROLE_ADMIN')
)
));
有任何帮助吗? 非常感谢!! ; - )
答案 0 :(得分:0)
'users' => $app->share(function() use ($app) {
return new AuthenticationSuccessHandler($app['db']);
}),
上述函数需要返回一个实现
的对象的Symfony \元器件\安全\核心\用户\ UserProviderInterface
点击此处查看自定义用户提供商documentation
将login_path移动到安全区域之外也可能是合适的。另一种配置方式是:
$app['security.firewalls'] = array(
'secure' => array(
'pattern' => '^/admin/',
'form' => array('login_path' => '/login', 'check_path' => '/admin/auth'),
'users' => $app->share(function () use ($app) {
return new MyUserProvider($app['db']);
}),
),
),
);
$app['security.access_rules'] = array(
array('^/admin', 'ROLE_ADMIN')
);
请务必注册doctrine dbal。