0

我的问题是我想使用 2 种不同的用户类型“Familia”和“Doctor”我以这种方式配置 security.yml:

providers: 




    client_db:
        entity: 
          class: Goodday\PreditBundle\Entity\Familia
          property: email

    manager_db:
        entity: 
          class: Goodday\PreditBundle\Entity\Doctor
          property: email

问题是我可以使用 Familia 登录,但如果我尝试使用医生登录,它会返回“Bad Credentials”。两个实体都有

 class Doctor implements UserInterface
 {
 public function getRoles()
{
    return array('ROLE_DOC');
}

public function getSalt()

{
    return false;
}

public function getUsername()
{
    return $this->email;
}

public function eraseCredentials()
{

}

public function equals(UserInterface $user)
{
    return $user->getUsername() == $this->getUsername();
}

这是我的安全文件。

security:
encoders:
    Symfony\Component\Security\Core\User\User: sha512

    Goodday\PreditBundle\Entity\Familia: 
      algorithm: plaintext

    Goodday\PreditBundle\Entity\Doctor:
      algorithm: plaintext




providers: 
  chain_provider:
    chain:
      providers: [user_db, admin_db]



      user_db:
        entity: 
          class: Goodday\PreditBundle\Entity\Familia
          property: email

      admin_db:
        entity: 
          class: Goodday\PreditBundle\Entity\Doctor
          property: email

firewalls:

    secured_area:
        pattern:    ^/
        anonymous: ~
        form_login:
            check_path: /check
            login_path: /login
            always_use_default_target_path: false
            default_target_path:            /checking

            use_referer:                    false
        logout:
            path:   /logout
            target: /
        #anonymous: ~
        #http_basic:
        #    realm: "Secured Demo Area"

access_control:
    - { path: ^/familia, roles: ROLE_FAM }
    - { path: ^/doctor, roles: ROLE_DOC}

问题:

  • 安全代码部分写得好吗?有东西吗?
  • 我必须在实体中添加一些东西吗?
4

1 回答 1

0

您要做的是将您的提供者链接如下:

# app/config/security.yml
security:
    providers:
        chain_provider:
            chain:
                providers: [client_db, manager_db]
        client_db:
            entity: 
                class: Goodday\PreditBundle\Entity\Familia
                property: email

        manager_db:
            entity: 
                class: Goodday\PreditBundle\Entity\Doctor
                property: email

这将首先尝试使用客户端提供程序登录过程,然后使用管理器提供程序,如果两者都失败,它将告诉您某种“错误凭据”错误。

于 2013-08-07T07:40:45.107 回答