使用 FOSUserBundle 时出现防火墙问题

Having a firewall issues when using FOSUserBundle

我正在尝试将 FOSUserBundle 合并到具有管理员身份验证系统的现有项目中,我正在为用户使用 FOSUserBundle,但我遇到了防火墙错误!

我正在使用这个 url:http://localhost/myproject/web/app_dev.php/fr/user/login

和错误:

InvalidConfigurationException in BaseNode.php line 313:
Invalid configuration for path "security.firewalls.Fos_secured_area": The check_path "/login_check" for login method "form_login" is not matched by the firewall pattern "^/(fr|en)/user/.*".

这是我的security.yml

 admin:
            entity: { class: AppBundle:Admin}

        fos_userbundle:
            id: fos_user.user_provider.username

    firewalls:

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

        Fos_secured_area:
            pattern:  ^/(%app_locales%)/User/.*
            form_login:
                provider: fos_userbundle
                csrf_token_generator: security.csrf.token_manager
            logout:       true
            anonymous:    true



        admin_secured_area:
            pattern: ^/(%app_locales%)/admin/.*
            anonymous: true
            provider: admin
            form_login:
                check_path: security_admin_login 
                login_path: security_admin_login
                csrf_token_generator: security.csrf.token_manager
                default_target_path: admin_page
            logout:
                path: admin_logout
                target: homepage
  access_control:

     - { path: ^/(%app_locales%)/User/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
     - { path: ^/(%app_locales%)/User/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
     - { path: ^/(%app_locales%)/User/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }

我的routing.yml

fos_user:
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"


app:
    resource: '@AppBundle/Controller/'
    type:     annotation
    prefix:   /{_locale}
    requirements:
        _locale: '%app_locales%'
    defaults:
        _locale: '%locale%'

尝试更改

pattern: ^/(%app_locales%)/User/.*

pattern: ^/

我认为你的情况不需要那种模式

简短说明: 该模式是一个正则表达式,用于确定什么防火墙规则将适用于什么路由。

Fosuserbundle 使用看起来像 /login_check 的路由作为登录操作的回调。由于它与您的模式不匹配,因此 Fos_secured_area rull 将不适用于该路线。