AuthenticationCredentialsNotFoundException:安全上下文不包含身份验证令牌 [英] AuthenticationCredentialsNotFoundException: The security context contains no authentication token

查看:61
本文介绍了AuthenticationCredentialsNotFoundException:安全上下文不包含身份验证令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误

AuthenticationCredentialsNotFoundException:安全上下文不包含身份验证令牌.一种可能的原因可能是没有为此 URL 配置防火墙.

AuthenticationCredentialsNotFoundException: The security context contains no authentication token. One possible reason may be that there is no firewall configured for this URL.

我尝试了解决方案,因为我知道当没有为路由配置安全防火墙时会发生此错误,但我似乎无法解决该错误.

I have tried solutions because i know this error occurs when there is no security firewall configured for the route, however i cant seem to solve the error.

这是我的 security.yml

This is my 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')"}

所以我添加了默认路由和匿名允许但错误仍然存​​在

So ive added default routes and anonymous allowed but the error still persists

推荐答案

试试这个:

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

这篇关于AuthenticationCredentialsNotFoundException:安全上下文不包含身份验证令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆