-2

i'm new with symfony 4.4 and i'm struggling with roles in security.yaml file , i have 3 types of users : Admin , recruter and user , i was trying to give recruter access to the login form security_login_recruteur and at the same time i wanted the user to have access to his login form security_login

this is my security.yaml file

security:
    encoders:
        App\Entity\User:
            algorithm: bcrypt
        App\Entity\Recruteur:
            algorithm: bcrypt

    # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
    providers:
        users_in_memory: { memory: null }
        in_database:
            entity:
                class: App\Entity\User # here i'm trying to mention both of the entities
                       App\Entity\Recruteur
                property: email

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            anonymous: lazy
            provider: in_database
            form_login:
                login_path: security_login |security_login_recruteur #here i'm tring to put both of the paths
                check_path: security_login | security_login_recruteur
            logout:
                path: security_logout | security_logout_recruteur #also in the logout path
                target: home



            # 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: ^/recruteur, roles: ROLE_RECRUTEUR }
      #- { path: ^/admin, roles: ROLE_ADMIN }

i had this error after trying to access to /recruteur/connexion

Unable to generate a URL for the named route "security_login |security_login_recruteur" as such route does not exist.

can anyone help me please ?

Hello_world
  • 65
  • 1
  • 3
  • 17

1 Answers1

-1

For your business case you have to create multiple firewalls, one for each of your "user" (also multiple providers).

security:
    firewalls:
        ...

        main:
            form_login:
                login_path: security_login
            ...
            provider: user_provider #example
            lazy: true

        recruter:
            form_login:
                login_path: security_login_recruteur
            ...
            provider: recruter_provider #example
            lazy: true
        
         ... # add firewall for "Admin" for example
qdequippe
  • 1,075
  • 6
  • 15