Symfony FosUserBundle access_control安全管理员登录

时间:2017-07-19 20:06:45

标签: php symfony fosuserbundle php-5.5

这是我的安全档案

# app/config/security.yml
security:
    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt

    role_hierarchy:
        ROLE_CONDIDAT:       ROLE_VISITEUR
        ROLE_RECRUTEUR:      ROLE_CONDIDAT
        ROLE_ADMIN :         ROLE_RECRUTEUR

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username

    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_token_generator: security.csrf.token_manager

                login_path: fos_user_security_login
                check_path: fos_user_security_check
                # if you are using Symfony < 2.8, use the following config instead:
                # csrf_provider: form.csrf_provider

            logout:       true
            anonymous:    true

    access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/, role: ROLE_ADMIN }

这是我的路由应用

co_manager_back:
    resource: "@CoManagerBackBundle/Resources/config/routing.yml"
    prefix:   /admin

co_manager_front:
    resource: "@CoManagerFrontBundle/Resources/config/routing.yml"
    prefix:   /
co_manager_user:
    resource: "@CoManagerUserBundle/Resources/config/routing.yml"
    prefix:   /


_liip_imagine:
    resource: "@LiipImagineBundle/Resources/config/routing.xml"


fos_user:
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"
    prefix:   /

我的问题是当我输入时: 本地主机/项目/管理

我想显示连接到管理员后台的登录表单

但未显示它直接连接到管理员

我使用fosUserBundle

1 个答案:

答案 0 :(得分:0)

最后我发现了问题:
问题是我正在使用jms_i18n_routing捆绑进行翻译和国际化

access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/%locale%/admin, roles: ROLE_ADMIN }