Symfony 5-多种保护身份验证-主页对用户进行身份验证

时间:2020-09-11 11:06:01

标签: php symfony web-application-firewall

我在symfony中还很新,我正在尝试做的是多次登录身份验证。 我已经有两个表COMPANY和CANDIDATE。他们两个都有不同的登录形式,控制器和身份验证器。身份验证过程进行得很顺利,并且可以授权我的两个用户使用,因此防火墙可以正常工作,期望最后一个“主”模式为“ / ^”。主页(顺便说一下索引)不对用户进行身份验证,并且像defualt一样显示为“ ANON”。

这是我的“ security.yaml”

security:
encoders:
    App\Entity\Candidates:
        algorithm: auto
    App\Entity\Companies:
        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)
    candidates:
        entity:
            class: App\Entity\Candidates
            property: email
    # used to reload user from session & other features (e.g. switch_user)
    companies:
        entity:
            class: App\Entity\Companies
            property: email

    chain_provider:
        chain:
            providers: [candidates, companies]
    
firewalls:
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false



    candidate:
        pattern: ^/candidate/.*
        anonymous: true
        lazy: true
        provider: candidates
        guard:
            authenticators:
                - App\Security\CandidatesAuthenticator
        logout:
            path: app_candidate_logout
            # where to redirect after logout
            target: /
        form_login:
            login_path: /candidate/login
            check_path: /candidate/login
        #     username_parameter: "login_form[email]"
        #     password_parameter: "login_form[password]"

    company:
        pattern: ^/company/.*
        anonymous: true
        lazy: true
        provider: companies
        guard:
            authenticators:
                - App\Security\CompaniesAuthenticator
        logout:
            path: app_company_logout
            # where to redirect after logout
            target: /
        form_login:
            login_path: /company/login
            check_path: /company/login
            # username_parameter: "login_form[email]"
            # password_parameter: "login_form[password]"
    main:
        pattern: ^/
        anonymous: true
        provider: chain_provider
        guard:
            authenticators:
                - App\Security\CandidatesAuthenticator
                - App\Security\CompaniesAuthenticator
            entry_point: App\Security\CandidatesAuthenticator 
        # logout:
        #     path: app_logout
        #     where to redirect after logout
        #     target: /

        # 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 tocontrol 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 }

我做错了什么?

0 个答案:

没有答案