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