gpt4 book ai didi

mongodb - Symfony3 + "Authentication request could not be processed due to a system"

转载 作者:可可西里 更新时间:2023-11-01 10:49:14 27 4
gpt4 key购买 nike

我将 Symfony3 与 MongoDB ODM 结合使用。当我尝试登录时,出现以下消息:“由于系统问题,无法处理身份验证请求。”

这是 security.yml 文件:

# To get started with security, check out the documentation:
# http://symfony.com/doc/current/security.html
security:
encoders:
PlannerBundle\Document\Account: sha512

# http://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
providers:
account_provider:
mongodb: { class: PlannerBundle\Document\Account, property: username }
in_memory:
memory: ~

role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_COMMERCIAL: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN]

firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false

admin:
pattern: ^/admin
form_login:
provider: account_provider
check_path: login
login_path: login
default_target_path: sonata_admin_dashboard

logout:
path: logout
target: /admin/login

anonymous: true
logout: true

access_control:
- { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin, roles: [ROLE_ADMIN, ROLE_COMMERCIAL] }

实体文件:

<?php
// src/PlannerBundle/Document/Account.php
namespace PlannerBundle\Document;

use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

/**
* @MongoDB\Document(collection="users", repositoryClass="PlannerBundle\Repository\AccountRepository")
*/
class Account implements UserInterface, \Serializable
{
/**
* @MongoDB\Id(strategy="UUID", type="string")
*/
protected $id;

/**
* @MongoDB\Field(type="string")
* @MongoDB\Index(unique=true)
*/
private $username;

/**
* @MongoDB\Field(type="string")
*/
private $password;

/**
* @MongoDB\Field(type="string")
* @MongoDB\Index(unique=true)
*/
private $email;

/**
* @MongoDB\Field(type="collection")
*/
private $roles;

/**
* @MongoDB\Field(type="boolean")
*/
private $isActive;

public function __construct()
{
$this->isActive = true;
}

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

public function getSalt()
{
return null;
}

public function getPassword()
{
return $this->password;
}

public function getRoles()
{
return $this->roles;
}

public function eraseCredentials()
{
}

/** @see \Serializable::serialize() */
public function serialize()
{
return serialize(array(
$this->id,
$this->username,
$this->password
));
}

/** @see \Serializable::unserialize() */
public function unserialize($serialized)
{
list (
$this->id,
$this->username,
$this->password,
) = unserialize($serialized);
}

/**
* Get id
*
* @return string $id
*/
public function getId()
{
return $this->id;
}



}

你知道为什么吗?

谢谢你的帮助!

最佳答案

此错误消息过于笼统,您需要查看/logs/dev.log 以找到您的具体问题。搜索错误文本,例如在我的情况下它显示 "[Semantical Error] line 0, col 44 near 'username = :username': Error: 'username' is not defined." 然后我不得不在 security.yml 中添加这个 **"property: username"** 下面这个例子的最后一行:

# To get started with security, check out the documentation:
# https://symfony.com/doc/current/security.html
security:
encoders:
AppBundle\Entity\User:
algorithm: bcrypt

# https://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
providers:
db_provider:
entity:
class: AppBundle:User
property: username

关于mongodb - Symfony3 + "Authentication request could not be processed due to a system",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44725499/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com