Symfony2 - 带FOSUserBundle的防火墙

New user with Symfony2 here.

I'm trying to set up a firewall with FOSUserBundle.

I've got everything after /admin/ needs the user to be an admin.

However, I want to move the login path to /admin/login instead of just /login

Security.yml

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: sha512

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username

    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_provider: form.csrf_provider
            logout:       true
            anonymous:    true

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

Routing.yml

pwd_admin:
    resource: "@PWDAdminBundle/Resources/config/routing.yml"
    prefix:   /admin

pwd_website:
    resource: "@PWDWebsiteBundle/Resources/config/routing.yml"
    prefix:   /

fos_js_routing:
    resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"

fos_user_security:
    resource: "@FOSUserBundle/Resources/config/routing/security.xml"

fos_user_profile:
    resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
    prefix: /profile

fos_user_register:
    resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
    prefix: /admin/register

fos_user_resetting:
    resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
    prefix: /resetting

fos_user_change_password:
    resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
    prefix: /profile

I get the following error when trying to visit /admin/login

No route found for "GET /admin/login

Edit: Routes

fos_user_security_login           ANY      ANY    ANY  /login
fos_user_security_check           POST     ANY    ANY  /login_check
fos_user_security_logout          ANY      ANY    ANY  /logout
fos_user_profile_show             GET      ANY    ANY  /profile/
fos_user_profile_edit             ANY      ANY    ANY  /profile/edit
fos_user_registration_register    ANY      ANY    ANY  /admin/register/

You need to change your security.yml as:

security:
    firewalls:
        main:
            form_login:
                login_path: /admin/login

I have had the same problem as you and the next solution helped me see the login page.

Try adding the prefix to your fos_user_security route

fos_user_security:
    resource: "@FOSUserBundle/Resources/config/routing/security.xml"
    prefix: admin

Hope this helped. You might further get some access problem, to which I do not yet have a solution, but maybe you can find the solution your self. Good luck with that and maybe you will share the solution with us, that would be great

Have fun coding.