简体   繁体   中英

Symfony complex acl based on dynamic roles and permissions

I want to build a system which has multiple users, each user can be assigned 0 to many roles to projects or sections of projects (Objects). Each role can have 1 to many permissions. The roles can be created dynamically , so assigning them to users. However, permissions can be hard-coded.

I know I should use ACL, however I am not sure of how to add dynamic roles into it in Symfony2. Additionally, should I use voters?

Hopefully the below code help you

// creating the ACL
$aclProvider = $this->get('security.acl.provider');
$objectIdentity = ObjectIdentity::fromDomainObject($the_object_to_be_granted);
$acl = $aclProvider->createAcl($objectIdentity);

$securityIdentity = new RoleSecurityIdentity("CUSTOM_ROLE_YOU_HAVE");

// grant owner access
$acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_OWNER);// This is sample you can use any other masks you need
$aclProvider->updateAcl($acl);

You can obtain more info on the following link ( Symfony ACL )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM