AuthenticationCredentialsNotFoundException:安全上下文不包含身份验证令牌

时间:2013-12-08 09:39:20

标签: php security symfony

我收到以下错误

  

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

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

1 个答案:

答案 0 :(得分:2)

尝试这样的事情:

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