I looked in to this post but my problem is a little different and many things in symfony security component have changed for version 5.
So, I try to set entity manager other than default in user provider. I created two connections using documentation: https://symfony.com/doc/current/doctrine/multiple_entity_managers.html
doctrine:
dbal:
default_connection: default
connections:
default:
url: '%env(resolve:DATABASE_URL)%'
b2b:
url: '%env(resolve:DATABASE_B2B_URL)%'
users:
url: '%env(resolve:DATABASE_USERS_URL)%'
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '5.7'
orm:
auto_generate_proxy_classes: true
default_entity_manager: default
entity_managers:
default:
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: false
connection: default
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/Main'
prefix: 'App\Entity\Main'
alias: Main
b2b:
connection: b2b
users:
connection: users
mappings:
Users:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/Users'
prefix: 'App\Entity\Users'
alias: Users
Next I change my security.yaml and add manager_name: users - exactly as in the documentation:
security:
encoders:
App\Entity\Users\User:
algorithm: auto
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
# used to reload user from session & other features (e.g. switch_user)
app_user_provider:
entity:
class: App\Entity\Users\User
property: email
manager_name: users
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: lazy
provider: app_user_provider
guard:
authenticators:
- App\Security\LoginFormAuthenticator
logout:
path: app_logout
# where to redirect after logout
# target: app_any_route
# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#firewalls-authentication
# https://symfony.com/doc/current/security/impersonating_user.html
# switch_user: true
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
# - { path: ^/admin, roles: ROLE_ADMIN }
# - { path: ^/profile, roles: ROLE_USER }
Despite the above settings security component try to load class from default entity manager:
[2020-04-16T05:53:55.276798+00:00] request.CRITICAL: Uncaught PHP Exception Doctrine\Persistence\Mapping\MappingException: "The class 'App\Entity\Users\User' was not found in the chain configured namespaces App\Entity\Main" at /home/budmechzz/public_html/rfm.computermedia.com.pl/vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/MappingException.php line 23 {"exception":"[object] (Doctrine\\Persistence\\Mapping\\MappingException(code: 0): The class 'App\\Entity\\Users\\User' was not found in the chain configured namespaces App\\Entity\\Main at /home/budmechzz/public_html/rfm.computermedia.com.pl/vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/MappingException.php:23)"} []
What am I doing wrong?