I'm trying to create a new role in Symfony 2 below the default USER_ROLE (that role would have limited write access to some features). I am using FOSUserBundle.
I've written the following security settings so far but my ROLE_DEMO users still get the ROLE_USER.
role_hierarchy:
ROLE_DEMO: []
ROLE_USER: [ROLE_DEMO]
ROLE_ADMIN: [ROLE_USER, ROLE_SONATA_ADMIN]
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
Is it possible to create a role under the ROLE_USER in Symfony 2. If yes, how?
A even shorter solution i came up with was to override the
const ROLE_DEFAULT
at the beginning of my ownerUser
class.That way i did not even have to override the FOS user bundle
getRoles()
method.for symfony 3 and 4
use this in you entity User
If you are using FOSUserBundle, it will give all users the
ROLE_USER
by default.ROLE_USER
is present on every single hydrated user under the default FOSUserBundle setup (although not in the database). You could override that implementation by defining your owngetRoles()
method on your ownUser
class. Or change the default role toROLE_NONE
(it doesn't really matter what). Or just avoid usingROLE_USER
and come up with another role name for your actual users.This is from the default
User
implementation