dsce23640 2015-02-05 13:44
浏览 84
已采纳

访问/ admin,为什么登录系统的用户可以访问?

I have days trying to make this work and I can't so as a last resort I hope any can help me here. The point is that my application, as every application has a frontend which should be accessed by any user registered in the system except those that have, so far, the role ROLE_ADMIN and a backend which so otherwise, should have access only users with ROLE_ADMIN and normal users who do not own roles or having the default role ROLE_USER should neither be able to login.

The problem I have is that, regardless, if I sign with any normal user without permissions to the admin (lacks ROLE_ADMIN) and access to the URL app.php/admin them can enter without any problem which is completely wrong. On the other hand if I try to log on to the frontend with any user with ROLE_ADMIN can do it without any problem and this should not happen.

This is my configuration security.yml:

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

    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
                login_path:  /login
                check_path:  /login_check
                default_target_path: home
                always_use_default_target_path: true
                use_referer: true
            logout:
                 path: fos_user_security_logout
                 target: /
                 invalidate_session: true
            anonymous: ~

    access_control:
        # Anonymous area
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/isLoggedIn$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/registro, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/cedula, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/rif, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/correo, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/usuario, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/razon_social, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/registro_mercantil, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/padre, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/correo_alternativo, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/paises, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/estados, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/ciudades, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/municipios, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/parroquias, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/empresas, role: IS_AUTHENTICATED_ANONYMOUSLY }

        # Secured area
        - { path: ^/, role: ROLE_USER }
        - { path: ^/admin, role: ROLE_ADMIN }

What am I doing wrong? Can anyone give me any suggestions?

I have read docs from top to bottom several times but don't get what I'm doing wrong

  • 写回答

1条回答 默认 最新

  • dpp3047 2015-02-05 13:56
    关注

    Access control works very similar to routing, the first match is the one executed.

    This means that requests for /admin will be matched with:

    - { path: ^/, role: ROLE_USER }
    

    You should put your /admin rule first. Also, I find it much better practice to secure the controllers whenever you can (which avoids common problems like these): http://symfony.com/doc/current/book/security.html#securing-controllers-and-other-code

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图