1

如果在security.yml中,在access_control中我们必须指定路径,那么拥有灵活路由有什么意义(能够在不破坏应用程序的情况下更改路由,这要归功于'admin_settings'->'/admin/settings'之类的路由标识符) (而不是ID)?

access_control:
    - { path: ^/test, ip: 127.0.0.1 }
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/reset, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/admin, role: ROLE_ADMIN }
    - { path: ^/settings, role: ROLE_USER }

每次我更改路线时,我都必须检查它是否仍然安全。

4

1 回答 1

1

最近我有同样的问题,所以我为 symfony security.yml 写了一个小扩展,添加了路由名称支持,也许你会感兴趣:https ://github.com/madesst/MadesstSecurityExtraBundle

您将能够以这种方式编写:

# app/config/security.yml
security:
    firewalls:
        secured_area:
            pattern:    '@*' # Equals to '^/' in old syntax
            anonymous:  ~
            form_login:
                login_path:  '_demo_login'
                check_path:  '_security_check'

    access_control:
        - { path: '@my_bundle_post_delete', roles: ROLE_ADMIN}
        - { path: '@my_bundle_post_*', roles: ROLE_USER}
        - { path: '@my_bundle_post', roles: IS_AUTHENTICATED_ANONYMOUSLY}
        - { path: ^/esi, roles: IS_AUTHENTICATED_ANONYMOUSLY, ip: 127.0.0.1 }
        - { path: ^/esi, roles: ROLE_NO_ACCESS }
于 2013-01-29T06:30:49.920 回答