所有! 我想用安全系统一起保护我的应用程序。 在security.yml文件下面
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
in_memory:
users:
user: { password: userpass, roles: [ 'ROLE_USER' ] }
admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/{_locale}/demo/secured/login$
security: false
secured_area:
pattern: ^/{_locale}/demo/secured/
form_login:
check_path: /{_locale}/demo/secured/login_check
login_path: /{_locale}/demo/secured/login
logout:
path: /{_locale}/demo/secured/logout
target: /{_locale}/demo/
问题:
logout->目标返回不起作用。 有人能帮助我吗?
PS:任何例子都会受到赞赏!
THX
答案 0 :(得分:15)
只需确保为所有使用locale变量的路由定义路由,并且安全性似乎会自动获取它。无需在安全配置中考虑区域设置。
这是我项目的一个例子。
摘录自security.yml
:
login:
pattern: /(game|admin)/login$
security: false
admin:
pattern: /admin/
form_login:
check_path: /admin/login_check
login_path: _admin_login
logout:
path: _admin_logout
target: _home
game:
pattern: /game/
form_login:
check_path: /game/login_check
login_path: _game_login
logout:
path: _game_logout
target: _home
摘录自routing.yml
:
BrowserMMOSecurityBundle:
resource: "@BrowserMMOSecurityBundle/Controller/"
type: annotation
prefix: /{_locale}/
defaults: { _locale: en }
requirements:
_locale: en|fr
_game_login_check:
pattern: /game/login_check
_admin_login_check:
pattern: /admin/login_check
_admin_logout:
pattern: /{_locale}/admin/logout
requirements:
_locale: en|fr
_game_logout:
pattern: /{_locale}/game/logout
requirements:
_locale: en|fr
以上配置适合我。值得注意的是_admin_login
和_game_login
路由是在SecurityController
类的注释中定义的。