Symfony2:isGranted方法返回AuthenticationCredentialsNotFoundException

时间:2014-01-09 14:11:40

标签: symfony twig

我的页面中有一个Twig扩展菜单,但我需要使用isGranted方法根据用户显示菜单项,但symfony2 profilers向我显示警告:

分析师说:

  

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

     

在C:\ xampp \ htdocs \ galvez_motos \ app \ cache \ dev \ classes.php第2395行   at SecurityContext-> isGranted('ROLE_ADMIN')位于C:\ xampp \ htdocs \ galvez_motos \ src \ GalvezMotos \ AlmacenBundle \ Twig \ MenuExtension.php第432行

如何在登录前使用isGranted方法?

security.yml:

security:
firewalls:
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false
    secured_area:
        pattern: ^/
        anonymous: ~
        form_login:
            login_path: login
            check_path: login_check
        logout:
            path: /logout
            target: /
            invalidate_session: false

access_control:
    - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY  }
    - { path: ^/admin, roles: ROLE_ADMIN }
    - { path: ^/, roles: ROLE_USER }

providers:
    user_db:
        entity: { class: GalvezMotos\AlmacenBundle\Entity\Usuario, property: username }

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

encoders:
    GalvezMotos\AlmacenBundle\Entity\Usuario:
        algorithm: sha1
        iterations: 1
        encode_as_base64: false

Pd:图片

enter image description here

enter image description here

enter image description here

0 个答案:

没有答案