Skip to content

[Cookbook][Security] usage of a non-default entity manager in an entity user provider #4023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions cookbook/security/entity_provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,69 @@ entity user provider to load User entity objects from the database by using
the ``username`` unique field. In other words, this tells Symfony how to
fetch the user from the database before checking the password validity.

.. note::

By default, the entity provider uses the default entity manager to fetch
user information from the database. If you,
:doc:`use multiple entity managers </cookbook/doctrine/multiple_entity_managers>`,
you can specify which manager to use with the ``manager_name`` option:

.. configuration-block::

.. code-block:: yaml

# app/config/config.yml
security:
# ...

providers:
administrators:
entity:
class: AcmeUserBundle:User
property: username
manager_name: customer

# ...

.. code-block:: xml

<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<srv:container xmlns="http://symfony.com/schema/dic/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd">
<config>
<!-- ... -->

<provider name="administrators">
<entity class="AcmeUserBundle:User"
property="username"
manager-name="customer" />
</provider>

<!-- ... -->
</config>
</srv:container>

.. code-block:: php

// app/config/config.php
$container->loadFromExtension('security', array(
// ...
'providers' => array(
'administrator' => array(
'entity' => array(
'class' => 'AcmeUserBundle:User',
'property' => 'username',
'manager_name' => 'customer',
),
),
),
// ...
));

Forbid inactive Users
---------------------

Expand Down