Mongodb Symfony3+&引用;由于系统原因,无法处理身份验证请求;

Mongodb Symfony3+&引用;由于系统原因,无法处理身份验证请求;,mongodb,symfony,security,Mongodb,Symfony,Security,我将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\Acc

我将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]第0行,第44列靠近“username=:username”:错误:“username”未定义。“
然后我必须添加security.yml此
**”属性: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

日志文件对错误有何说明?身份验证请求失败。{“异常”:“[对象](Symfony\\Component\\Security\\Core\\exception\\AuthenticationServiceException(代码:0):身份验证失败。at/data/bas/site/vendor/Symfony/Symfony/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php:94,MongoConnectionException(代码:11):身份验证失败。at/data/bas/site/vendor/alcaeus/mongophp适配器/lib/alcaeus/MongoDbAdapter/ExceptionConverter.php:83,MongoDB\\Driver\\Exception\\AuthenticationException(代码:11):身份验证失败。at/data/bas/site/vendor/MongoDB/MongoDB/src/Operation/Find.php:219)}终于找到了解决方案!当您的连接具有用户名/密码时,您必须设置“authSource”参数@请在哪里设置“authSource”?