【问题标题】:The service "security.command.debug_firewall" has a dependency on a non-existent service服务“security.command.debug_firewall”依赖于不存在的服务
【发布时间】:2022-11-10 16:26:02
【问题描述】:

我正在为我的电子商务网站使用 Symfony 5.4.10。在生成认证表格时,输入 php bin/console make:auth 后,所有必要的文件都已生成。但在那之后,执行登录表单时出现此错误:服务“security.command.debug_firewall”依赖于不存在的服务“App\Security\LoginFormAuthenticator”

我的 Security.yaml 文件:

security:
    encoders:
        App\Entity\User:
            algorithm: auto

    enable_authenticator_manager: true
    # https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
    password_hashers:
        Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
    # https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
    providers:
        # used to reload user from session & other features (e.g. switch_user)
        app_user_provider:
            entity:
                class: App\Entity\User
                property: email
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            lazy: true
            provider: app_user_provider
            custom_authenticator: 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#the-firewall

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

when@test:
    security:
        password_hashers:
            # By default, password hashers are resource intensive and take time. This is
            # important to generate secure password hashes. In tests however, secure hashes
            # are not important, waste resources and increase test times. The following
            # reduces the work factor to the lowest possible values.
            Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface:
                algorithm: auto
                cost: 4 # Lowest possible value for bcrypt
                time_cost: 3 # Lowest possible value for argon
                memory_cost: 10 # Lowest possible value for argon

【问题讨论】:

    标签: symfony5.4


    【解决方案1】:

    如果你写
    custom_authenticator:AppSecurityLoginFormAuthenticator

    你需要自己实现这个类。

    1. 创建 src/Security 文件夹,
    2. 创建类LoginFormAuthenticator.php
    3. 扩展了 AbstractFormLoginAuthenticator。

      之后,只需根据您的需要覆盖这些方法。

    【讨论】:

      猜你喜欢
      • 2017-03-21
      • 2019-09-28
      • 2015-05-29
      • 2018-07-22
      • 2019-07-08
      • 2018-01-16
      • 2018-05-18
      • 2016-10-11
      • 1970-01-01
      相关资源
      最近更新 更多