Symfony 2 - firewall and access control issue

I have a wired problem with the symfony 2 security component. Because the {{ app.user }} object is only available in a protected area, I installed the ^/ firewall template. Now I want to โ€œunprotectedโ€ some pages, such as registration. I tried this using access_control but it does not work.

Here is my security.yml

 firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false login: pattern: ^/account/login$ security: false account_area: pattern: ^/ form_login: check_path: /account/login_check login_path: /account/login default_target_path: /account remember_me: key: blaBlubKey lifetime: 3600 path: / domain: ~ logout: path: /account/logout target: / access_control: #works - { path: ^/backend, roles: ROLE_USER } #works not - { path: ^/registration, roles: IS_AUTHENTICATED_ANONYMOUSLY } 

Thanks in advance!

+4
source share
2 answers

Use any directive in account_area:

 account_area: pattern: ^/ anonymous: ~ 
+4
source

It should be noted that it is best to use only one firewall with access_control for the login page. What for? What would you do if a registered user tries to access the / login page? You cannot verify the controller if it has been authenticated and redirected, because the user will be authenticated on your main firewall, but not on the login firewall, as these are separate security systems.

Here is security.yml that works fine for me:

 security: firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: true anonymous: ~ secured_area: pattern: ^/ anonymous: ~ form_login: login_path: /login check_path: /login_check always_use_default_target_path: true default_target_path: / logout: path: /logout target: / providers: main: entity: { class: Core\UserBundle\Entity\User, property: username } access_control: - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/admin, roles: ROLE_SUPERADMIN } - { path: ^/user, roles: ROLE_USER } - { path: ^/, roles: IS_AUTHENTICATED_FULLY } 
+10
source

Source: https://habr.com/ru/post/1400762/


All Articles