Symfony2 security: Multiple providers Symfony2 security: Multiple providers symfony symfony

Symfony2 security: Multiple providers


Old question but for anyone looking for a solution, the manual explains it all here.Basically, you need to chain your providers like this:

# app/config/security.ymlsecurity:    providers:        chain_provider:            chain:                providers: [korea, galvez]        korea:            entity: { class: Korea\AlmacenBundle\Entity\Usuario, property: username }        galvez:            entity: { class: Galvez\RepuestosBundle\Entity\Usuario, property: username }


This is probably an issue with namespaces of your classes. Check if class Galvez\RepuestosBundle\Entity\Usuario is in the right namespace and if configuration is correct - maybe you accidentally left some copy-and-paste code from the other entity.

Try to persist both of these entities and fetch them (without security context) - I think you'll find your issue there.


I made a test with both entities:

abcController.php

$em= $this->get('doctrine')->getManager('galvez');$usuario_g = $this->get('doctrine')->getRepository('RepuestosBundle:Usuario', 'galvez')->find(1);$usuario_g->setUsername('asdasd');$em->persist($usuario_g);$em->flush();

Works fine, but if i use

$em = $this->getDoctrine()->getEntityManager();

instead of

$em = $this->get('doctrine')->getManager('galvez');

When i try to flush, Symfony launchs the same error:

The class 'Galvez\RepuestosBundle\Entity\Usuario' was not found in the chain configured namespaces Korea\AlmacenBundle\Entity

Usuario.php (AlmacenBundle)

<?phpnamespace Korea\AlmacenBundle\Entity;use Symfony\Component\Security\Core\User\UserInterface;use Doctrine\ORM\Mapping as ORM;/** * Usuario * * @ORM\Table() * @ORM\Entity(repositoryClass="Korea\AlmacenBundle\Entity\UsuarioRepository") */class Usuario implements UserInterface{/** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */private $id;/** * @var string * * @ORM\Column(name="username", type="string", length=255) */private $username;/** * @var string * * @ORM\Column(name="password", type="string", length=255) */private $password;/** * @var string * * @ORM\Column(name="salt", type="string", length=255) */private $salt;

Usuario.php (RepuestosBundle)

<?phpnamespace Galvez\RepuestosBundle\Entity;use Symfony\Component\Security\Core\User\UserInterface;use Doctrine\ORM\Mapping as ORM;/*** Usuario** @ORM\Table()* @ORM\Entity(repositoryClass="Galvez\RepuestosBundle\Entity\UsuarioRepository")*/class Usuario implements UserInterface{/** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */private $id;/** * @var string * * @ORM\Column(name="username", type="string", length=255) */private $username;/** * @var string * * @ORM\Column(name="password", type="string", length=255) */private $password;/** * @var string * * @ORM\Column(name="salt", type="string", length=255) */private $salt;

PD: Well, i think it's not possible, if i change this:

default_connection: korea

to:

default_connection: galvez

Symfony says:

MappingException: The class 'Korea\AlmacenBundle\Entity\Usuario' was not found in the chain configured namespaces Galvez\RepuestosBundle\Entity

the same error, but in reverse..

It seems like the monolog validation take the default connection (korea in this case) for search and validate