duanquezhan7268 2014-09-23 10:09
浏览 46
已采纳

如何在symfony中的匿名会话中查看经过身份验证的用户

I have a little problem in project with symfony.

I am developing a article website in which normal visitor can see all the article without login and admin can login and add or remove article but admin can remove the comments that are marked as spam in article page after login.The problem is that i have allowed anonymous in article section (main controller) and if i login in admin section still session shows me anonymous user in main controller.? why?

 firewalls:
    admin_login:
        pattern:  ^/admin/login$
        security: false
    main_area:(article area)
        pattern: ^/main
        anonymous: ~

    adminrestricted_area:
        pattern: ^/
        form_login:
            csrf_provider: form.csrf_provider
            login_path: _admin_login
            check_path: _admin_login_check
        logout:
            path:   _admin_logout
            target: _admin_login

only page having /admin in url shows me the current logged in user but i want to access that user in /main but in session it shows me enter image description here

Am i missing something?

I want that if login it should show me the logged in user and if i don't this page should normally be accessed without login?

  • 写回答

1条回答 默认 最新

  • drgovyk64676 2014-09-23 11:41
    关注

    In Symfony, you may define many area in the security.yml configuration. But each area is separated. You may be authenticated in one area but not in the other.

    In your case, your user is authenticated in the admin_login area, but not in the main_area, so Symfony's consider that you are an anonymous user.

    If you need that your admin can be connected in the "public area", so you need to define a single area, and use the access_control. Something like this :

    firewalls:
        main:
            pattern: ^/
            form_login:
                csrf_provider: form.csrf_provider
                login_path: _admin_login
                check_path: _admin_login_check
            logout:
                path:   _admin_logout
                target: _admin_login
            anonymous: ~
    
    access_control:
        - { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/, role: ROLE_ADMIN }
        - { path: ^/, role: IS_AUTHENTICATED_ANONYMOUSLY }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 主要进行描述泥浆在管路不同区段泥浆的密度不相同,泥浆的密度有高有低,此时管路的摩阻分布需要怎么计算,(标签-matlab)
  • ¥40 通过编制程序计算圆管内层流充分发展对流换热,参数如图5-4,以及公式5-16所示,要求用表5-6对程序计算准确性进行验证
  • ¥20 该学习哪个编程语言? AI会取代程序员吗?
  • ¥15 ensp如何拼通IP地址
  • ¥15 saber软件导入Ibis模型报错
  • ¥15 商城生产日期批次库存问题
  • ¥15 esp8266控制共阳极wrgb灯板无法关闭所有led灯
  • ¥100 python读取速度问题
  • ¥15 stm32f407使用DMA问题
  • ¥15 您好 这个API接口该怎么弄 网站搭建好了 API也有 现在就不知道该怎么填写API 不知道怎么用