我是 symfony 4.4 的新手,我正在努力处理 security.yaml 文件中的角色,我有 3 种类型的用户:Admin、recruter 和 user,我试图让 recruter 访问登录表单 security_login_recruteur,同时我希望用户可以访问他的登录表单 security_login
这是我的security.yaml文件
security:
encoders:
App\Entity\User:
algorithm: bcrypt
App\Entity\Recruteur:
algorithm: bcrypt
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
users_in_memory: { memory: null }
in_database:
entity:
class: App\Entity\User # here i'm trying to mention both of the entities
App\Entity\Recruteur
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: lazy
provider: in_database
form_login:
login_path: security_login |security_login_recruteur #here i'm tring to put both of the paths
check_path: security_login | security_login_recruteur
logout:
path: security_logout | security_logout_recruteur #also in the logout path
target: home
# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#firewalls-authentication
# https://symfony.com/doc/current/security/impersonating_user.html
# switch_user: true
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
- {path: ^/recruteur, roles: ROLE_RECRUTEUR }
#- { path: ^/admin, roles: ROLE_ADMIN }
我在尝试访问 /recruteur/connexion 后遇到此错误
<块引用>无法为命名路由“security_login”生成 URL |security_login_recruteur",因为这样的路由不存在。
有人可以帮我吗?
答案 0 :(得分:-1)
对于您的业务案例,您必须创建多个防火墙,每个“用户”(也是多个提供商)一个。
security:
firewalls:
...
main:
form_login:
login_path: security_login
...
provider: user_provider #example
lazy: true
recruter:
form_login:
login_path: security_login_recruteur
...
provider: recruter_provider #example
lazy: true
... # add firewall for "Admin" for example