Activiti源码浅析:Activiti的活动授权机制

来源:互联网 发布:网络建设与管理答案 编辑:程序博客网 时间:2024/06/11 11:32

1. IdentityLink与TaskEntity

An identity link is used to associate a task with a certain identity. For example: - a user can be an assignee (= identity link type) for a task - a group can be a candidate-group (= identity link type) for a task

TaskEntity包含了一系列的IdentityLink操作方法:

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. public IdentityLinkEntity addIdentityLink(String userId, String groupId, String type) {  
  2.    IdentityLinkEntity identityLinkEntity = new IdentityLinkEntity();  
  3.    getIdentityLinks().add(identityLinkEntity);  
  4.    identityLinkEntity.setTask(this);  
  5.    identityLinkEntity.setUserId(userId);  
  6.    identityLinkEntity.setGroupId(groupId);  
  7.    identityLinkEntity.setType(type);  
  8.    identityLinkEntity.insert();  
  9.    if (userId != null && processInstanceId != null) {  
  10.      getProcessInstance().involveUser(userId, IdentityLinkType.PARTICIPANT);  
  11.    }  
  12.    return identityLinkEntity;  
  13.  }  

注意,IdentityLink有一个Type,有一些默认的Type:

[java] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. public void addCandidateUser(String userId) {  
  2.   addIdentityLink(userId, null, IdentityLinkType.CANDIDATE);  
  3. }  


[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. public void addCandidateGroup(String groupId) {  
  2.   addIdentityLink(null, groupId, IdentityLinkType.CANDIDATE);  
  3. }  


2. IdentityLink与权限过滤

如下查询语句对应于“用户kermit待签收任务列表”的调用过程:

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. Preparing: select distinct RES.* from AC  
  2. T_RU_TASK RES inner join ACT_RU_IDENTITYLINK I on I.TASK_ID_ = RES.ID_ WHERE RES.ASSIGNEE_ is null and I.TYPE_ = 'candidate' and ( I.USER_ID_ = ? or I.GROUP_ID_ IN ( ? , ? ) )   
  3.   
  4. Parameters: kermit(String), admin(String), management(String)  

其中admin和management来自于用户群组关系查询接口:

UserEntityManager.findGroupsByUser("kermit")

0 0
原创粉丝点击