在我的Symfony 5.3项目中,我必须使用多个用户提供者和防火墙。
我想为每个防火墙定义login_throttling。只有一个用户提供者和防火墙,一切都很好(based on documentation),但当我添加第二个防火墙和用户提供者时,我得到了错误:

下面是我的security.yaml:
security:
enable_authenticator_manager: true
password_hashers:
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
App\Entity\User:
algorithm: auto
App\Entity\Seller:
algorithm: auto
providers:
# used to reload user from session & other features (e.g. switch_user)
app_user_provider:
entity:
class: App\Entity\User
property: email
sellers_provider:
entity:
class: App\Entity\Seller
property: email
firewalls:
main:
# use a custom rate limiter via its service ID
login_throttling:
limiter: app.login_rate_limiter
custom_authenticator: App\Security\LoginFormAuthenticator
logout:
path: app_logout
seller:
custom_authenticator: App\SellerPanel\Security\SellerAuthenticator
logout:
path: seller_logout
framework:
rate_limiter:
# define 2 rate limiters (one for username+IP, the other for IP)
username_ip_login:
policy: token_bucket
limit: 5
rate: { interval: '5 minutes' }
ip_login:
policy: sliding_window
limit: 50
interval: '15 minutes'
services:
# our custom login rate limiter
app.login_rate_limiter:
class: Symfony\Component\Security\Http\RateLimiter\DefaultLoginRateLimiter
arguments:
# globalFactory is the limiter for IP
$globalFactory: '@limiter.ip_login'
# localFactory is the limiter for username+IP
$localFactory: '@limiter.username_ip_login'如果我在main防火墙中注释login_throttling key,我没有得到错误,但我想在我的项目中使用它。
有什么解决方案吗?
发布于 2021-09-10 10:55:50
我已经解决了这个问题,我应该定义防火墙的模式和提供者
我更新的security.yaml如下:
security:
enable_authenticator_manager: true
password_hashers:
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
App\Entity\User:
algorithm: auto
App\Entity\Seller:
algorithm: auto
providers:
# used to reload user from session & other features (e.g. switch_user)
app_user_provider:
entity:
class: App\Entity\User
property: email
sellers_provider:
entity:
class: App\Entity\Seller
property: email
firewalls:
seller:
pattern: ^/seller-panel
custom_authenticator: App\SellerPanel\Security\SellerAuthenticator
login_throttling:
limiter: app.login_rate_limiter
provider: sellers_provider
logout:
path: seller_logout
main:
# use a custom rate limiter via its service ID
login_throttling:
limiter: app.login_rate_limiter
pattern: ^/
custom_authenticator: App\Security\LoginFormAuthenticator
provider: app_user_provider
logout:
path: app_logout
framework:
rate_limiter:
# define 2 rate limiters (one for username+IP, the other for IP)
username_ip_login:
policy: token_bucket
limit: 5
rate: { interval: '5 minutes' }
ip_login:
policy: sliding_window
limit: 50
interval: '15 minutes'
services:
# our custom login rate limiter
app.login_rate_limiter:
class: Symfony\Component\Security\Http\RateLimiter\DefaultLoginRateLimiter
arguments:
# globalFactory is the limiter for IP
$globalFactory: '@limiter.ip_login'
# localFactory is the limiter for username+IP
$localFactory: '@limiter.username_ip_login'https://stackoverflow.com/questions/69130846
复制相似问题