dptrmt4366 2014-12-22 10:34
浏览 54
已采纳

symfony2配置防火墙 - 登录时的奇怪行为

I am using symfony2 with FOSUserBundle and i am trying to set up correctly my firewall.

I want the major part of my website to not be available to anonymous users. Home page (the $ in the public pattern) and some others should be available according to a pattern.

With my current configuration, after login I am redirected to the home page but still as anonymous. If i directly type a url of a page not allowed to anonymous directly afterwards, I can access it and I am logged (in the profiler).

My configuration:

dev:
    pattern:  ^/(_(profiler|wdt)|css|images|js)/
    security: false
public:
    pattern:        /(login$|register|resetting|public|$)
    anonymous:      true
main:
    pattern:        ^/
    anonymous:      false
    provider:       main
    form_login:
        login_path: fos_user_security_login
        check_path: fos_user_security_check
    logout:
        path:       fos_user_security_logout
        target:     /

What can I do to make it work properly (logged correctly after login).

EDIT: I understand better what is happening: after login, I am being redirected to the home page=root address. This falls first into the public firewall and that's whay I'm not seen as connected.

  • 写回答

2条回答 默认 最新

  • doushu7588 2014-12-22 11:23
    关注

    Done! Solution involves the context property of the firewall which is better described here : Authenticate multiple symfony2 firewalls with one login form

    My configuration now becomes:

    firewalls:

    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false
    guest:
        pattern:        /(user/login$|user/register|user/resetting|$)
        anonymous:      true
        context:        main_auth
    main:
        pattern:        ^/(?!user/login$)
        anonymous:      false
        provider:       main
        context:        main_auth
        form_login:
            login_path: fos_user_security_login
            check_path: fos_user_security_check
        logout:
            path:       fos_user_security_logout
            target:     /
        remember_me:
            key:      "%secret%"
            lifetime: 86400 # 365 jours en secondes
            path:     /
            domain:   ~ # Prend la valeur par défaut du domaine courant depuis $_SERVER
        oauth:
            remember_me: true
            resource_owners:
                facebook:           "/loginhwi/check-facebook"
                github:             "/loginhwi/check-github"
                google:             "/loginhwi/check-google"
                twitter:            "/loginhwi/check-twitter"
                linkedin:           "/loginhwi/check-linkedin"
                flickr:             "/loginhwi/check-flickr"
            login_path:        fos_user_security_login
            check_path:        fos_user_security_check
            failure_path:      fos_user_security_login
            success_handler:  foodmeup_user.handler_auth
            oauth_user_provider:
                service: fosubuser.provider
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源