Search in sources :

Example 36 with Group

use of org.camunda.bpm.engine.identity.Group in project camunda-bpm-platform by camunda.

the class IdentityServiceTest method testCreateMembershipAlreadyExisting.

@Test
public void testCreateMembershipAlreadyExisting() {
    Group sales = identityService.newGroup("sales");
    identityService.saveGroup(sales);
    User johndoe = identityService.newUser("johndoe");
    identityService.saveUser(johndoe);
    // Create the membership
    identityService.createMembership(johndoe.getId(), sales.getId());
    thrown.expect(ProcessEngineException.class);
    identityService.createMembership(johndoe.getId(), sales.getId());
}
Also used : Group(org.camunda.bpm.engine.identity.Group) User(org.camunda.bpm.engine.identity.User) Test(org.junit.Test)

Example 37 with Group

use of org.camunda.bpm.engine.identity.Group in project camunda-bpm-platform by camunda.

the class IdentityServiceTest method testDeleteMembershipWhenUserIsNoMember.

@Test
public void testDeleteMembershipWhenUserIsNoMember() {
    Group sales = identityService.newGroup("sales");
    identityService.saveGroup(sales);
    User johndoe = identityService.newUser("johndoe");
    identityService.saveUser(johndoe);
    // Delete the membership when the user is no member
    identityService.deleteMembership(johndoe.getId(), sales.getId());
    identityService.deleteGroup("sales");
    identityService.deleteUser("johndoe");
}
Also used : Group(org.camunda.bpm.engine.identity.Group) User(org.camunda.bpm.engine.identity.User) Test(org.junit.Test)

Example 38 with Group

use of org.camunda.bpm.engine.identity.Group in project camunda-bpm-platform by camunda.

the class IdentityServiceTest method testUpdateGroup.

@Test
public void testUpdateGroup() {
    Group group = identityService.newGroup("sales");
    group.setName("Sales");
    identityService.saveGroup(group);
    group = identityService.createGroupQuery().groupId("sales").singleResult();
    group.setName("Updated");
    identityService.saveGroup(group);
    group = identityService.createGroupQuery().groupId("sales").singleResult();
    assertEquals("Updated", group.getName());
    identityService.deleteGroup(group.getId());
}
Also used : Group(org.camunda.bpm.engine.identity.Group) Test(org.junit.Test)

Example 39 with Group

use of org.camunda.bpm.engine.identity.Group in project camunda-bpm-platform by camunda.

the class IdentityServiceTest method testFindGroupsByUserAndType.

@Test
public void testFindGroupsByUserAndType() {
    Group sales = identityService.newGroup("sales");
    sales.setType("hierarchy");
    identityService.saveGroup(sales);
    Group development = identityService.newGroup("development");
    development.setType("hierarchy");
    identityService.saveGroup(development);
    Group admin = identityService.newGroup("admin");
    admin.setType("security-role");
    identityService.saveGroup(admin);
    Group user = identityService.newGroup("user");
    user.setType("security-role");
    identityService.saveGroup(user);
    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("johndoe", "user");
    identityService.createMembership("johndoe", "admin");
    identityService.createMembership("joesmoe", "user");
    List<Group> groups = identityService.createGroupQuery().groupMember("johndoe").groupType("security-role").list();
    Set<String> groupIds = getGroupIds(groups);
    Set<String> expectedGroupIds = new HashSet<String>();
    expectedGroupIds.add("user");
    expectedGroupIds.add("admin");
    assertEquals(expectedGroupIds, groupIds);
    groups = identityService.createGroupQuery().groupMember("joesmoe").groupType("security-role").list();
    groupIds = getGroupIds(groups);
    expectedGroupIds = new HashSet<String>();
    expectedGroupIds.add("user");
    assertEquals(expectedGroupIds, groupIds);
    groups = identityService.createGroupQuery().groupMember("jackblack").groupType("security-role").list();
    assertTrue(groups.isEmpty());
    identityService.deleteGroup("sales");
    identityService.deleteGroup("development");
    identityService.deleteGroup("admin");
    identityService.deleteGroup("user");
    identityService.deleteUser("johndoe");
    identityService.deleteUser("joesmoe");
    identityService.deleteUser("jackblack");
}
Also used : Group(org.camunda.bpm.engine.identity.Group) User(org.camunda.bpm.engine.identity.User) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 40 with Group

use of org.camunda.bpm.engine.identity.Group in project camunda-bpm-platform by camunda.

the class WriteMultipleEntitiesInOneTransactionTest method testWriteMultipleEntitiesInOneTransaction.

public void testWriteMultipleEntitiesInOneTransaction() {
    // the identity service provider registered with the engine creates a user, a group, and a membership
    // in the following call:
    Assert.assertTrue(identityService.checkPassword("multipleEntities", "inOneStep"));
    User user = identityService.createUserQuery().userId("multipleEntities").singleResult();
    Assert.assertNotNull(user);
    Assert.assertEquals("multipleEntities", user.getId());
    Assert.assertEquals("{SHA}pfdzmt+49nwknTy7xhZd7ZW5suI=", user.getPassword());
    // It is expected, that the User is in exactly one Group
    List<Group> groups = this.identityService.createGroupQuery().groupMember("multipleEntities").list();
    Assert.assertEquals(1, groups.size());
    Group group = groups.get(0);
    Assert.assertEquals("multipleEntities_group", group.getId());
    // clean the Db
    identityService.deleteMembership("multipleEntities", "multipleEntities_group");
    identityService.deleteGroup("multipleEntities_group");
    identityService.deleteUser("multipleEntities");
}
Also used : Group(org.camunda.bpm.engine.identity.Group) User(org.camunda.bpm.engine.identity.User)

Aggregations

Group (org.camunda.bpm.engine.identity.Group)92 Test (org.junit.Test)34 User (org.camunda.bpm.engine.identity.User)29 GroupQuery (org.camunda.bpm.engine.identity.GroupQuery)22 Authorization (org.camunda.bpm.engine.authorization.Authorization)13 ArrayList (java.util.ArrayList)12 Matchers.anyString (org.mockito.Matchers.anyString)12 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)10 MissingAuthorization (org.camunda.bpm.engine.authorization.MissingAuthorization)9 Tenant (org.camunda.bpm.engine.identity.Tenant)9 IdentityService (org.camunda.bpm.engine.IdentityService)7 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)7 UserQuery (org.camunda.bpm.engine.identity.UserQuery)4 Authentication (org.camunda.bpm.engine.impl.identity.Authentication)4 Before (org.junit.Before)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 AuthorizationService (org.camunda.bpm.engine.AuthorizationService)3 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)3 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)2