Symfony安全性加载错误的实体存储库

时间:2016-01-04 10:55:20

标签: php symfony doctrine-orm

我遇到的问题是Symfony在安全组件中获取了相关的EntityRepository。

Symfony返回Symfony\Bridge\Doctrine\Security\User\EntityUserProvider而不是AppBundle\Repository\UserRepository ...

我的配置如下:

providers:
    database_users:
        entity: { class: AppBundle:User, property: mobile }
    our_db_provider:
        entity:
            class: AppBundle:User

为了测试它,我运行了这段代码:

public function testAction(Request $request)
{
    $repo1 = $this->getDoctrine()->getRepository("AppBundle:User");

    $userProvider = $this->get("security.user.provider.concrete.our_db_provider");


    $data = [
        'Hello' => 'world',
        'doctrine' => get_class($repo1),
        'security' => get_class($userProvider),
    ];

    return new JsonResponse($data);
}

返回此内容:

{
"Hello": "world",
"doctrine": "AppBundle\\Repository\\UserRepository",
"security": "Symfony\\Bridge\\Doctrine\\Security\\User\\EntityUserProvider"
}

非常感谢任何帮助......

另外,firwalls:

firewalls:
    # disables authentication for assets and the profiler, adapt it according to your needs
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    main:
        anonymous: ~

        logout:
            path:   logout
            invalidate_session: false

        guard:
            provider: our_db_provider
            authenticators: [app.form_login_authenticator]
            entry_point: app.form_login_authenticator

1 个答案:

答案 0 :(得分:0)

不是最好的解决方案,但我的目的是为User存储库创建服务,并在用户提供程序中使用它...

   app.user_repository:
     class: AppBundle\Repository\UserRepository
     factory: ["@doctrine.orm.default_entity_manager", getRepository]
     arguments:
       - AppBundle:User

我的新用户提供商:

providers:
    our_db_provider:
        id: app.user_repository

如果有人能够真正解决问题,我很乐意接受这个答案:)

真正的解决方案

Actuall问题是我实施了UserProviderInterface而不是UserLoaderInterface。此外,属性也不得在security.yml中设置。