我得到以下错误
AuthenticationCredentialsNotFoundException:安全上下文不包含身份验证令牌。一个可能的原因可能是没有为此URL配置防火墙。
我已经尝试了解决方案,因为我知道当没有为路由配置安全防火墙时会发生这个错误,但我似乎无法解决这个错误。
这是我的安全。yml
security:
access_decision_manager:
# strategy can be: affirmative, unanimous or consensus
strategy: unanimous
encoders:
"MyNameMyBundleEntityUser": { algorithm: sha1, encode_as_base64: false, iterations: 0 } # You'll set this to sha1 when you have everything working.
providers:
default:
entity: { class: MyNameMyBundleEntityUser, property: username } # This is an ORM entity and username is just the username property of the entity.
role_hierarchy:
ROLE_MEMBER: ROLE_GUEST
ROLE_STAFF: ROLE_MEMBER
ROLE_ADMIN: ROLE_STAFF
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
anonymous: true
main:
pattern: ^/
anonymous: ~
form_login:
login_path: /login
check_path: /login_check
success_handler: authentication_handler
failure_handler: authentication_handler
use_referer: true
default_target_path: /
remember_me:
key: "%secret%"
lifetime: 31536000 # 365 days in seconds
path: /
domain: ~ # Defaults to the current domain from $_SERVER
always_remember_me: true
logout:
path: /logout
target: /
access_control:
- { path: ^/admin, roles: ROLE_STAFF }
- { path: ^/admin2, roles: ROLE_STAFF }
- { path: ^/members, roles: ROLE_MEMBER }
- { path: ^/shop/ipn/paypal, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/shop/step, roles: IS_AUTHENTICATED_FULLY }
- { path: ^/shop/confirm, roles: IS_AUTHENTICATED_FULLY }
- { path: ^/application, roles: IS_AUTHENTICATED_FULLY }
- { path: ^/account, roles: IS_AUTHENTICATED_FULLY }
- { path: ^/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/home, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
#- { path: ^/foo, access: "hasRole('FOO') and hasRole('BAR')" }
#- { path: ^/forum, access: "!hasRole('ROLE_BANNED')"}
因此,我添加了默认路由和允许匿名,但错误仍然存在
试试这样的东西:
secure:
pattern: ^/(admin|admin2|members|shop|application|account)
anonymous: true
form_login:
login_path: /login
check_path: /login_check
success_handler: authentication_handler
failure_handler: authentication_handler
use_referer: true
default_target_path: /
remember_me:
key: "%secret%"
lifetime: 31536000 # 365 days in seconds
path: /
domain: ~ # Defaults to the current domain from $_SERVER
always_remember_me: true
logout:
path: /logout
target: /
main:
pattern: ^/
anonymous: true