用于登录Symfony 4的多个提供程序和防火墙

时间:2019-03-24 14:06:51

标签: symfony

我有一个Symfony 4网站,其中包含用户和登录过程。我想添加一个新的实体“客户”,并允许客户使用与用户相同的过程登录。

当我尝试编辑 security.yaml 文件时,出现此错误:未明确配置“主”防火墙上的“后卫”侦听器的提供程序,因为存在多家注册提供商。

我的编码器被声明为:

encoders:
        App\Entity\User:
            algorithm: bcrypt
        App\Entity\Client:
            algorithm: bcrypt

我的提供者: 提供者:

app_user_provider:
    entity:
        class: App\Entity\User
        property: email
        manager_name: user
app_customer_provider:
    entity:
        class: App\Entity\Customer
        property: email
        manager_name: customer

还有主防火墙:

main:
            logout:
                path: app_logout
            anonymous: true
            guard:
                authenticators:
                    - App\Security\LoginFormAuthenticator

我尝试了其他方法来声明新的防火墙,但是它不起作用。是否可以对两个提供程序使用相同的安全性过程?我想念什么吗?

谢谢

1 个答案:

答案 0 :(得分:3)

您应该将提供程序添加到防火墙中,因为您有多个提供程序symfony不知道您要使用哪个提供程序,因此请尝试像这样配置防火墙

 main:
  logout:
      path: app_logout
  anonymous: true
  provider: app_user_provider
  guard:
     authenticators:
           - App\Security\LoginFormAuthenticator

不要忘记缓存:清除 您可以在他们的文档here

中找到它
相关问题