0

我在一个正在进行的项目中使用 FOSUserBundle,一切正常,但是当我关闭会话时我遇到了一个小问题,因为我转到应用程序的索引而不是留在/admin/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_email

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_provider: form.csrf_provider
            logout:
                 path: /logout
                 target: /admin
                 invalidate_session: false
            anonymous: true

    access_control:
        - { path: ^/admin, role: ROLE_ADMIN }

谁能告诉我我在哪里犯了错误?

4

1 回答 1

1

我认为是anonymous: true. 如果您基本上希望整个站点处于访问控制之下,除了登录页面之外没有其他页面可供未登录的人访问,那么您需要这样的东西:

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_email

        firewalls:
            dev:
                pattern: ^/(_(profiler|wdt)|css|images|js)/
                security: false
            main:
                pattern: ^/
                form_login:
                    provider: fos_userbundle
                    csrf_provider: form.csrf_provider
                logout:
                     path: /logout
                     target: /admin
                     invalidate_session: false
                anonymous: ~ # NO ANONYMOUS ACCESS

        access_control:
            - { path: ^/admin, role: ROLE_ADMIN }
            # anonymous visitors need to be able to get to the logon pages
            - { path: ^/login, role: IS_AUTHENTICATED_ANONYMOUSLY } 
            - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
            # Could also add "safe" routes like an "about" or "contact us" pages here if you like
            - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
于 2014-09-16T13:32:32.830 回答