用户
在各种需要人工参与的系统中,用户和组时一个身份系统或者模块的基础,在flowable中用户和组主要是应用于用户任务
本文章此次只示例组的基本用法,明天更新附带逻辑的demo
第一步 导包
<dependency> <groupId>org.flowable</groupId> <artifactId>flowable-bpmn-layout</artifactId> <version>6.3.0</version> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <version>1.3.176</version> </dependency>
第二步 增加名为 flowable.cfg.xml 的配置文件放在 resources 目录下
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="processEngineConfiguration" class="org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration"> <property name="jdbcUrl" value="jdbc:h2:mem:flowable;DB_CLOSE_DELAY=1000" /> <property name="jdbcDriver" value="org.h2.Driver" /> <property name="jdbcUsername" value="sa" /> <property name="jdbcPassword" value="" /> <property name="databaseSchemaUpdate" value="true" /> <property name="asyncExecutorActivate" value="false" /> <property name="mailServerHost" value="mail.my-corp.com" /> <property name="mailServerPort" value="5025" /> </bean> </beans>
第三步 新建测试类
//配置文件 @Rule public FlowableRule flowableRule = new FlowableRule("flowable.cfg.xml"); @Test public void testUser(){ //获取identityService 实例 IdentityService identityService = flowableRule.getIdentityService(); //创建一个用户对象 User user = identityService.newUser("hello_"); user.setFirstName("Hello"); user.setLastName("_"); user.setEmail("475591383@qq.com"); //保存用户到数据库 identityService.saveUser(user); //验证用户是否保存成功 User userInDb = identityService.createUserQuery().userId("hello_").singleResult(); Assert.assertNotNull(userInDb); //删除用户 identityService.deleteUser("hello_"); userInDb = identityService.createUserQuery().userId("hello_").singleResult(); Assert.assertNull(userInDb); }
组
组时权限控制的一种方式,属于某个组的用户就拥有操作某些功能的权限。
在flowabke中,组的类型分为两种,及assignment和security-role,前者Wie一种普通的岗位角色,是用户分配业务中的功能权限,后者是安全角色,可以从全局管理用户组织及整个流程的状态
@Test public void testGroup(){ //获取identityService 实例 IdentityService identityService = flowableRule.getIdentityService(); //创建一个用户对象 Group group = identityService.newGroup("deptLeader"); group.setName("部门领导"); group.setType("assignment"); //保存组到数据库 identityService.saveGroup(group); //验证是否保存成功 List<Group> groupList = identityService.createGroupQuery().groupId("deptLeader").list(); Assert.assertEquals(1, groupList.size()); //删除 identityService.deleteGroup("deptLeader"); groupList = identityService.createGroupQuery().groupId("deptLeader").list(); //是否删除成功 Assert.assertEquals(0, groupList.size()); }
用户和组
组和用户单独存在只是一盘散沙,下面代码展示设置组和用户的关系
@Test public void testUserAndGroup(){ //创建并保存组对象 IdentityService identityService = flowableRule.getIdentityService(); Group group = identityService.newGroup("deptLeader"); group.setName("部门领导"); group.setType("assignment"); identityService.saveGroup(group); //创建并保存用户对象 User user = identityService.newUser("hello_"); user.setFirstName("Hello"); user.setLastName("_"); user.setEmail("475591383@qq.com"); identityService.saveUser(user); //将用户hello放入deptLeader中 identityService.createMembership("hello_", "deptLeader"); User userInGroup = identityService.createUserQuery().memberOfGroup("deptLeader").singleResult(); Assert.assertNotNull(userInGroup); Assert.assertEquals("hello_", user.getId()); //查询组信息 Group groupContainsHello = identityService.createGroupQuery().groupMember("hello_").singleResult(); Assert.assertNotNull(groupContainsHello); Assert.assertEquals("deptLeader", groupContainsHello.getId()); }
来源:博客园
作者:廖海龙
链接:https://www.cnblogs.com/liaohailong/p/11570004.html