I developing own User Provider. For retrieving User I have injected my UserRepository:
app_bundle.api_key_user_provider:
class: AppBundle\Security\User\ApiKeyUserProvider
factory: ["@doctrine.orm.entity_manager", "getRepository"]
arguments:
- AppBundle\Entity\User
I also added EntityManager into __construct()
method of my provider:
class ApiKeyUserProvider implements UserProviderInterface
{
public function __construct(EntityManager $em)
{
$this->em = $em;
}
public function loadUserByUsername($email)
{
$user = $this->em->findBy(array('email' => $email));
if (!$user) {
throw new UsernameNotFoundException('User not found!');
}
$this->user = $user;
return $user;
}
public function refreshUser(UserInterface $user)
{
return $user;
}
public function supportsClass($class)
{
return $class === 'AppBundle\Entity\User';
}
}
But when Provider is called, I got next error:
Catchable Fatal Error: Argument 1 passed to Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider::__construct() must implement interface Symfony\Component\Security\Core\User\UserProviderInterface, instance of AppBundle\Repository\UserRepository given
I have tried to inject Symfony\Component\Security\Core\User\UserProviderInterface
, but have no success. I pass as argument to services.yml
provider definition next strings:
- Symfony\Component\Security\Core\User\UserProviderInterface (got error "class not exists")
- Vendor\Symfony\Component\Security\Core\User\UserProviderInterface (got same error)
Also I've searched for needed service in SecurityBundle, but found nothing.
My question: How can I inject Symfony\Component\Security\Core\User\UserProviderInterface
to my ApiKeyUserProvider
or what else I can do to solve this problem?
Thanks a lot for help!
ApiKeyUserProvider
is my own UserProvider. I want to injectUserRepository
into it instead of injecting entire entity manager. I think it's possible. So I try to find the way to do it. – Sergio Ivanuzzo