I have a big problem with my role_hierarchy,
security:
role_hierarchy:
ROLE_ADMIN:[ROLE_USER,ROLE_AUTHOR,ROLE_MODERATOR]
ROLE_SUPER_ADMIN:[RO
I cannot see what's wrong from the code snippets you provided, so I made a little example application to give you a step by step-instruction which might lead you to the source of the problem.
"friendsofsymfony/user-bundle": "dev-master"
to composer.jsonphp app/console generate:bundle
)php app/console doctrine:generate:entity
Modified app/AppKernel.php
, app/config/config.yml
, app/config/routing.yml
and app/config/security.yml
according to FOS\UserBundle documentation. For reference: This is the security.yml I use:
jms_security_extra:
secure_all_services: false
expressions: true
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_AUTHOR: [ROLE_USER]
ROLE_MODERATOR: [ROLE_AUTHOR]
ROLE_ADMIN: [ROLE_MODERATOR]
ROLE_SUPER_ADMIN: [ROLE_ADMIN]
providers:
fos_userbundle:
id: fos_user.user_manager
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
auth:
pattern: (^/login$|^/register|^/resetting)
anonymous: true
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
logout: true
anonymous: true
access_control:
- { path: ^/admin, role: ROLE_ADMIN }
Created user with `php app/console fos:user:create sa --super-admin
Modified DefaultController:default.html.twig in Mahok\SecurityBundle, checking for {% is_granted('ROLE_MODERATOR') %}
:
Hello {{ name }}!
{% if is_granted('ROLE_MODERATOR') %}
{% for role in app.user.roles %}
- {{ role }}
{% endfor %}
{% else %}
oh noes!
{% endif %}
edit: When going to localhost/example/app_dev.php/hello/User (after logging in as "sa"), I get the following output:
Hello User!
* ROLE_SUPER_ADMIN
* ROLE_USER