I have security set like thisy in security.yaml in my test project, and I want visitor of project to be logged only if acesses admin.localhost page.
firewalls:
secured_area:
host: ^admin\.localhost$
security: true
secured_area_two:
pattern: ^/user/list
security: true
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
lazy: true
provider: app_user_provider
form_login:
login_path: login
check_path: login
enable_csrf: true
My Answer:
To set "admin.localhost" as a secured area in Symfony 6 using security.yaml, you can modify your configuration as follows:
yaml
firewalls:
secured_area:
host: ^admin\.localhost$
security: true
provider: app_user_provider
secured_area_two:
pattern: ^/user/list
security: true
provider: app_user_provider
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
lazy: true
provider: app_user_provider
form_login:
login_path: login
check_path: login
enable_csrf: true
In this configuration, the "secured_area" firewall is set to only allow access to requests with the host "admin.localhost". The "secured_area_two" firewall is set to only allow access to requests matching the pattern "^/user/list". Both firewalls are configured to use the "app_user_provider" as the provider for user authentication.
Make sure to adjust the provider and other settings according to your specific requirements.
Rate this post
3 of 5 based on 4156 votesComments