【问题标题】:Symfony 3.4 - new security providerSymfony 3.4 - 新的安全提供者
【发布时间】:2018-06-19 03:25:51
【问题描述】:

我尝试添加提供商。我做错了什么。

我有实体类,我想扩展这个类

namespace AppBundle\Service;

use AppBundle\Entity\Pracownik;
use Symfony\Component\Security\Core\User\UserInterface;


class Userek extends Pracownik implements UserInterface
{
    public function getUsername()
    {
        return $this->getLogin();
    }

    public function getSalt()
    {
        // you *may* need a real salt depending on your encoder
        // see section on salt below
        return null;
    }

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

    public function getRoles()
    {
        return array('ROLE_PRACOWNIK');
    }

    public function eraseCredentials()
    {
    }

    public function isSuperAdmin()
    {
        return false;
    }

}

在 security.yml 我添加

encoders:
        AppBundle\Service\Userek: plaintext
providers:
    pracownik_db_provider:
        entity:
            class: AppBundle\Service\Userek
            property: login
firewalls:
     main:
          pattern: ^/
          form_login:
              provider: pracownik_db_provider
              login_path: /login
              check_path: /login_check
          logout:
              path: /logout
              target: /login

当我尝试登录时,我收到消息:

The class 'AppBundle\Service\Userek' was not found in the chain configured namespaces AppBundle\Entity, FOS\UserBundle\Model"

如果我从实现的类中添加方法而不创建扩展 Pracownik 类的额外新类 - 工作

【问题讨论】:

标签: symfony security


【解决方案1】:

尝试将您的Userek 类移动到AppBundle\Entity\ 文件夹,因为Doctrine 期望在该文件夹Entity\ 上找到模型类。

只需将AppBundle\Service\Userek.php 移至AppBundle\Entity\Userek.php,如果仍然收到错误消息,请返回。

如果您希望 Doctrine 使用另一个文件夹来存储您的模型类或实体,您可以在 here 或完整文档 Doctrine configurations 上找到一些帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-25
    • 2016-03-16
    • 1970-01-01
    • 2013-04-15
    • 1970-01-01
    • 2012-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多