Reputation: 569
I've created a custom auth provider. Is there a way to get the entity manager in the auth provider or listener?
I know you can get it in the UserProvider, but the fact is that I want to only flush the user when credentials are right (I authenticate against a windows server Active Directory)
Upvotes: 0
Views: 526
Reputation: 2379
Yes, you can inject entity manager in service definition, for examle:
services:
wsse.security.authentication.provider:
class: Acme\DemoBundle\Security\Authentication\Provider\WsseProvider
arguments: ["", "%kernel.cache_dir%/security/nonces", "@doctrine.orm.entity_manager"]
And then adjust __construct
method inside WsseProvider:
private $em;
public function __construct(UserProviderInterface $userProvider, $cacheDir, EntityManager $em)
{
$this->userProvider = $userProvider;
$this->cacheDir = $cacheDir;
$this->em = $em;
}
Upvotes: 1