Symfony 2: get current user login on insecure pages through a firewall

How to get the current registered user on unprotected pages?

I only have / account / page that is protected through the firewall and other pages are insecure.

My global navigation has the following template (simplified):

{% if app.user %} <a href="/account/data">... <a href="/logout>... {% else %} <a href="/account/login">.... {% endif %} 

Problem. Navigation with an exit link should also be available on an insecure page, but there is no UsernamePasswordToken ... and symfony displays a login link, not the / logout and / account / data links. I configured all the other pages with an anonymous listener, but it does not work properly.

is there a solution for it?

+4
source share
1 answer

You cannot get a user on a page without a firewall. Turn on the firewall for the entire application, enable anonymous access, and protect specific parts of the application with access_control :

 security: firewalls: main: pattern: ^/ anonymous: ~ access_control: - { path: ^/protected, roles: ROLE_SOME } 
+8
source

All Articles