0
我有一个问题,Symfony不会在安全组件中获取相应的EntityRepository。Symfony安全加载错误的实体存储库
的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
你能解释你的实际问题吗? DoctrineBridge中的'EntityUserProvider'类将在您的用户实体内部使用您的自定义实体存储库。所以你在你的控制器中做的测试并不是真正有意义的。 – xabbuh
嗨!是的,这是问题,它没有。我有一个永远不会被调用的自定义loadUserByUsername .... – Richard87
其实,你是对的,问题是我的仓库实现'UserProviderInterface'而不是'UserLoaderInterface' – Richard87