我使用此SecurityServiceProvider
设置安装了Silex:
$this->app->register(new SecurityServiceProvider(), array(
'security.firewalls' => array(
'login' => array(
'pattern' => '^/login$',
),
'secured' => [
'pattern' => '^/admin.*$',
'anonymous' => true,
'form' => array(
'login_path' => '/login',
'check_path' => '/admin/auth'
),
'logout' => array(
'logout_path' => '/admin/logout'
),
'users' => $this->app->share(function() use ($self) {
return new AuthenticationSuccessHandler($self->app['db']);
}),
]
),
'security.role_hierarchy' => [
'ROLE_USER' => [],
'ROLE_BACKEND_USER' => ['ROLE_USER'],
'ROLE_SUPERADMIN' => $this->getAllBasicRoleName()
],
'security.access_rules' => array(
['^/.*$', 'ROLE_USER'],
['^/admin.*$', 'ROLE_SUPERADMIN'],
['^/admin.*$', 'ROLE_BACKEND_USER']
)
));
此设置解决:
/login -> login form
/admin -> secure area
/admin/logout -> logout form
但我需要在管理路径下可以访问登录表单,如下所示:
/admin/login -> login form UNDER ADMIN PATH!
/admin -> secure area
/admin/logout -> logout form
有办法做到这一点吗?
感谢。 S上。
答案 0 :(得分:0)
您是否尝试过更改:
'login_path' => '/login',
到'login_path' => '/admin/login',
?
我认为您还希望将'pattern'=> '^/login$',
更改为'pattern'=> /admin(.*)