伙计们我是Symfony 4的新手,
这是我的security.yaml,我的目的是从数据库登录加载用户
security:
encoders:
App\Entity\Login:
algorithm: bcrypt
providers:
db_provider:
entity:
class: App\Entity\Login
property: username
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
provider: db_provider
anonymous: ~
form_login:
login_path: login
check_path: login
default_target_path: postlogin
这是我的实体
class Login
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $username;
/**
* @ORM\Column(type="string", length=255)
*/
private $email;
/**
* @ORM\Column(type="string", length=255)
*/
private $password;
public function getId()
{
return $this->id;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
}
这是完整的错误
Symfony \ Component \ Security \ Core \ Exception \ AuthenticationServiceException:用户提供程序必须返回UserInterface对象。在C:\ xampp \ htdocs \ Auth \ vendor \ symfony \ security \ Core \ Authentication \ Provider \ DaoAuthenticationProvider.php:85堆栈跟踪:#0 C:\ xampp \ htdocs \ Auth \ vendor \ symfony \ http-foundation \ Session \ Storage \ NativeSessionStorage.php(142):session_start()#1 C:\ xampp \ htdocs \ Auth \ vendor \ symfony \ http-foundation \ Session \ Storage \ NativeSessionStorage.php(299):Symfony \ Component \ HttpFoundation \ Session \ Storage \ NativeSessionStorage-> start()#2 C:\ xampp \ htdocs \ Auth \ vendor \ symfony \ http-foundation \ Session \ Session.php(249):Symfony \ Component \ HttpFoundation \ Session \ Storage \ NativeSessionStorage- > getBag('attributes')#3 C:\ xampp \ htdocs \ Auth \ vendor \ symfony \ http-foundation \ Session \ Session.php(271):Symfony \ Component \ HttpFoundation \ Session \ Session-> getBag( 'attributes')#4 C:\ xampp \ htdocs \ Auth \ vendor \ symfony \ http-foundation \ Session \ Session.php(73):Symfony \ Component \ HttpFoundation \ Session \ Session-> getAttributeBag()#5 C :\ xampp \ htdocs \ Auth \ vendor \ symfony \ security \ Http \ Firewall \ ContextListener.php(88):Symfon y \ Component \ HttpFoundation \ Session \ Session-> get('_ security_main')#6 C:\ xampp \ htdocs \ Auth \ vendor \ symfony \ security-bundle \ Debug \ WrappedListener.php(46):Symfony \ Component \ Security \ Http \ Firewall \ ContextListener-> handle(对象(Symfony \ Component \ HttpKernel \ Event \ GetResponseEvent))#7 C:\ xampp \ htdocs \ Auth \ vendor \ symfony \ security-bundle \ Debug \ TraceableFirewallListener.php( 35):Symfony \ Bundle \ SecurityBundle \ Debug \ WrappedListener-> handle(对象(Symfony \ Component \ HttpKernel \ Event \ GetResponseEvent))#8 C:\ xampp \ htdocs \ Auth \ vendor \ symfony \ security \ Http \ Firewall .php(56):Symfony \ Bundle \ SecurityBundle \ Debug \ TraceableFirewallListener-> handleRequest(Object(Symfony \ Component \ HttpKernel \ Event \ GetResponseEvent),Object(Symfony \ Component \ DependencyInjection \ Argument \ RewindableGenerator))#9 C: \ xampp \ htdocs \ Auth \ vendor \ symfony \ security-bundle \ EventListener \ FirewallListener.php(48):Symfony \ Component \ Security \ Http \ Firewall-> onKernelRequest(Object(Symfony \ Component \ HttpKernel \ Event \ GetRespons) eEvent))#10 [内部函数]:Symfony \ Bundle \ SecurityBundle \ EventListener \ FirewallListener-> onKernelRequest(Object(Symfony \ Component \ HttpKernel \ Event \ GetResponseEvent),'kernel.request',Object(Symfony \ Component \ HttpKernel \ Debug \ TraceableEventDispatcher))#11 C:\ xampp \ htdocs \ Auth \ vendor \ symfony \ event-dispatcher \ Debug \ WrappedListener.php(104):call_user_func(Array,Object(Symfony \ Component \ HttpKernel \ Event \ GetResponseEvent) ,'kernel.request',Object(Symfony \ Component \ HttpKernel \ Debug \ TraceableEventDispatcher))#12 C:\ xampp \ htdocs \ Auth \ vendor \ symfony \ event-dispatcher \ EventDispatcher.php(212):Symfony \ Component \ EventDispatcher \ Debug \ WrappedListener-> __ invoke(Object(Symfony \ Component \ HttpKernel \ Event \ GetResponseEvent),'kernel.request',Object(Symfony \ Component \ EventDispatcher \ EventDispatcher))#13 C:\ xampp \ htdocs \ Auth \ vendor \ symfony \ event-dispatcher \ EventDispatcher.php(44):Symfony \ Component \ EventDispatcher \ EventDispatcher-> doDispatch(Array,'kernel.request',Object(Symfony \ C) omponent \ HttpKernel \ Event \ GetResponseEvent))#14 C:\ xampp \ htdocs \ Auth \ vendor \ symfony \ event-dispatcher \ Debug \ TraceableEventDispatcher.php(139):Symfony \ Component \ EventDispatcher \ EventDispatcher-> dispatch(' kernel.request',Object(Symfony \ Component \ HttpKernel \ Event \ GetResponseEvent))#15 C:\ xampp \ htdocs \ Auth \ vendor \ symfony \ http-kernel \ HttpKernel.php(125):Symfony \ Component \ EventDispatcher \ Debug \ TraceableEventDispatcher-> dispatch('kernel.request',Object(Symfony \ Component \ HttpKernel \ Event \ GetResponseEvent))#16 C:\ xampp \ htdocs \ Auth \ vendor \ symfony \ http-kernel \ HttpKernel.php( 66):Symfony \ Component \ HttpKernel \ HttpKernel-> handleRaw(Object(Symfony \ Component \ HttpFoundation \ Request),1)#17 C:\ xampp \ htdocs \ Auth \ vendor \ symfony \ http-kernel \ Kernel.php (190):Symfony \ Component \ HttpKernel \ HttpKernel-> handle(Object(Symfony \ Component \ HttpFoundation \ Request),1,true)#18 C:\ xampp \ htdocs \ Auth \ public \ index.php(37) :Symfony \ Component \ HttpKernel \ Kernel-> handle(Object(Symfony \ Component \ HttpFoun) dation \ Request))#19 {main}
答案 0 :(得分:3)
您的“登录”实体必须实现UserInterface或AdvancedUserInterface
像:
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
class User implements AdvancedUserInterface, \Serializable
{
....
}