flowable users and groups

user

In the system needs human intervention, the basic user and group identity system or a module, users and groups in the flowable is mainly used in user tasks

This article is only an example of the group's basic usage, update logic comes tomorrow demo

The first step guide package

        <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>  

The second step of increasing the profile name flowable.cfg.xml on the resources directory

<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>

The third step is to test the new class

   // profile 
    @rule
     public FlowableRule flowableRule = new new FlowableRule ( "flowable.cfg.xml" ); 

    @Test 
    public  void testUser to () {
         // Get identityService example 
        IdentityService identityService = flowableRule.getIdentityService ();
         // Create a user object 
        user = identityService.newUser the user ( "hello_" ); 
        user.setFirstName ( "the Hello" ); 
        user.setLastName ( "_" ); 
        user.setEmail ( "[email protected]" );
         // save the user to the database
        identityService.saveUser (the User);
         // verify user successfully saved 
        the User userInDb = identityService.createUserQuery () userId ( "hello_." ) .singleResult (); 
        Assert.assertNotNull (userInDb); 
        // delete user 
        identityService.deleteUser ( " hello_ " ); 
        userInDb = identityService.createUserQuery () the userId (." hello_ " ) .singleResult (); 
        Assert.assertNull (userInDb); 
    }

 

group

One way to control when the group permissions, belong to a group of users to have permission to operate certain functions.

In flowabke, the group is divided into two types, and the assignment and security-role, the former is Wie a common job roles, assign user permissions functional business, which is a security role, can manage users from the global organization and status of the entire process

    @Test
     public  void TestGroup () {
         // get identityService instance 
        IdentityService identityService = flowableRule.getIdentityService ();
         // create a user object 
        Group Group = identityService.newGroup ( "deptLeader" ); 
        group.setName ( "department heads" ); 
        group.setType ( "Assignment" );
         // save the group database 
        identityService.saveGroup (group);
         // verify successfully saved 
        List <group> groupList = identityService.createGroupQuery () the groupId ( "deptLeader." ) .list () ; 
        Assert.assertEquals ( 1, GroupList.size ());
         // delete 
        identityService.deleteGroup ( "deptLeader" ); 
        groupList = identityService.createGroupQuery () groupId ( "deptLeader." ) .List ();
         // Delete the success 
        Assert.assertEquals (0 , groupList.size ()); 
    }
Users and Groups

Group and users relationship exists only a mess, and the following code shows the user group setting alone

    @Test
     public  void testUserAndGroup () {
         // Create and save a set of objects 
        IdentityService identityService = flowableRule.getIdentityService (); 
        Group Group = identityService.newGroup ( "deptLeader" ); 
        group.setName ( "department heads" ); 
        group.setType ( "the Assignment" ); 
        identityService.saveGroup (Group); 
        // create and save user object in 
        the user = identityService.newUser the user ( "hello_" ); 
        user.setFirstName ( "the Hello" ); 
        user.setLastName ( "_" ); 
        the user .setEmail ("[email protected]");
        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());
    }

 

Guess you like

Origin www.cnblogs.com/liaohailong/p/11570004.html
Recommended