-1

This is my security.yml file

firewalls:
    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
            login_path: project_frontend_main_index
        logout: 
            path: project_frontend_main_logout
            anonymous: true

access_control: 
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } 
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } 
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } 
    - { path: ^/admin/, role: ROLE_ADMIN } 
    - { path: ^/alerts*, role: ROLE_USER }

My question is The problem is with logout, I can't access logout function in the Main controller. I get this error when i click "logout" You must activate the logout in your security firewall configuration.

Brewal
  • 8,067
  • 2
  • 24
  • 37
sasser
  • 3
  • 4
  • Please, add details and ask a question. – Brewal May 18 '15 at 12:09
  • My question is why I can not access the logout action on the Main controller – sasser May 18 '15 at 12:20
  • Can you provide your access_control parameters (should be at the bottom of this file) ? – Brewal May 18 '15 at 12:21
  • access_control: - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/admin/, role: ROLE_ADMIN } - { path: ^/alerts*, role: ROLE_USER } – sasser May 18 '15 at 12:24

2 Answers2

0

Remove anonymous : true, or atleast make it false. This will solve your issue.

user3227262
  • 563
  • 1
  • 6
  • 16
  • I try that, still not working. I get the same error "You must activate the logout in your security firewall configuration." – sasser May 18 '15 at 12:16
0

Try to add this on the top of your access_control :

- { path: ^/logout$, role: IS_AUTHENTICATED_ANONYMOUSLY } 

Also, you have to add the target for the logout (where the user will be redirected :

logout: 
    path: project_frontend_main_logout
    target: / #or a specific public route

If none of this works, use the default configuration for a sonata project that can be found here :

security:
    providers:
        fos_userbundle:
            id: fos_user.user_manager

    firewalls:
        main:
            pattern:      .*
            form-login:
                provider:       fos_userbundle
                login_path:     /login
                use_forward:    false
                check_path:     /login_check
                failure_path:   null
            logout:       true
            anonymous:    true
Brewal
  • 8,067
  • 2
  • 24
  • 37
  • Thank you for the answer, but I still get the error "You must activate the logout in your security firewall configuration." – sasser May 18 '15 at 12:32
  • Ok, try adding the `target` for the logout then (see my edit) – Brewal May 18 '15 at 12:34
  • I try adding "target" but still getting the same error – sasser May 18 '15 at 12:37
  • Ok, maybe you could use the default configuration ? – Brewal May 18 '15 at 12:38
  • Yes it works if I use the default configuration, but I want when a user click"log out" to get that action and update their online status on the database, so I need to call the specific function something like this logoutAction()(..update set online =0 "} – sasser May 18 '15 at 12:42
  • That is what I meant by "ask a question". You should have ask this in the first place. Anyway, you can find a way to [do this with logout handlers](http://stackoverflow.com/questions/21835509/redirect-symfony2-logoutsuccesshandler-to-original-logout-target) – Brewal May 18 '15 at 12:54