multiple firewalls with symfony2

前端 未结 3 1413
北海茫月
北海茫月 2020-12-25 13:14

How to have multiple firewalls with symfony2?

This is mentioned in the documentation but never explained.

相关标签:
3条回答
  • 2020-12-25 13:54

    In your yml config file put:

    security:
        firewalls:
            filrewall_1:
                ...
            filrewall_2:
                ...
    

    Post a comment if you have problems.

    See also : http://symfony.com/doc/current/reference/configuration/security.html

    0 讨论(0)
  • 2020-12-25 13:55

    I finally found the answer. Here is the final working 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
    

    And a pastebin

    0 讨论(0)
  • 2020-12-25 14:04

    You can have users authenticate into one firewall and be authenticated on others by configuring the same firewall context. Take for example this 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

    0 讨论(0)
提交回复
热议问题