Search in sources :

Example 56 with Group

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

the class IdentityRestServiceImpl method getGroupInfo.

@Override
public GroupInfoDto getGroupInfo(String userId) {
    if (userId == null) {
        throw new InvalidRequestException(Status.BAD_REQUEST, "No user id was supplied");
    }
    IdentityService identityService = getProcessEngine().getIdentityService();
    GroupQuery query = identityService.createGroupQuery();
    List<Group> userGroups = query.groupMember(userId).orderByGroupName().asc().list();
    Set<UserDto> allGroupUsers = new HashSet<UserDto>();
    List<GroupDto> allGroups = new ArrayList<GroupDto>();
    for (Group group : userGroups) {
        List<User> groupUsers = identityService.createUserQuery().memberOfGroup(group.getId()).list();
        for (User user : groupUsers) {
            if (!user.getId().equals(userId)) {
                allGroupUsers.add(new UserDto(user.getId(), user.getFirstName(), user.getLastName()));
            }
        }
        allGroups.add(new GroupDto(group.getId(), group.getName()));
    }
    return new GroupInfoDto(allGroups, allGroupUsers);
}
Also used : Group(org.camunda.bpm.engine.identity.Group) User(org.camunda.bpm.engine.identity.User) UserDto(org.camunda.bpm.engine.rest.dto.task.UserDto) GroupDto(org.camunda.bpm.engine.rest.dto.task.GroupDto) ArrayList(java.util.ArrayList) IdentityService(org.camunda.bpm.engine.IdentityService) GroupQuery(org.camunda.bpm.engine.identity.GroupQuery) GroupInfoDto(org.camunda.bpm.engine.rest.dto.task.GroupInfoDto) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) HashSet(java.util.HashSet)

Example 57 with Group

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

the class GroupResourceImpl method getGroup.

public GroupDto getGroup(UriInfo context) {
    Group dbGroup = findGroupObject();
    if (dbGroup == null) {
        throw new InvalidRequestException(Status.NOT_FOUND, "Group with id " + resourceId + " does not exist");
    }
    GroupDto group = GroupDto.fromGroup(dbGroup);
    return group;
}
Also used : Group(org.camunda.bpm.engine.identity.Group) GroupDto(org.camunda.bpm.engine.rest.dto.identity.GroupDto) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException)

Example 58 with Group

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

the class TenantQueryTest method setUp.

@Before
public void setUp() {
    identityService = engineRule.getIdentityService();
    createTenant(TENANT_ONE, "Tenant_1");
    createTenant(TENANT_TWO, "Tenant_2");
    User user = identityService.newUser(USER);
    identityService.saveUser(user);
    Group group = identityService.newGroup(GROUP);
    identityService.saveGroup(group);
    identityService.createMembership(USER, GROUP);
    identityService.createTenantUserMembership(TENANT_ONE, USER);
    identityService.createTenantGroupMembership(TENANT_TWO, GROUP);
}
Also used : Group(org.camunda.bpm.engine.identity.Group) User(org.camunda.bpm.engine.identity.User) Before(org.junit.Before)

Example 59 with Group

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

the class IdentityServiceTest method testDeleteMembershipUnexistingUser.

@Test
public void testDeleteMembershipUnexistingUser() {
    Group sales = identityService.newGroup("sales");
    identityService.saveGroup(sales);
    // No exception should be thrown when user doesn't exist
    identityService.deleteMembership("unexistinguser", sales.getId());
    identityService.deleteGroup(sales.getId());
}
Also used : Group(org.camunda.bpm.engine.identity.Group) Test(org.junit.Test)

Example 60 with Group

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

the class IdentityServiceTest method testDeleteMembership.

@Test
public void testDeleteMembership() {
    Group sales = identityService.newGroup("sales");
    identityService.saveGroup(sales);
    User johndoe = identityService.newUser("johndoe");
    identityService.saveUser(johndoe);
    // Add membership
    identityService.createMembership(johndoe.getId(), sales.getId());
    List<Group> groups = identityService.createGroupQuery().groupMember(johndoe.getId()).list();
    assertTrue(groups.size() == 1);
    assertEquals("sales", groups.get(0).getId());
    // Delete the membership and check members of sales group
    identityService.deleteMembership(johndoe.getId(), sales.getId());
    groups = identityService.createGroupQuery().groupMember(johndoe.getId()).list();
    assertTrue(groups.size() == 0);
    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)

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