博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Symfony2权限相关语句备忘
阅读量:7108 次
发布时间:2019-06-28

本文共 2142 字,大约阅读时间需要 7 分钟。

与Symfony2权限相关的语句在官方文档上不是很全,每次要用到时查找起来十分费劲,所以在这里列出与Symfony2权限相关的语句,以备查:

 
  1. /** 
  2.  * 生成SecurityIdentity 
  3.  */ 
  4. //基于用户生成SecurityIdentity 
  5. $securityIdentity = UserSecurityIdentity::fromAccount($user); 
  6. //基于角色生成SecurityIdentity 
  7. $securityIdentity = new RoleSecurityIdentity($role->getRole()); 
  8.  
  9. /** 
  10.  * 生成ObjectIdentity 
  11.  */ 
  12. //基于对象生成ObjectIdentity 
  13. $objectIdentity = ObjectIdentity::fromDomainObject($comment);  
  14. //基于类生成ObjectIdentity 
  15. $objectIdentity = new ObjectIdentity('some_identifier''Class\FQCN'); 
  16.  
  17. /** 
  18.  * 生成ACL 
  19.  */ 
  20. $acl = $aclProvider->createAcl($objectIdentity); 
  21. //插入ACE(基于对象) 
  22. $acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_OWNER);  
  23. //插入ACE(基于类) 
  24. $acl->insertClassAce($securityIdentity, MaskBuilder::MASK_CREATE); 
  25. $aclProvider->updateAcl($acl); 
  26.  
  27. /** 
  28.  * 判断权限 
  29.  */ 
  30. $securityContext = $this->get('security.context'); 
  31. $securityContext->isGranted('CREATE'$classIdentity);  // 返回真 
  32. $securityContext->isGranted('VIEW'$classIdentity);    // 返回真 
  33. $securityContext->isGranted('DELETE'$classIdentity);  // 返回假 
  34.  
  35.  
  36. /** 
  37.  *ACE的增删改查 
  38.  */ 
  39. //插入基于对象的ACE 
  40. $acl->insertObjectAce(SecurityIdentityInterface $sid$mask$index = 0, $granting = true, $strategy = null) ;
  41. //插入基于对象字段的ACE 
  42. $acl->insertObjectFieldAce($field, SecurityIdentityInterface $sid$mask$index = 0, $granting = true, $strategy = null) ;
  43. //插入基于类的ACE 
  44. $acl->insertClassAce(SecurityIdentityInterface $sid$mask$index = 0, $granting = true, $strategy = null) ;
  45. //插入基于类字段的ACE 
  46. $acl->insertClassFieldAce($field, SecurityIdentityInterface $sid$mask$index = 0, $granting = true, $strategy = null) ;
  47.  
  48. //删除ACE 
  49. $acl->deleteObjectAce($index) ;
  50. $acl->deleteObjectFieldAce($index$field);
  51. $acl->deleteClassAce($index) ;
  52. $acl->deleteClassFieldAce($index$field);
  53.  
  54. //更新ACE 
  55. $acl->updateObjectAce($index$mask$strategy = null) ;
  56. $acl->updateObjectFieldAce($index$field$mask$strategy = null) ;
  57. $acl->updateClassAce($index$mask$strategy = null) ;
  58. $acl->updateClassFieldAce($index$field$mask$strategy = null) ;
  59.  
  60. //得到ACE 
  61. $acl->getObjectAces() ;
  62. $acl->getObjectFieldAces($field) ;
  63. $acl->getClassAces() ;
  64. $acl->getClassFieldAces($field) ;

 

本文转自 firehare 51CTO博客,原文链接:http://blog.51cto.com/firehare/767785,如需转载请自行联系原作者

你可能感兴趣的文章
UIMovieClip的一点小认识(转载)
查看>>
OpenStack 企业私有云的若干需求(10):OpenStack 的前景和钱景
查看>>
ASP.NET免费服务器~支持MVC和Net4.5
查看>>
StackOverflow发布年度开发者调查报告:JavaScript备受欢迎
查看>>
自平衡二叉查找树
查看>>
shell脚本中的数据传递方式
查看>>
Shiro系列(0) - 权限管理在J2EE企业级开发中的应用与实战
查看>>
Oracle Goldengate REPLICAT启动时报正在运行解决办法
查看>>
Gdevops峰会归来
查看>>
[20170215]ORA-00088与DG Gap监测与解决4
查看>>
Hadoop Pig学习笔记(一) 各种SQL在PIG中实现
查看>>
充分挖掘大数据资源“富矿”
查看>>
oerr的用法
查看>>
解决GPG签名验证错误
查看>>
不属于自己的就忘掉吧,不要留恋,就当着是回忆吧…!
查看>>
文化衫、毕业纪念衫选用什么方式印刷合适?
查看>>
Spark亚太研究院决胜大数据时代100期公益大讲堂
查看>>
删除多target工程
查看>>
NSRunLoop详解
查看>>
[From Microsoft] Using command redirection oper...
查看>>