The firewall configuration is as follows:
firewalls:
login_firewall:
pattern: ^/login$
anonymous: ~
secured_area:
pattern: ^/
login_form: ~
After logging in, except for the /login page, other pages can obtain the current user information through $this->getUser()
,
How can I get the current user information on the /login page?
I solved the problem based on the answer. Here is my security.yml content:
security:
role_hierarchy:
ROLE_ADMIN: ROLE_USER
firewalls:
# login_firewall:
# pattern: ^/login$
# anonymous: ~
secured_area:
pattern: ^/
anonymous: ~
form_login:
login_path: login
check_path: login_check
logout:
path: /logout
target: /
access_control:
- { path: ^/login$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, roles: ROLE_USER }
providers:
in_memory:
memory:
users:
kevin: { password: kevinpass, roles: 'ROLE_USER' }
admin: { password: adminpass, roles: 'ROLE_ADMIN' }
encoders:
Symfony\Component\Security\Core\User\User: plaintext
At the same time, I also found a similar question on SO - link
Thanks for the answer friends!
You can delete the login firewall and configure it in acl: