如何解决如何在Symfony 4上使用多个提供程序配置防火墙?
我正在写这条消息,问您如何与多个用户提供商一起启动我的Symfony应用程序?这是我的安全Yaml:
security:
encoders:
App\Entity\User:
algorithm: auto
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
chain_provider:
chain:
providers: [in_memory,app_user_provider]
# used to reload user from session & other features (e.g. switch_user)
app_user_provider:
entity:
class: App\Entity\User
property: email
in_memory:
memory:
users:
foo: { password: test,roles: [ 'ROLE_ADMIN' ] }
# used to reload user from session & other features (e.g. switch_user)
# memory:
# users:
# admin: { password: '123412A',roles: ['ROLE_ADMIN']}
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
# form_login:
# csrf_token_generator : security.csrf.token_manager
anonymous: true
logout:
path: app_logout
guard:
authenticators:
- App\Security\UtilisateurAuthenticator
# where to redirect after logout
# target: app_any_route
# where to redirect after logout
# target: app_any_route
# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#firewalls-authentication
# 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: ^/Conversation,roles: [ROLE_ADMIN,ROLE_USER] }
- { path: ^/admin,roles: ROLE_ADMIN }
- { path: ^/login$,roles: IS_AUTHENTICATED_ANONYMOUSLY }
# - { path: ^/profile,roles: ROLE_USER }
我收到此错误消息,如何解决?
未在“主”防火墙上显式配置“后卫”侦听器的提供程序 因为有一个以上的注册提供者,所以模棱两可。
解决方法
您只需要声明要在main
防火墙中使用的用户提供者。它必须是使用providers
键声明的变量之一。
# security.yaml
# ...
main:
provider: chain_provider # or app_user_provider or in_memory
form_login:
# ...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。