php - Symfony 4 - 自定义身份验证 FosUserBundle

标签 php symfony fosuserbundle symfony4

friend ,

我需要 Symfony4 方面的帮助。我为 FosUserBundle 构建自定义身份验证系统。 (我需要转换它)。

我的行为基于 Symfony 文档

https://symfony.com/doc/4.1/security/custom_authentication_provider.html

并且根据文档,我创建了所有真实文件。我不会把它们扔进去,因为这与文档中的相同。

我得到这个错误:

Not configuring explicitly the provider for the "wsse" listener on "main" firewall is ambiguous as there is more than one registered provider.

这是我的security.yaml

安全性: # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers 编码器: FOS\UserBundle\Model\UserInterface: bcrypt

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: [ ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH ]

providers:
    in_memory: { memory: ~ }
    fos_userbundle:
        id: fos_user.user_provider.username

firewalls:
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false
    main:
        pattern: ^/
        stateless: true
        wsse:      true
        form_login:
            provider: fos_userbundle
            csrf_token_generator: security.csrf.token_manager
            default_target_path: /

        logout:
            path: /logout
            target: /login
        anonymous: true

        # activate different ways to authenticate

        # http_basic: true
        # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate

        # form_login: true
        # https://symfony.com/doc/current/security/form_login_setup.html

# 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: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/, role: ROLE_USER }
    - { path: ^/admin/, role: ROLE_ADMIN }

编辑

服务提供商

App\Security\Authentication\Provider\WsseProvider:
        arguments:
            $userProviderInterface: '@fos_user.user_provider.username'
            $cachePool: '@cache.app'
        public: false

我正在寻求帮助,因为我被困住了

谢谢

最佳答案

在你的 security.yml 上 添加:

providers:
    wsse:
        id: App\Security\wsseProvider #class of UserProviderInterface

firewalls:
    main:
        ...
        form_login:
            provider: wsse

在 services.yaml 上

services:
  App\Security\wsseProvider:
    autowire: true
    public: false

关于php - Symfony 4 - 自定义身份验证 FosUserBundle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53764371/

相关文章:

php - 每 15 分钟执行一次更改数据库的功能

php - Symfony2 和后台进程

symfony - 自定义更改密码表格

php - PHP 中的错误和异常有什么区别?

php - 导航离开 php 页面后,上传的文件会发生什么情况?

PHP $_SESSION 不在请求之间共享

php - 交响乐 2.8 : Doctrine getManagerForClass() not returning the right Entity Manager

symfony - FOSUserBundle 理解 twig 模板变量

php - 登录 Symfony2 后维护语言环境

symfony - APC 不保存 fosuserbundle 扩展类中的属性