简体   繁体   English

Symfony复杂acl基于动态角色和权限

[英]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). 我想构建一个具有多个用户的系统,每个用户可以被分配0到多个角色到项目或项目的部分(对象)。 Each role can have 1 to many permissions. 每个角色可以拥有1到多个权限。 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. 我知道我应该使用ACL,但是我不确定如何在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 ) 您可以通过以下链接获取更多信息( Symfony ACL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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