Search in sources :

Example 31 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class StartAuthorizationTest method testProcessDefinitionList.

// this test checks the list without user constraint
@Deployment
public void testProcessDefinitionList() throws Exception {
    setUpUsersAndGroups();
    try {
        // Process 1 has no potential starters
        ProcessDefinition latestProcessDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process1").singleResult();
        List<User> authorizedUsers = identityService.createUserQuery().potentialStarter(latestProcessDef.getId()).list();
        assertEquals(0, authorizedUsers.size());
        // user1 and user2 are potential Startes of Process2
        latestProcessDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process2").singleResult();
        authorizedUsers = identityService.createUserQuery().potentialStarter(latestProcessDef.getId()).orderByUserId().asc().list();
        assertEquals(2, authorizedUsers.size());
        assertEquals("user1", authorizedUsers.get(0).getId());
        assertEquals("user2", authorizedUsers.get(1).getId());
        // Process 2 has no potential starter groups
        latestProcessDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process2").singleResult();
        List<Group> authorizedGroups = identityService.createGroupQuery().potentialStarter(latestProcessDef.getId()).list();
        assertEquals(0, authorizedGroups.size());
        // Process 3 has 3 groups as authorized starter groups
        latestProcessDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process4").singleResult();
        authorizedGroups = identityService.createGroupQuery().potentialStarter(latestProcessDef.getId()).orderByGroupId().asc().list();
        assertEquals(3, authorizedGroups.size());
        assertEquals("group1", authorizedGroups.get(0).getId());
        assertEquals("group2", authorizedGroups.get(1).getId());
        assertEquals("group3", authorizedGroups.get(2).getId());
        // do not mention user, all processes should be selected
        List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().orderByProcessDefinitionName().asc().list();
        assertEquals(4, processDefinitions.size());
        assertEquals("process1", processDefinitions.get(0).getKey());
        assertEquals("process2", processDefinitions.get(1).getKey());
        assertEquals("process3", processDefinitions.get(2).getKey());
        assertEquals("process4", processDefinitions.get(3).getKey());
        // check user1, process3 has "user1" as only authorized starter, and
        // process2 has two authorized starters, of which one is "user1"
        processDefinitions = repositoryService.createProcessDefinitionQuery().orderByProcessDefinitionName().asc().startableByUser("user1").list();
        assertEquals(2, processDefinitions.size());
        assertEquals("process2", processDefinitions.get(0).getKey());
        assertEquals("process3", processDefinitions.get(1).getKey());
        // "user2" can only start process2
        processDefinitions = repositoryService.createProcessDefinitionQuery().startableByUser("user2").list();
        assertEquals(1, processDefinitions.size());
        assertEquals("process2", processDefinitions.get(0).getKey());
        // no process could be started with "user4"
        processDefinitions = repositoryService.createProcessDefinitionQuery().startableByUser("user4").list();
        assertEquals(0, processDefinitions.size());
        // "userInGroup3" is in "group3" and can start only process4 via group authorization
        processDefinitions = repositoryService.createProcessDefinitionQuery().startableByUser("userInGroup3").list();
        assertEquals(1, processDefinitions.size());
        assertEquals("process4", processDefinitions.get(0).getKey());
        // "userInGroup2" can start process4, via both user and group authorizations
        // but we have to be sure that process4 appears only once
        processDefinitions = repositoryService.createProcessDefinitionQuery().startableByUser("userInGroup2").list();
        assertEquals(1, processDefinitions.size());
        assertEquals("process4", processDefinitions.get(0).getKey());
    } finally {
        tearDownUsersAndGroups();
    }
}
Also used : Group(org.activiti.engine.identity.Group) User(org.activiti.engine.identity.User) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Deployment(org.activiti.engine.test.Deployment)

Example 32 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class TaskCandidateTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    Group accountants = identityService.newGroup("accountancy");
    identityService.saveGroup(accountants);
    Group managers = identityService.newGroup("management");
    identityService.saveGroup(managers);
    Group sales = identityService.newGroup("sales");
    identityService.saveGroup(sales);
    User kermit = identityService.newUser(KERMIT);
    identityService.saveUser(kermit);
    identityService.createMembership(KERMIT, "accountancy");
    User gonzo = identityService.newUser(GONZO);
    identityService.saveUser(gonzo);
    identityService.createMembership(GONZO, "management");
    identityService.createMembership(GONZO, "accountancy");
    identityService.createMembership(GONZO, "sales");
}
Also used : Group(org.activiti.engine.identity.Group) User(org.activiti.engine.identity.User)

Example 33 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class IdentityTest method testMembership.

public void testMembership() {
    Group sales = identityService.newGroup("sales");
    identityService.saveGroup(sales);
    Group development = identityService.newGroup("development");
    identityService.saveGroup(development);
    User johndoe = identityService.newUser("johndoe");
    identityService.saveUser(johndoe);
    User joesmoe = identityService.newUser("joesmoe");
    identityService.saveUser(joesmoe);
    User jackblack = identityService.newUser("jackblack");
    identityService.saveUser(jackblack);
    identityService.createMembership("johndoe", "sales");
    identityService.createMembership("joesmoe", "sales");
    identityService.createMembership("joesmoe", "development");
    identityService.createMembership("jackblack", "development");
    List<Group> groups = identityService.createGroupQuery().groupMember("johndoe").list();
    assertEquals(createStringSet("sales"), getGroupIds(groups));
    groups = identityService.createGroupQuery().groupMember("joesmoe").list();
    assertEquals(createStringSet("sales", "development"), getGroupIds(groups));
    groups = identityService.createGroupQuery().groupMember("jackblack").list();
    assertEquals(createStringSet("development"), getGroupIds(groups));
    List<User> users = identityService.createUserQuery().memberOfGroup("sales").list();
    assertEquals(createStringSet("johndoe", "joesmoe"), getUserIds(users));
    users = identityService.createUserQuery().memberOfGroup("development").list();
    assertEquals(createStringSet("joesmoe", "jackblack"), getUserIds(users));
    identityService.deleteGroup("sales");
    identityService.deleteGroup("development");
    identityService.deleteUser("jackblack");
    identityService.deleteUser("joesmoe");
    identityService.deleteUser("johndoe");
}
Also used : Group(org.activiti.engine.identity.Group) User(org.activiti.engine.identity.User)

Example 34 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class IdentityTest method testUser.

public void testUser() {
    User user = identityService.newUser("johndoe");
    user.setFirstName("John");
    user.setLastName("Doe");
    user.setEmail("johndoe@alfresco.com");
    identityService.saveUser(user);
    user = identityService.createUserQuery().userId("johndoe").singleResult();
    assertEquals("johndoe", user.getId());
    assertEquals("John", user.getFirstName());
    assertEquals("Doe", user.getLastName());
    assertEquals("johndoe@alfresco.com", user.getEmail());
    identityService.deleteUser("johndoe");
}
Also used : User(org.activiti.engine.identity.User)

Example 35 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class IdentityTest method testAuthentication.

public void testAuthentication() {
    User user = identityService.newUser("johndoe");
    user.setPassword("xxx");
    identityService.saveUser(user);
    assertTrue(identityService.checkPassword("johndoe", "xxx"));
    assertFalse(identityService.checkPassword("johndoe", "invalid pwd"));
    identityService.deleteUser("johndoe");
}
Also used : User(org.activiti.engine.identity.User)

Aggregations

User (org.activiti.engine.identity.User)94 Group (org.activiti.engine.identity.Group)22 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 Task (org.activiti.engine.task.Task)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)9 Picture (org.activiti.engine.identity.Picture)9 StringEntity (org.apache.http.entity.StringEntity)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 ArrayList (java.util.ArrayList)7 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)7 HttpPut (org.apache.http.client.methods.HttpPut)7 HttpGet (org.apache.http.client.methods.HttpGet)6 UserQuery (org.activiti.engine.identity.UserQuery)5 HttpDelete (org.apache.http.client.methods.HttpDelete)5 HttpPost (org.apache.http.client.methods.HttpPost)4 Item (com.vaadin.data.Item)3 ActivitiException (org.activiti.engine.ActivitiException)3 IdentityService (org.activiti.engine.IdentityService)3