首页 > 解决方案 > Symfony 3 - 无法实现 FOSUser 安全登录,因为我也使用 CAS 身份验证

问题描述

我想在我的 security.yml 上添加我的 FOSUser 登录方法,因为我使用身份验证 CAS,但我希望在我的主页上使用登录表单进行身份验证(数据库上的用户表与来自 CAS 身份验证的用户不同)

所以我像这样配置了我的security.yml:

# app/config/security.yml
security:
    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: ROLE_ADMIN

providers:
    app:
       id: bes_auth.user_provider

firewalls:

    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false
       # anonymous:    true

    public:
        pattern: ^accueil
        security: false
        anonymous: true

    main:
        logout_on_user_change: true
        pattern: ^/(admin|profile|packages|securiteInformatique|logout)
       # pattern: ^/(?!accueil)


        guard:
            authenticators:
                - app.security.login_form_authenticator:
                    check_path: fos_user_check_path

                - bes_auth.authenticator

        entry_point: Site\PagesBundle\Security\LoginFormAuthenticator


        logout:
            path:   deconnexion #nom de la route de déconnexion
            target: /
            success_handler: bes_auth.authenticator
        anonymous:    true

access_control:
    - { path: ^/admin, role: ROLE_SUPER_ADMIN }
    - { path: ^/accueil, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/, role: ROLE_USER }

但我现在有这个错误:

路径“security.firewalls.main.guard.authenticators.0”的类型无效。预期的标量,但得到了数组。

是关于 :

        guard:
            authenticators:
                - app.security.login_form_authenticator:
                    check_path: fos_user_check_path

                - bes_auth.authenticator

            entry_point: Site\PagesBundle\Security\LoginFormAuthenticator

但是我看不出有什么问题,有人可以帮我吗?

标签: phpsymfonyfosuserbundle

解决方案


just change your first Guard Authenticator without the option check_path: fos_user_check_path like this :

...........

guard:
    authenticators:
        - app.security.login_form_authenticator
        - bes_auth.authenticator

if you want more explain, this is the document: here

thanks, I hope it's help you


推荐阅读