dongzhenjian5195 2014-03-19 17:21
浏览 45

symfony2中的重定向循环,FOSUserBundle

I developped my first site with symfony, so maybe I'm having a really obvious problem.

I had no problem on my local dev server, but since I send it to my live server and using app.php instead of app_dev.php, I am stuck in a redirect loop...

I looked over the internet and it seems that redirect loop are often caused by security.yml.

I'm using FOSUserBundle, maybe this is related ?!

Edit : Since everyone is pointing out the fact I'm using /admin as route for login may be one of the cause of my problem, I changed it to /admin/login but I still have the problem.

Maybe I should clarify some point. The website is in two part : - a frontend, which can be accessible for everyone - a backoffice in which you can find some CMS like page and some other stuff..., only accessible by login.

On every page, even when I'm trying to access the homepage, I'm stuck in that loop. I end up with the requested url followed by a bunch of ///////////////////// at the end.

Anyway, here is my new security.yml :

security:
encoders:
    Symfony\Component\Security\Core\User\User: plaintext
    FOS\UserBundle\Model\UserInterface: sha512

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

providers:
    #in_memory:
    #    memory:
    #        users:
    #            user:  { password: userpass, roles: [ 'ROLE_USER' ] }
    #            admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }
    fos_userbundle:
        id: fos_user.user_manager

firewalls:
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false

    login:
        pattern: ^/admin/login$
        anonymous: true

    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
            login_path: /admin/login
            always_use_default_target_path: true
            default_target_path: /admin/menu
        logout:       ~
        anonymous:    true

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

routing.yml :

mcr:
    resource: "@McrBundle/Controller/"
    type:     annotation
    prefix:   /

fos_user_security:
    resource: "@FOSUserBundle/Resources/config/routing/security.xml"

fos_user_security_login:
    pattern:   /admin/login
    defaults:  { _controller: FOSUserBundle:Security:login }

fos_user_security_check:
    pattern:   /admin/login_check
    defaults:  { _controller: FOSUserBundle:Security:check }

Any help will be greatly apreciated :)

Thanks a lot.

  • 写回答

2条回答 默认 最新

  • dongyou8368 2014-03-20 00:50
    关注

    It likely has to do with how you have your routes setup;

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

    When you try and access /admin internally symfony redirects this to /admin/ and because your AC requires the role admin im guessing you are not logged in and want to be taken to your login page which im also guessing you have on /admin. Thus creating your non ending redirect loop.

    I would recommend using /admin/login for your login route. You will need to update you routing.yml and security.yml

    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败