我遇到一个问题,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"
}
任何帮助都将不胜感激。。。
此外,防火墙:
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
不是最好的解决方案,但我的解决方案是为用户存储库创建一个服务,并在用户提供程序中使用它。。。
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
如果有人真的能解决这个问题,我很乐意接受这个答案:)
真正的解决方案
实际问题是我实现了UserProviderInterface
而不是UserLoaderInterface
。此外,不能在security.yml
中设置属性。