質問

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)

役に立ちましたか?

解決

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;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top