簡體   English   中英

Symfony 4 - 自定義身份驗證FosUserBundle

[英]Symfony 4 - custom authentication FosUserBundle

朋友們,

我需要Symfony4的幫助。 我為FosUserBundle構建自定義身份驗證系統。 (我需要轉換它)。

我的行動基於Symfony文檔

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

根據文檔,我創建了所有可靠的文件。 我不會拋棄它們,因為這與文檔中的相同。

我收到這個錯誤:

未明確配置“主”防火牆上的“wsse”偵聽器的提供程序是不明確的,因為有多個已注冊的提供程序。

這是我的security.yaml

安全性:# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers編碼器:FOS \\ UserBundle \\型號\\的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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM