在symfony 4中,当我尝试登录时,页面返回此错误:
“由于系统问题,无法处理身份验证请求”
在我的var / log / dev.log中,详细的错误是:
[2018-09-02 23:18:23] security.INFO: Authentication request failed. {"exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\AuthenticationServiceException(code: 0): Class 'App\\Entity\\User' does not exist at /home/www/xxx/yyy/symfoproject/vendor/symfony/security/Core/Authentication/Provider/DaoAuthenticationProvider.php:85, Doctrine\\Common\\Persistence\\Mapping\\MappingException(code: 0): Class 'App/Entity/User' does not exist at /home/www/xxx/yyy/symfoproject/vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/Mapping/MappingException.php:93)"} []
我不明白,因为存在App / Entity / User类,并且使用它通过./bin/console生成数据库架构。
我的security.yaml代码:(在symfoproject / config / packages / security.yaml中)
security:
# https://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
encoders:
App\Entity\User:
algorithm: bcrypt
providers:
my_db_provider:
entity:
class: App\Entity\User
property: email
firewalls:
#dev:
# pattern: ^/(_(profiler|wdt)|css|images|js)/
# security: false
main:
provider: my_db_provider
anonymous: ~
form_login:
login_path: home
check_path: home
logout:
path: /logout
target: /
# activate different ways to authenticate
# http_basic: ~
# https://symfony.com/doc/current/book/security.html#a-configuring-how-your-users-will-authenticate
# form_login: ~
# https://symfony.com/doc/current/cookbook/security/form_login_setup.html
role_hierarchy:
ROLE_SUPER_ADMIN: [ROLE_USER]
我的用户实体代码(在symfoproject / src / Entity / UserEntity.php中)
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
*/
class User implements \Serializable, UserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=100, unique=true)
*/
private $email;
/**
* @ORM\Column(type="string", length=64, nullable=true)
*/
private $token_activation;
/**
* @var bool
* @ORM\Column(name="is_active", type="boolean")
*/
private $isActive;
/**
* @ORM\Column(type="string", length=64)
*/
private $password;
/**
* @Assert\NotBlank()
* @Assert\Length(max=4096)
*/
private $plainPassword;
/**
* @var array
* @ORM\Column(name="roles", type="array")
*/
protected $roles;
/**
* @var int
* @ORM\Column(type="smallint", options={"default":0})
*/
private $initial_roll;
public function __construct(string $email, array $roles = array(), bool $isActive = FALSE, string $password = "coucou", int $initial_roll = 0) {
$this->email =$email;
$brypt = new BCryptPasswordEncoder(4);
$this->password = $brypt->encodePassword($password, $this->getSalt());
$this->roles = $roles;
$this->isActive = $isActive;
$this->initial_roll = $initial_roll;
}
public function serialize() {
return serialize(array(
$this->id,
$this->email,
$this->password,
));
}
public function unserialize($serialized) {
list (
$this->id,
$this->email,
$this->password,
) = unserialize($serialized);
}
public function getRoles() {
return $this->roles;
}
public function getPassword() {
return $this->password;
}
public function getSalt() {
return NULL;
}
public function getUsername() {
return $this->email;
}
public function eraseCredentials() {
$this->plainPassword = NULL;
}
/**
* @return mixed
*/
public function getId() {
return $this->id;
}
/**
* @return mixed
*/
public function getEmail() {
return $this->email;
}
/**
* @param mixed $email
*/
public function setEmail($email): void {
$this->email = $email;
}
/**
* @return mixed
*/
public function getTokenActivation() {
return $this->token_activation;
}
/**
* @param mixed $token_activation
*/
public function setTokenActivation($token_activation): void {
$this->token_activation = $token_activation;
}
/**
* @return bool
*/
public function isActive(): bool {
return $this->isActive;
}
/**
* @param bool $isActive
*/
public function setIsActive(bool $isActive): void {
$this->isActive = $isActive;
}
/**
* @return mixed
*/
public function getPlainPassword() {
return $this->plainPassword;
}
/**
* @param mixed $plainPassword
*/
public function setPlainPassword($plainPassword): void {
$this->plainPassword = $plainPassword;
}
public function toArray() {
return array(
"id"=>$this->getId(),
"mail"=>$this->getEmail(),
"role(s)" => $this->getRoles(),
"actif?" => $this->isActive(),
);
}
/**
* @return int
*/
public function getInitialRoll(): int {
return $this->initial_roll;
}
/**
* @param int $initial_roll
*/
public function setInitialRoll(int $initial_roll): void {
$this->initial_roll = $initial_roll;
}
}
我不知道我的秘密在哪里。有人可以帮助我吗?