Activiti 工作流入门 (5) 用户/组 管理

Submitted by Lizhe on Wed, 11/08/2017 - 11:32

在需要人工参与的系统中, 用户和组是身份系统的基础, 在Activiti中用户和组主要是应用于用户任务(UserTAsk)

用api创建和查询一个用户

import org.activiti.engine.IdentityService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.identity.User;
import org.activiti.engine.repository.Deployment;
import org.junit.Test;

public class TestAct {

    @Test
    public void test() throws InterruptedException {

        ProcessEngine processEngine = ProcessEngineConfiguration
                .createProcessEngineConfigurationFromResource("activiti.cfg.xml").buildProcessEngine();

        IdentityService identityService = processEngine.getIdentityService();
        
        identityService.deleteUser("lz");
        
        User lz = identityService.newUser("lz");
        lz.setFirstName("Zhe");
        lz.setLastName("Li");
        lz.setEmail("mail@mail.com");
        identityService.saveUser(lz);
        
        User result = identityService.createUserQuery().userId("lz").singleResult();
        System.out.println(result.getEmail());

    }

}

 

组是控制权限的一种方式,属于某个组的用户会获得这个组的权限

在Activiti中,组的类型分为两种 assignment 和 security-role, 前者是一种普通的岗位角色,后者是安全角色

 

import java.util.List;

import org.activiti.engine.IdentityService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.identity.Group;
import org.activiti.engine.identity.User;
import org.activiti.engine.repository.Deployment;
import org.junit.Test;

public class TestGroup {

    @Test
    public void test() throws InterruptedException {

        ProcessEngine processEngine = ProcessEngineConfiguration
                .createProcessEngineConfigurationFromResource("activiti.cfg.xml").buildProcessEngine();

        IdentityService identityService = processEngine.getIdentityService();
        
        identityService.deleteGroup("deptManager");
        
        Group deptManager = identityService.newGroup("deptManager");
        deptManager.setName("Dept Manager");
        deptManager.setType("assignment");
        identityService.saveGroup(deptManager);
        
        List<Group> result = identityService.createGroupQuery().groupId("deptManager").list();
        for(Group g:result){
            System.out.println(g.getName());
        }

    }

}