Skip to content
一、IdentityService
  • IdentityService

    • 管理用户(User)
    • 管理用户组(Group)
    • 用户与用户组的关系(Membership)
  • 身份管理服务接口方法调用流程

    image-20200729161914283

  • 相关方法

    image-20200715163046636

  • 具体测试代码:

    java
    package com.laogoubi.coreapi;
    
    import org.activiti.engine.IdentityService;
    import org.activiti.engine.identity.Group;
    import org.activiti.engine.identity.User;
    import org.activiti.engine.test.ActivitiRule;
    import org.apache.commons.lang3.builder.ToStringBuilder;
    import org.apache.commons.lang3.builder.ToStringStyle;
    import org.junit.Rule;
    import org.junit.Test;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    import java.util.List;
    
    /**
     * @ClassName IdentityServiceTest
     * @Description Identity
     * @Author eastern
     * @Date 2020/7/3 下午4:56
     * @Version 1.0
     **/
    public class IdentityServiceTest {
    	private static final Logger logger = LoggerFactory.getLogger(IdentityServiceTest.class);
    
    	@Rule
    	public ActivitiRule activitiRule = new ActivitiRule();
    
    	@Test
    	public void testIdenttity(){
    		IdentityService identityService = activitiRule.getIdentityService();
    		User user1 = identityService.newUser("user1");
    		user1.setEmail("user1@qq.com");
    		User user2 = identityService.newUser("user2");
    		user2.setEmail("user2@qq.com");
    		
        // 保存用户
    		identityService.saveUser(user1);
    		identityService.saveUser(user2);
    		
    		Group group1 = identityService.newGroup("group1");
        // 保存组
    		identityService.saveGroup(group1);
    
    		Group group2 = identityService.newGroup("group2");
    		identityService.saveGroup(group2);
    
    		// 建立关系
    		identityService.createMembership("user1", "group1");
    		identityService.createMembership("user2", "group1");
    		identityService.createMembership("user1", "group2");
    
    		// 根据userId查询
    		User user11 = identityService.createUserQuery().userId("user1").singleResult();
    		user11.setLastName("zhangsan");
    		identityService.saveUser(user11);
    		
        // 查询属于group1组的用户
    		List<User> userList = identityService.createUserQuery().memberOfGroup("group1").listPage(0, 100);
    		for (User user : userList) {
    			logger.info("user = {}", ToStringBuilder.reflectionToString(user, ToStringStyle.JSON_STYLE));
    		}
    		List<Group> groupList = identityService.createGroupQuery().groupMember("user1").listPage(0, 100);
    		for (Group group : groupList) {
    			logger.info("group = {}", ToStringBuilder.reflectionToString(group, ToStringStyle.JSON_STYLE));
    		}
    	}

}

Released under the MIT License.