简体   繁体   中英

Symfony FosUserBundle access_control security admin login

this is my security file

# 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 }

this my routing app

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:   /

my problem is when I type : localhost/project/admin

i want to show login form for connect to admin back office

but is not showing it connect directly to admin

i work with fosUserBundle

finally I found the problem :
the problem was that i'm working with jms_i18n_routing bundle for Translations and Internationalisation

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 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM