如何使用symfony2创建多个防火墙?
这在文档中提到但从未解释过。
答案 0 :(得分:45)
我终于找到了答案。这是最后的工作security.yml:
security:
encoders:
entity_admin:
class: MyBundle\Entity\AdminUser
algorithm: sha512
iterations: 5000
encode_as_base64: false
entity_members:
class: MyBundle\Entity\User
algorithm: sha512
iterations: 1000
encode_as_base64: false
providers:
entity_admin:
entity:
class: MyBundle\Entity\AdminUser
property: username
entity_members:
entity:
class: MyBundle\Entity\User
property: username
firewalls:
admin_secured_area:
pattern: /admin/.*
provider: entity_admin
anonymous: ~
form_login:
check_path: /admin/login_check
login_path: /admin/login
logout:
path: /admin/logout
target: /admin/
members_secured_area:
pattern: /members/.*
provider: entity_members
anonymous: ~
form_login:
check_path: /members/login_check
login_path: /members/login
logout:
path: /members/logout
target: /members/
access_control:
admin_login:
path: /admin/login
roles: IS_AUTHENTICATED_ANONYMOUSLY
admin_area:
path: /admin/.*
roles: ROLE_ADMIN
members_login:
path: /members/login
roles: IS_AUTHENTICATED_ANONYMOUSLY
members_register:
path: /members/register
roles: IS_AUTHENTICATED_ANONYMOUSLY
members_area:
path: /members/.*
roles: ROLE_USER
答案 1 :(得分:4)
在你的yml配置文件中输入:
security:
firewalls:
filrewall_1:
...
filrewall_2:
...
如果您遇到问题,请发表评论。
另请参阅:http://symfony.com/doc/current/reference/configuration/security.html
答案 2 :(得分:1)
通过配置相同的防火墙context
,您可以让用户在一个防火墙中进行身份验证,并在其他防火墙上进行身份验证。以app / config / security.yml为例:
security:
firewalls:
filrewall_1:
...
context: my_context
filrewall_2:
...
context: my_context
http://symfony.com/doc/current/reference/configuration/security.html#firewall-context