Java Code Examples for org.flowable.idm.api.Group#setType()

The following examples show how to use org.flowable.idm.api.Group#setType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroupServiceImpl.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public Group createNewGroup(String id, String name, String type) {
    if (StringUtils.isBlank(name)) {
        throw new BadRequestException("Group name required");
    }

    Group newGroup = identityService.newGroup(id);
    newGroup.setName(name);

    if (type == null) {
        newGroup.setType(GroupTypes.TYPE_ASSIGNMENT);
    } else {
        newGroup.setType(type);
    }

    identityService.saveGroup(newGroup);
    return newGroup;
}
 
Example 2
Source File: GroupResourceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Test deleting a single group.
 */
@Test
public void testDeleteGroup() throws Exception {
    try {
        Group testGroup = identityService.newGroup("testgroup");
        testGroup.setName("Test group");
        testGroup.setType("Test type");
        identityService.saveGroup(testGroup);

        closeResponse(executeRequest(new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, "testgroup")), HttpStatus.SC_NO_CONTENT));

        assertThat(identityService.createGroupQuery().groupId("testgroup").singleResult()).isNull();

    } finally {
        try {
            identityService.deleteGroup("testgroup");
        } catch (Throwable ignore) {
            // Ignore, since the group may not have been created in the test
            // or already deleted
        }
    }
}
 
Example 3
Source File: Application.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Bean
InitializingBean usersAndGroupsInitializer(final IdentityService identityService) {

    return new InitializingBean() {
        @Override
        public void afterPropertiesSet() throws Exception {

            // install groups & users
            Group group = identityService.newGroup("user");
            group.setName("users");
            group.setType("security-role");
            identityService.saveGroup(group);

            User josh = identityService.newUser("jlong");
            josh.setFirstName("Josh");
            josh.setLastName("Long");
            josh.setPassword("password");
            identityService.saveUser(josh);

            identityService.createMembership("jlong", "user");
        }
    };
}
 
Example 4
Source File: GroupResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Update a group", tags = {
        "Groups" }, notes = "All request values are optional. For example, you can only include the name attribute in the request body JSON-object, only updating the name of the group, leaving all other fields unaffected. When an attribute is explicitly included and is set to null, the group-value will be updated to null.")
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Indicates the group was updated."),
        @ApiResponse(code = 404, message = "Indicates the requested group was not found."),
        @ApiResponse(code = 409, message = "Indicates the requested group was updated simultaneously.")
})
@PutMapping(value = "/identity/groups/{groupId}", produces = "application/json")
public GroupResponse updateGroup(@ApiParam(name = "groupId") @PathVariable String groupId, @RequestBody GroupRequest groupRequest, HttpServletRequest request) {
    Group group = getGroupFromRequest(groupId);

    if (groupRequest.getId() == null || groupRequest.getId().equals(group.getId())) {
        if (groupRequest.isNameChanged()) {
            group.setName(groupRequest.getName());
        }
        if (groupRequest.isTypeChanged()) {
            group.setType(groupRequest.getType());
        }
        identityService.saveGroup(group);
    } else {
        throw new FlowableIllegalArgumentException("Key provided in request body does not match the key in the resource URL.");
    }

    return restResponseFactory.createGroupResponse(group);
}
 
Example 5
Source File: PluggableFlowableIdmTestCase.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected Group createGroup(String id, String name, String type) {
    Group group = idmIdentityService.newGroup(id);
    group.setName(name);
    group.setType(type);
    idmIdentityService.saveGroup(group);
    return group;
}
 
Example 6
Source File: GroupQueryTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private Group createGroup(String id, String name, String type) {
    Group group = identityService.newGroup(id);
    group.setName(name);
    group.setType(type);
    identityService.saveGroup(group);
    return group;
}
 
Example 7
Source File: GroupCollectionResource.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Create a group", tags = { "Groups" })
@ApiResponses(value = {
        @ApiResponse(code = 201, message = "Indicates the group was created."),
        @ApiResponse(code = 400, message = "Indicates the id of the group was missing.")
})
@PostMapping(value = "/groups", produces = "application/json")
public GroupResponse createGroup(@RequestBody GroupRequest groupRequest, HttpServletRequest httpRequest, HttpServletResponse response) {
    if (groupRequest.getId() == null) {
        throw new FlowableIllegalArgumentException("Id cannot be null.");
    }

    // Check if a user with the given ID already exists so we return a CONFLICT
    if (identityService.createGroupQuery().groupId(groupRequest.getId()).count() > 0) {
        throw new FlowableConflictException("A group with id '" + groupRequest.getId() + "' already exists.");
    }

    Group created = identityService.newGroup(groupRequest.getId());
    created.setId(groupRequest.getId());
    created.setName(groupRequest.getName());
    created.setType(groupRequest.getType());
    
    if (restApiInterceptor != null) {
        restApiInterceptor.createNewGroup(created);
    }
    
    identityService.saveGroup(created);

    response.setStatus(HttpStatus.CREATED.value());

    return restResponseFactory.createGroupResponse(created);
}
 
Example 8
Source File: GroupResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Test getting a single group.
 */
@Test
public void testGetGroup() throws Exception {
    try {
        Group testGroup = identityService.newGroup("testgroup");
        testGroup.setName("Test group");
        testGroup.setType("Test type");
        identityService.saveGroup(testGroup);

        CloseableHttpResponse response = executeRequest(
                new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, "testgroup")), HttpStatus.SC_OK);

        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertThat(responseNode).isNotNull();
        assertThatJson(responseNode)
                .when(Option.IGNORING_EXTRA_FIELDS)
                .isEqualTo("{"
                        + " id: 'testgroup',"
                        + " name: 'Test group',"
                        + " type: 'Test type',"
                        + " url: '" + SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, testGroup.getId()) + "'"
                        + "}");

        Group createdGroup = identityService.createGroupQuery().groupId("testgroup").singleResult();
        assertThat(createdGroup).isNotNull();
        assertThat(createdGroup.getName()).isEqualTo("Test group");
        assertThat(createdGroup.getType()).isEqualTo("Test type");

    } finally {
        try {
            identityService.deleteGroup("testgroup");
        } catch (Throwable ignore) {
            // Ignore, since the group may not have been created in the test
            // or already deleted
        }
    }
}
 
Example 9
Source File: GroupCollectionResource.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Create a group", tags = { "Groups" })
@ApiResponses(value = {
        @ApiResponse(code = 201, message = "Indicates the group was created."),
        @ApiResponse(code = 400, message = "Indicates the id of the group was missing.")
})
@PostMapping(value = "/identity/groups", produces = "application/json")
public GroupResponse createGroup(@RequestBody GroupRequest groupRequest, HttpServletRequest httpRequest, HttpServletResponse response) {
    if (groupRequest.getId() == null) {
        throw new FlowableIllegalArgumentException("Id cannot be null.");
    }
    
    if (restApiInterceptor != null) {
        restApiInterceptor.createGroup(groupRequest);
    }

    // Check if a user with the given ID already exists so we return a CONFLICT
    if (identityService.createGroupQuery().groupId(groupRequest.getId()).count() > 0) {
        throw new FlowableConflictException("A group with id '" + groupRequest.getId() + "' already exists.");
    }

    Group created = identityService.newGroup(groupRequest.getId());
    created.setId(groupRequest.getId());
    created.setName(groupRequest.getName());
    created.setType(groupRequest.getType());
    identityService.saveGroup(created);

    response.setStatus(HttpStatus.CREATED.value());

    return restResponseFactory.createGroupResponse(created);
}
 
Example 10
Source File: Sample15RestApplication.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Bean
public CommandLineRunner usersAndGroupsInitializer(final IdentityService identityService) {
    return args -> {
        // install groups & users
        Group group = identityService.newGroup("user");
        group.setName("users");
        group.setType("security-role");
        identityService.saveGroup(group);

        User joram = identityService.newUser("jbarrez");
        joram.setFirstName("Joram");
        joram.setLastName("Barrez");
        joram.setPassword("password");
        identityService.saveUser(joram);

        User filip = identityService.newUser("filiphr");
        filip.setFirstName("Filip");
        filip.setLastName("Hrisafov");
        filip.setPassword("password");
        identityService.saveUser(filip);

        User josh = identityService.newUser("jlong");
        josh.setFirstName("Josh");
        josh.setLastName("Long");
        josh.setPassword("password");
        identityService.saveUser(josh);

        identityService.createMembership("jbarrez", "user");
        identityService.createMembership("filiphr", "user");
        identityService.createMembership("jlong", "user");
    };
}
 
Example 11
Source File: GroupQueryTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private Group createGroup(String id, String name, String type) {
    Group group = identityService.newGroup(id);
    group.setName(name);
    group.setType(type);
    identityService.saveGroup(group);
    return group;
}
 
Example 12
Source File: GroupQueryEscapeClauseTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private Group createGroup(String id, String name, String type) {
    Group group = idmIdentityService.newGroup(id);
    group.setName(name);
    group.setType(type);
    idmIdentityService.saveGroup(group);
    return group;
}
 
Example 13
Source File: AiaGroupEntityManager.java    From plumdo-work with Apache License 2.0 5 votes vote down vote up
@Override
public List<Group> findGroupByQueryCriteria(GroupQueryImpl query) {
    List<Group> groups = new ArrayList<>();
    ObjectMap response = restClient.getForIdentityService("/groups", queryToParams(query), ObjectMap.class);
    List<ObjectMap> dataMap = response.getAsList("data");
    for (ObjectMap groupMap : dataMap) {
        Group group = new GroupEntityImpl();
        group.setId(groupMap.getAsString("id"));
        group.setName(groupMap.getAsString("name"));
        group.setType(groupMap.getAsString("type"));
        groups.add(group);
    }
    return groups;
}
 
Example 14
Source File: Application.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Bean
CommandLineRunner seedUsersAndGroups(final IdmIdentityService identityService) {
    return new CommandLineRunner() {
        @Override
        public void run(String... strings) throws Exception {

            // install groups & users
            Group adminGroup = identityService.newGroup("admin");
            adminGroup.setName("admin");
            adminGroup.setType("security-role");
            identityService.saveGroup(adminGroup);

            Group group = identityService.newGroup("user");
            group.setName("users");
            group.setType("security-role");
            identityService.saveGroup(group);

            Privilege userPrivilege = identityService.createPrivilege("user-privilege");
            identityService.addGroupPrivilegeMapping(userPrivilege.getId(), group.getId());

            Privilege adminPrivilege = identityService.createPrivilege("admin-privilege");

            User joram = identityService.newUser("jbarrez");
            joram.setFirstName("Joram");
            joram.setLastName("Barrez");
            joram.setPassword("password");
            identityService.saveUser(joram);
            identityService.addUserPrivilegeMapping(adminPrivilege.getId(), joram.getId());

            User filip = identityService.newUser("filiphr");
            filip.setFirstName("Filip");
            filip.setLastName("Hrisafov");
            filip.setPassword("password");
            identityService.saveUser(filip);

            User josh = identityService.newUser("jlong");
            josh.setFirstName("Josh");
            josh.setLastName("Long");
            josh.setPassword("password");
            identityService.saveUser(josh);

            identityService.createMembership("jbarrez", "user");
            identityService.createMembership("jbarrez", "admin");
            identityService.createMembership("filiphr", "user");
            identityService.createMembership("jlong", "user");
        }
    };
}
 
Example 15
Source File: GroupCollectionResourceTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * Test getting all groups.
 */
@Test
@Deployment
public void testGetGroups() throws Exception {
    List<Group> savedGroups = new ArrayList<>();
    try {
        Group group1 = identityService.newGroup("testgroup1");
        group1.setName("Test group");
        group1.setType("Test type");
        identityService.saveGroup(group1);
        savedGroups.add(group1);

        Group group2 = identityService.newGroup("testgroup2");
        group2.setName("Another group");
        group2.setType("Another type");
        identityService.saveGroup(group2);
        savedGroups.add(group2);

        Group group3 = identityService.createGroupQuery().groupId("admin").singleResult();
        assertThat(group3).isNotNull();
        
        Group group4 = identityService.createGroupQuery().groupId("sales").singleResult();
        assertThat(group4).isNotNull();

        // Test filter-less
        String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION);
        assertResultsPresentInDataResponse(url, group1.getId(), group2.getId(), group3.getId(), group4.getId());

        // Test based on name
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?name=" + encode("Test group");
        assertResultsPresentInDataResponse(url, group1.getId());

        // Test based on name like
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?nameLike=" + encode("% group");
        assertResultsPresentInDataResponse(url, group2.getId(), group1.getId());

        // Test based on type
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?type=" + encode("Another type");
        assertResultsPresentInDataResponse(url, group2.getId());

        // Test based on group member
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?member=kermit";
        assertResultsPresentInDataResponse(url, group3.getId());

    } finally {

        // Delete groups after test passes or fails
        if (!savedGroups.isEmpty()) {
            for (Group group : savedGroups) {
                identityService.deleteGroup(group.getId());
            }
        }
    }
}
 
Example 16
Source File: IdentityTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
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");
}
 
Example 17
Source File: GroupResourceTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * Test updating a single group.
 */
@Test
public void testUpdateGroup() throws Exception {
    try {
        Group testGroup = identityService.newGroup("testgroup");
        testGroup.setName("Test group");
        testGroup.setType("Test type");
        identityService.saveGroup(testGroup);

        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("name", "Updated group");
        requestNode.put("type", "Updated type");

        HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, "testgroup"));
        httpPut.setEntity(new StringEntity(requestNode.toString()));
        CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);

        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertThat(responseNode).isNotNull();
        assertThatJson(responseNode)
                .when(Option.IGNORING_EXTRA_FIELDS)
                .isEqualTo("{"
                        + " id: 'testgroup',"
                        + " name: 'Updated group',"
                        + " type: 'Updated type',"
                        + " url: '" + SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, testGroup.getId()) + "'"
                        + "}");

        Group createdGroup = identityService.createGroupQuery().groupId("testgroup").singleResult();
        assertThat(createdGroup).isNotNull();
        assertThat(createdGroup.getName()).isEqualTo("Updated group");
        assertThat(createdGroup.getType()).isEqualTo("Updated type");

    } finally {
        try {
            identityService.deleteGroup("testgroup");
        } catch (Throwable ignore) {
            // Ignore, since the group may not have been created in the test
            // or already deleted
        }
    }
}
 
Example 18
Source File: GroupResourceTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * Test updating a single group passing in no fields in the json, user should remain unchanged.
 */
@Test
public void testUpdateGroupNoFields() throws Exception {
    try {
        Group testGroup = identityService.newGroup("testgroup");
        testGroup.setName("Test group");
        testGroup.setType("Test type");
        identityService.saveGroup(testGroup);

        ObjectNode requestNode = objectMapper.createObjectNode();

        HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, "testgroup"));
        httpPut.setEntity(new StringEntity(requestNode.toString()));
        CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);

        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertThat(responseNode).isNotNull();
        assertThatJson(responseNode)
                .when(Option.IGNORING_EXTRA_FIELDS)
                .isEqualTo("{"
                        + " id: 'testgroup',"
                        + " name: 'Test group',"
                        + " type: 'Test type',"
                        + " url: '" + SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, testGroup.getId()) + "'"
                        + "}");

        Group createdGroup = identityService.createGroupQuery().groupId("testgroup").singleResult();
        assertThat(createdGroup).isNotNull();
        assertThat(createdGroup.getName()).isEqualTo("Test group");
        assertThat(createdGroup.getType()).isEqualTo("Test type");

    } finally {
        try {
            identityService.deleteGroup("testgroup");
        } catch (Throwable ignore) {
            // Ignore, since the group may not have been created in the test
            // or already deleted
        }
    }
}
 
Example 19
Source File: GroupResourceTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * Test updating a single user passing in null-values.
 */
@Test
public void testUpdateGroupNullFields() throws Exception {
    try {
        Group testGroup = identityService.newGroup("testgroup");
        testGroup.setName("Test group");
        testGroup.setType("Test type");
        identityService.saveGroup(testGroup);

        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.set("name", null);
        requestNode.set("type", null);

        HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, "testgroup"));
        httpPut.setEntity(new StringEntity(requestNode.toString()));
        CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertThat(responseNode).isNotNull();
        assertThatJson(responseNode)
                .when(Option.IGNORING_EXTRA_FIELDS)
                .isEqualTo("{"
                        + " id: 'testgroup',"
                        + " name: null,"
                        + " type: null,"
                        + " url: '" + SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, testGroup.getId()) + "'"
                        + "}");

        Group createdGroup = identityService.createGroupQuery().groupId("testgroup").singleResult();
        assertThat(createdGroup).isNotNull();
        assertThat(createdGroup.getName()).isNull();
        assertThat(createdGroup.getType()).isNull();

    } finally {
        try {
            identityService.deleteGroup("testgroup");
        } catch (Throwable ignore) {
            // Ignore, since the group may not have been created in the test
            // or already deleted
        }
    }
}
 
Example 20
Source File: IdentityTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@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();
    assertThat(groups)
            .extracting(Group::getId)
            .containsExactlyInAnyOrder("user", "admin");

    groups = identityService.createGroupQuery().groupMember("joesmoe").groupType("security-role").list();
    assertThat(groups)
            .extracting(Group::getId)
            .containsExactly("user");

    groups = identityService.createGroupQuery().groupMember("jackblack").groupType("security-role").list();
    assertThat(groups).isEmpty();

    identityService.deleteGroup("sales");
    identityService.deleteGroup("development");
    identityService.deleteGroup("admin");
    identityService.deleteGroup("user");
    identityService.deleteUser("johndoe");
    identityService.deleteUser("joesmoe");
    identityService.deleteUser("jackblack");
}