title: Symfony2 security: Multiple providers
body: <p>I have 2 bundles in my project: </p>
  
  <ul>
  <li>src/Korea/AlmacenBundle </li>
  <li>src/Galvez/RepuestosBundle</li>
  </ul>
  
  <p>Each with their own database</p>
  
  <ul>
  <li>korea_motos -> AlmacenBundle</li>
  <li>galvez_motos -> RepuestosBundle </li>
  </ul>
  
  <p>Actually my security.yml has only one provider:</p>
  
  <pre><code>providers:
      korea:
          entity: { class: Korea\AlmacenBundle\Entity\Usuario, property: username }
  </code></pre>
  
  <p>As you can see, both bundles are authenticated by the same table: Usuario, in korea_motos</p>
  
  <p>TABLE: Usuario (korea_motos database)</p>
  
  <h1>--ID--|----USERNAME----|---------BUNDLE---</h1>
  
  <p>-----1-----|-------------admin----------------|----------AlmacenBundle----------</p>
  
  <p>-----2-----|-------------admin----------------|----------RepuestosBundle-------</p>
  
  <p>Now i want to validate the users, for RepuestosBundle with a table Usuario in galvez_motos, removing the column "bundle" in the previous table.</p>
  
  <p>The problem is in the security.yml file. If i make this:</p>
  
  <pre><code>providers:
      korea:
          entity: { class: Korea\AlmacenBundle\Entity\Usuario, property: username }
      galvez:
          entity: { class: Galvez\RepuestosBundle\Entity\Usuario, property: username }
  </code></pre>
  
  <p>Symfony launch a exception:</p>
  
  <pre><code>The class 'Galvez\RepuestosBundle\Entity\Usuario' was not found in the chain configured namespaces Korea\AlmacenBundle\Entity
  </code></pre>
  
  <p>Im trying to use 2 providers, one table per each bundle.. is this possible? </p>
  
  <p>Files:
  security.yml</p>
  
  <pre><code>jms_security_extra:
  secure_all_services: false
  expressions: true
  </code></pre>
  
  <p>security:
      encoders:
          Korea\AlmacenBundle\Entity\Usuario:
              algorithm:        sha1
              encode_as_base64: false
              iterations:       1
          Galvez\RepuestosBundle\Entity\Usuario:
              algorithm:        sha1
              encode_as_base64: false
              iterations:       1</p>
  
  <pre><code>role_hierarchy:
      ROLE_ADMIN:       ROLE_USER
      ROLE_SUPER_ADMIN: [ ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH ]
  
  providers:
      korea:
          entity: { class: Korea\AlmacenBundle\Entity\Usuario, property: username }
      galvez:
          entity: { class: Galvez\RepuestosBundle\Entity\Usuario, property: username }
  
  firewalls:
      dev:
          pattern:  ^/(_(profiler|wdt)|css|images|js)/
          security: false
  
      login:
          pattern:  ^/demo/secured/login$
          security: false
  
      secured_area:
          pattern:    ^/
          anonymous: ~
          access_denied_handler: accessdenied_handler
          form_login:
              login_path:  /login
              check_path:  /login_check
              default_target_path: /redirect
              always_use_default_target_path: true
          logout:
              path:   /logout
              target: /login
          #anonymous: ~
          #http_basic:
          #    realm: "Secured Demo Area"
  
  access_control:
      - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
      - { path: ^/redirect, roles: IS_AUTHENTICATED_ANONYMOUSLY }
      - { path: ^/galvez, roles: ROLE_ADMIN_GALVEZ }
      - { path: ^/, roles: ROLE_ADMIN_KOREA }
  </code></pre>
  
  <p>config.yml -- can't copy/paste all :(</p>
  
  <pre><code>doctrine:
  dbal:
      default_connection:   default
      connections:
          default:
              driver:   "%database_driver%"
              dbname:   "%database_name%"
              user:     "%database_user%"
              password: "%database_password%"
              host:     "%database_host%"
              port:     "%database_port%"
              charset:  UTF8
          galvez:
              driver:   %database_driver%
              dbname:   %database_name2%
              user:     %database_user2%
              password: %database_password2%
              host:     %database_host%
              port:     %database_port%
              charset:  UTF8
  orm:
      default_entity_manager:   default
      entity_managers:
          default:
              connection:       default
              mappings:
                  AlmacenBundle: ~
          galvez:
              connection:       galvez
              mappings:
                  RepuestosBundle: ~
  </code></pre>
  
  <p>parameters.yml</p>
  
  <pre><code>parameters:
  database_driver: pdo_mysql
  database_host: localhost
  database_port: null
  database_name: korea_motos
  database_user: root
  database_password:
  mailer_transport: smtp
  mailer_host: localhost
  mailer_user: null
  mailer_password: null
  locale: en
  secret: 5f7ac4e7c2b38d6dbe55a1f05bee2b02
  database_path: null
  
  database_name2: galvez_motos
  database_user2: root
  database_password2:
  </code></pre>
  
  <p>PD: Sry for my english :S</p>