I'm trying to figure out why I can't set multiple user providers into a single provider. Currently I'm configuring ACL. For the user providers I want to have a couple of "hard-coded" users and users which would be loaded from a database.
Reading the documentation it's stated that you're not required to have two user providers - one for the in_memory
users and one for the database
users. You should be able to combine them into a single user provider (which is what I'm trying to do).
The suggested configuration is:
security:
providers:
main_provider:
memory:
users:
foo: { password: test }
entity:
class: Acme\UserBundle\Entity\User,
property: username
My configuration is:
security:
providers:
main_provider:
memory:
users:
foo: { password: test }
entity:
class: Company\EntitiesBundle\Entity\User,
property: username
Unfortunately I get this exception:
InvalidConfigurationException: Invalid configuration for path "security.providers.main_provider": You cannot set multiple provider types for the same provider
If I, however, set two different providers and chain them, it works without problems.
I can't figure out why this would happen? It's clearly stated in the documentation - you can accomplish this even more easily by combining the two sources into a single provider
.
What am I missing here?
Why don't you chain providers? The documentation that you're referring states that you can use multiple user providers "...by creating a new provider that chains the two together".
http://symfony.com/doc/current/book/security.html#using-multiple-user-providers
Each authentication mechanism (e.g. HTTP Authentication, form login, etc) uses exactly one user provider, and will use the first declared user provider by default. But what if you want to specify a few users via configuration and the rest of your users in the database? This is possible by creating a new provider that chains the two together.
Now, all authentication mechanisms will use the chain_provider, since it's the first specified. The chain_provider will, in turn, try to load the user from both the in_memory and user_db providers.
All you have to do is to setup a chain provider.
# app/config/security.yml security: providers: main_provider: chain: providers: [memory_provider, entity_provider] memory_provider: memory: users: foo: { password: test } entity_provider: entity: class: Company\EntitiesBundle\Entity\User property: username
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With