1

I'm using Symfony 2.3 and I have a problem on my production server.

It happens (not always) that (I did not understand what opportunities) in the production environment all AJAX requests fail. In prod.log I have:

security.INFO: Populated SecurityContext with an anonymous Token [] []
[2013-08-08 16:03:28] security.INFO: No expression found; abstaining from voting. [] []
[2013-08-08 16:03:28] security.DEBUG: Access is denied (user is not fully authenticated)      by  "/var/www/clients/client1/web1/web/vendor/symfony/symfony/src/Symfony/Component/Security/Http/Firewall/AccessListener.php" at line 73; redirecting to authentication entry point

If I am in prod environment and I refresh the page (after the ajax errors), nothing happens. I'm still logged in. But ajax fails with same errors. If I switch to app_dev.php the errors disappear and AJAX works.

(The ajax routes is under game/* pattern)

Here my config:

jms_security_extra:
secure_all_services: false
expressions: true

security:
    encoders:
        Gdr\UserBundle\Entity\User: sha512

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

providers:
    database:
        entity: { class: GdrUserBundle:User, property: email }

firewalls:
    secured_area:
        pattern:    ^/
        form_login:
            check_path: /login_check
            login_path: /login
            success_handler: authentication_handler
        logout:
            path:   /logout
            target: /
            success_handler: authentication_handler
            invalidate_session: true
        anonymous: ~

access_control:
    - { path: /game/*, roles: ROLE_USER }
    - { path: /login/choose-character, roles: ROLE_USER }
    - { path: /login, roles: IS_AUTHENTICATED_ANONYMOUSLY}
    - { path: /logout, roles: ROLE_USER }
    - { path: /admin/*, roles: ROLE_ADMIN }

######Config.yml
framework:
session:
    cookie_lifetime: 0
    save_path: "%kernel.root_dir%/Sessions/"
    cookie_httponly: false
   # save_path: ~

Every ajax request that I log with firebug send a 302 header to redirect to login. If I try to access without AJAX to the url, it works. No 302 code.

Any idea?

j0k
  • 22,600
  • 28
  • 79
  • 90
Diego
  • 215
  • 1
  • 7
  • 14
  • It silly, but it is always useful to begin with: Have you cleared the cache? – Jovan Perovic Aug 08 '13 at 14:37
  • Try listening to traffic to server. My guess that session_id cookie is not being sent and thus no secure session could be established. Can you temporarily disable those custom `session` settings in `config.yml` in order to see if that could be the cause? – Jovan Perovic Aug 08 '13 at 14:58
  • mb you have some proxy server that disable cookie? – Alexey B. Aug 08 '13 at 15:23

1 Answers1

0

I found the problem.

The issue was that I was using absolute urls with 'www' i.e. www.mydomain.com, but the cookie host was without 'www'.

Using relative urls now is all fine. Thanks all :)

I found here my solutions, at the end: Symfony, jQuery.ajax() call, session variables lost

Community
  • 1
  • 1
Diego
  • 215
  • 1
  • 7
  • 14