我有我的role_hierarchy一个很大的问题,
security:
role_hierarchy:
ROLE_ADMIN:[ROLE_USER,ROLE_AUTHOR,ROLE_MODERATOR]
ROLE_SUPER_ADMIN:[ROLE_ADMIN,ROLE_ALLOWED_TO_SWITCH]
这一说法,如果我得到了超级管理员的角色,我就得到了ROLE_AUTHOR,ROLE_MODERATOR,ROLE_USER和ROLE_ADMIN。 但我的问题是,当我登录我的网站上,如果我检查剖析,我可以看到我只拿到了ROLE_SUPER_ADMIN,而不是其他人的角色,所以,你能帮助我吗?
我的观点( base.html.twig
)
<h3>Blog</h3>
<ul class="nav nav-pills nav-stacked">
<li><a href="{{ path('dom_home') }}">Home Page</a></li>
{% if is_granted('ROLE_AUTHOR') %}
<li><a href="{{ path('dom_add') }}">Add a post</a></li>
{% endif %}
{% if is_granted('IS_AUTHENTICATED_FULLY') %}
<li><a href="{{ path('fos_user_security_logout') }}">Logout</a></li>
{% else %}
<li><a href="{{ path('fos_user_security_login') }}">login</a></li>
<li><a href="{{ path('fos_user_registration_register') }}">register</a></li>
{% endif %}
</ul>
我security.yml
(应用程序/配置)
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_ADMIN: [ROLE_USER,ROLE_AUTHOR,ROLE_MODERATOR]
ROLE_SUPER_ADMIN: [ROLE_ADMIN,ROLE_ALLOWED_TO_SWITCH]
providers:
in_memory:
users:
user: { password: userpass, roles: [ 'ROLE_USER' ] }
admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }
fos_userbundle:
id: fos_user.user_manager
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/(login$|register|resetting)
anonymous: true
main:
pattern: ^/
form_login:
provider: fos_userbundle
remember_me: true
always_use_default_target_path: true
default_target_path: /dom/
remember_me:
key: %secret%
anonymous: false
logout: true
编辑:
我的观点(base.html.twig)
<h3>Blog</h3>
<ul class="nav nav-pills nav-stacked">
<li><a href="{{ path('dom_home') }}">Home Page</a></li>
{% if is_granted('ROLE_AUTHOR') %}
<li><a href="{{ path('dom_add') }}">Add a post</a></li>
{% endif %}
{% if is_granted('IS_AUTHENTICATED_FULLY') %}
<li><a href="{{ path('fos_user_security_logout') }}">Logout</a></li>
{% else %}
<li><a href="{{ path('fos_user_security_login') }}">login</a></li>
<li><a href="{{ path('fos_user_registration_register') }}">register</a></li>
{% endif %}
</ul>
我security.yml(应用程序/配置)
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_ADMIN: [ROLE_USER,ROLE_AUTHOR,ROLE_MODERATOR]
ROLE_SUPER_ADMIN: [ROLE_ADMIN,ROLE_ALLOWED_TO_SWITCH]
providers:
in_memory:
users:
user: { password: userpass, roles: [ 'ROLE_USER' ] }
admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }
fos_userbundle:
id: fos_user.user_manager
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/(login$|register|resetting)
anonymous: true
main:
pattern: ^/
form_login:
provider: fos_userbundle
remember_me: true
always_use_default_target_path: true
default_target_path: /dom/
remember_me:
key: %secret%
anonymous: false
logout: true
请回答 :)