3

我在 Symfony2 中的安全配置有问题。我有两个实体:AdminsUsers.

我正在关注这个问题,但总是有"admin/login_check" unable to find例外。

谢谢!

安全.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: Mdv\CommonBundle\Entity\Administrator
                property: username
        entity_members:
            entity:
                class: Mdv\CommonBundle\Entity\User
                property: username

    firewalls:
        dev:
            pattern:  ^/(_(profiler|wdt)|css|images|js)/
            security: false

        admin_secured_area:
            pattern: ^/admin
            provider: entity_admin
            anonymous: ~
            form_login:
                login_path: /admin/login
                check_path: /admin/login_check
            logout:
                path:   /admin/logout
                target: /admin/

        members_secured_area:
            pattern: ^/user
            provider: entity_members
            anonymous: ~
            form_login:
                check_path: /user/login_check
                login_path: /user/login
            logout:
                path:   /user/logout
                target: /user/

    access_control:
        admin_login:
            path: /admin/login
            roles: IS_AUTHENTICATED_ANONYMOUSLY
        admin_area:
            path: ^/admin
            roles: ROLE_ADMIN
        members_login:
            path: /user/login
            roles: IS_AUTHENTICATED_ANONYMOUSLY
        members_register:
            path: /user/register
            roles: IS_AUTHENTICATED_ANONYMOUSLY
        members_area:
            path: ^/user
            roles: ROLE_USER

路由.yml

admin_administrator:
    resource: @MdvAdminBundle/Resources/config/routing/administrator.yml
    prefix: /admin

管理员.yml

admin_login:
    pattern: /login
    defaults: { _controller: MdvAdminBundle:Administrator:login }
admin_login_check:
    pattern: /login_check
admin_logout:
    pattern: /logout
4

1 回答 1

1

我遇到了同样的问题,我通过以下方式解决了它:

    firewalls:
        ...
        login:         #add a firewall for the login who accepts anonymous
            pattern: ^/(admin/login|user/register)$ #it will accept one of the two chains given
            anonymous: true

        admin_secured_area:
            pattern: ^/           #remove the 'admin' it will be defined in the 'access_control'
            provider: entity_admin
            anonymous: ~
            form_login:
                login_path: /admin/login
                check_path: /admin/login_check
            logout:
                path:   /admin/logout
                target: /admin/

        #remove the 'members_secured_area' it will be defined in the 'access_control'

    access_control:
        admin_login:
            path: /admin/login
            roles: IS_AUTHENTICATED_ANONYMOUSLY
        admin_area:
            path: ^/admin
            roles: ROLE_ADMIN
        members_register:
            path: /user/register
            roles: IS_AUTHENTICATED_ANONYMOUSLY
        members_area:
            path: ^/user
            roles: ROLE_USER

admin/login和可能是相同的user/login,因为它们来自同一个对象User,但它们具有不同的角色。

于 2014-05-20T19:42:42.763 回答