1

Symfony2 的新用户在这里。

我正在尝试使用 FOSUserBundle 设置防火墙。

在/admin/需要用户成为管理员之后,我已经拥有了一切。

但是,我想将登录路径移动到/admin/login而不仅仅是/login

安全.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 }

路由.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

尝试访问/admin/login时出现以下错误

No route found for "GET /admin/login

编辑:路线

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

2 回答 2

3

我遇到了和你一样的问题,下一个解决方案帮助我看到了登录页面。

尝试将前缀添加到您的 fos_user_security 路由

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

希望这有帮助。您可能会进一步遇到一些访问问题,我还没有解决方案,但也许您可以自己找到解决方案。祝你好运,也许你会与我们分享解决方案,那太好了

玩得开心编码。

于 2014-06-12T13:15:58.687 回答
2

您需要将您的 security.yml 更改为:

security:
    firewalls:
        main:
            form_login:
                login_path: /admin/login
于 2013-09-11T09:33:16.123 回答