我的问题是我想使用 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}
问题:
- 安全代码部分写得好吗?有东西吗?
- 我必须在实体中添加一些东西吗?