I am learning Symfony 4 and i want to change role of somes users to ROLE_ADMIN.
How can do this with a database ?
I tried to change it manually in database but it doesn't work...
(a:1:{i:0;s:9:"ROLE_USER";} -> a:1:{i:0;s:10:"ROLE_ADMIN";})
Thank you ;)
To promote users you can use command lines tools for FosUser:
php bin/console fos:user:promote testuser --super
php bin/console fos:user:promote testuser ROLE_ADMIN
check the doc here: https://symfony.com/doc/current/bundles/FOSUserBundle/command_line_tools.html
I tried to change the:
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
But nothing happens. What should I do?
according to symfony it should be, you missed the security layer. Try adding it:
security:
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
after migrating from php5.6 to php7.0 on (dev and prod), i'm prevented to connect on my admin account although i can create a new one !
i get "Bad credentials"
My security.yml :
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
Application\Sonata\UserBundle\Entity\User: sha512
any idea please.
I'm not sure why you have two encoders specified, try to comment the first one as you're loading user from database use
security:
encoders:
Application\Sonata\UserBundle\Entity\User: sha512
I am trying to configure SonataAdmin to display certain entity management for different roles. Read sonata docs, lots of QnA on stackoverflow, cannot find the problem...
Problem:
If I login as ROLE_ADMIN user, I can see all blocks, so sonata admin is working fine. But if I log in with other user, I just see empty page with no blocks. I would say I only need to add role ROLE_SONATA_CONTRACT to my user but as it did not work I tried every role I could think of including all roles auto-generated in user admin form.
I can give more information from configs, now I just copied parts I think are relevant.
My config:
Reference: http://sonata-project.org/bundles/admin/master/doc/reference/security.html#role-handler
# services.yml
services:
sonata.block.admin.contract:
class: STH\OrderBundle\Admin\ContractAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Orders", label: "Orders" }
arguments: [null, STH\OrderBundle\Entity\Contract, SonataAdminBundle:CRUD ]
# security.yml
role_hierarchy:
ROLE_SONATA_CONTRACT:
- ROLE_SONATA_BLOCK_ADMIN_CONTRACT_VIEW
- ROLE_SONATA_BLOCK_ADMIN_CONTRACT_GUEST
ROLE_ADMIN: [ROLE_USER, ROLE_ALLOWED_TO_SWITCH, ROLE_SONATA_PAGE_ADMIN_PAGE_EDIT, ROLE_SONATA_PAGE_ADMIN_BLOCK_EDIT]
ROLE_SUPER_ADMIN: ROLE_ADMIN
SONATA:
- ROLE_SONATA_PAGE_ADMIN_PAGE_EDIT # if you are using acl then this line must be commented
- ROLE_SONATA_PAGE_ADMIN_BLOCK_EDIT
access_decision_manager:
strategy: unanimous
# config.yml
security:
handler: sonata.admin.security.handler.role
# acl security information
information:
GUEST: [VIEW, LIST]
STAFF: [EDIT, LIST, CREATE]
EDITOR: [OPERATOR, EXPORT]
ADMIN: [MASTER, ROLE_ADMIN]
# permissions not related to an object instance and also to be available when objects do not exist
# the DELETE admin permission means the user is allowed to batch delete objects
admin_permissions: [CREATE, LIST, DELETE, UNDELETE, EXPORT, OPERATOR, MASTER]
# permission related to the objects
object_permissions: [VIEW, EDIT, DELETE, UNDELETE, OPERATOR, MASTER, OWNER]
System: Symfony 2.5.2, SonataAdminBundle, SonataUserBundle, FOSUserBundle.
I think you are not correctly defining your role hierearchies. Did you tried something like:
role_hierarchy:
ROLE_USER: [ROLE_SONATA_BLOCK_ADMIN_CONTRACT_VIEW,ROLE_SONATA_BLOCK_ADMIN_CONTRACT_GUEST ]
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
Just to trigger some insights about the way you define your hierarchies. hope it helps.
I'm currently having some frustration trying to implement the Symfony2 cookbook for creating a custom user provider utilising doctrine:
http://symfony.com/doc/2.0/cookbook/security/entity_provider.html
Here is my security.yml file:
security:
encoders:
Rep\Bundle\ProjectBundle\Model\User:
algorithm: sha1
encode_as_base64: false
iterations: 1
role_hierarchy:
ROLE_USER: ROLE_USER
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH ]
providers:
user_db:
entity: { class: ProjectBundle:User, property: username }
firewalls:
admin_area:
pattern: ^/admin
http_basic: ~
access_control:
- { path: ^/admin, roles: ROLE_ADMIN }
Here is my error:
Obvious questions:
Do I have doctrine installed? Yes. And Registered in the kernel.
Have I created the user interface and provider. Yes.
Also, I am choosing to build this instead of using the FOSUserBundle as it's too "bulky" for what I need, so any help would be ideal!
Problem was caused by missing configuration information for doctrine, however the bundle was registered in the kernel. Strange error message which doesn't point towards lacking config, but process of elimination resolved my issue.