4
我收到以下錯誤AuthenticationCredentialsNotFoundException:安全上下文不包含身份驗證令牌
AuthenticationCredentialsNotFoundException:安全上下文 不包含身份驗證令牌。一個可能的原因可能是 沒有爲此URL配置防火牆。
我嘗試瞭解決方案,因爲我知道這個錯誤發生在沒有爲路由配置安全防火牆時,但是我似乎無法解決錯誤。
這是我security.yml
security:
access_decision_manager:
# strategy can be: affirmative, unanimous or consensus
strategy: unanimous
encoders:
"MyName\MyBundle\Entity\User": { algorithm: sha1, encode_as_base64: false, iterations: 0 } # You'll set this to sha1 when you have everything working.
providers:
default:
entity: { class: MyName\MyBundle\Entity\User, 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')"}
所以香港專業教育學院添加默認路由和匿名允許的,但錯誤仍然存在
它的一個錯字? ' - {path:/ ^,role:IS_AUTHENTICATED_ANONYMOUSLY}'你在什麼地方得到異常? –
HTTP://localhost/app_dev.php/homeewfwefwe我試圖使它所以它顯示了一個404頁面側邊欄上不存在的網頁,但是側邊欄包含is_granted(「IS_AUTHENTICATED_REMEMBERED」)引用來檢查用戶是否登錄 –
是因爲你有2個default_target_path? –