Search in sources :

Example 66 with User

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

the class GroupMembershipResourceTest method testCreatemembership.

public void testCreatemembership() throws Exception {
    try {
        Group testGroup = identityService.newGroup("testgroup");
        testGroup.setName("Test group");
        testGroup.setType("Test type");
        identityService.saveGroup(testGroup);
        User testUser = identityService.newUser("testuser");
        identityService.saveUser(testUser);
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("userId", "testuser");
        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_MEMBERSHIP_COLLECTION, "testgroup"));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertNotNull(responseNode);
        assertEquals("testuser", responseNode.get("userId").textValue());
        assertEquals("testgroup", responseNode.get("groupId").textValue());
        assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_MEMBERSHIP, testGroup.getId(), testUser.getId())));
        Group createdGroup = identityService.createGroupQuery().groupId("testgroup").singleResult();
        assertNotNull(createdGroup);
        assertEquals("Test group", createdGroup.getName());
        assertEquals("Test type", createdGroup.getType());
        assertNotNull(identityService.createUserQuery().memberOfGroup("testgroup").singleResult());
        assertEquals("testuser", identityService.createUserQuery().memberOfGroup("testgroup").singleResult().getId());
    } finally {
        try {
            identityService.deleteGroup("testgroup");
        } catch (Throwable ignore) {
        // Ignore, since the group may not have been created in the test
        // or already deleted
        }
        try {
            identityService.deleteUser("testuser");
        } catch (Throwable ignore) {
        // Ignore, since the group may not have been created in the test
        // or already deleted
        }
    }
}
Also used : Group(org.activiti.engine.identity.Group) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) User(org.activiti.engine.identity.User) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 67 with User

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

the class GroupMembershipResourceTest method testDeleteMembershipNoMember.

/**
   * Test delete membership that is no member in the group.
   */
public void testDeleteMembershipNoMember() throws Exception {
    try {
        Group testGroup = identityService.newGroup("testgroup");
        testGroup.setName("Test group");
        testGroup.setType("Test type");
        identityService.saveGroup(testGroup);
        User testUser = identityService.newUser("testuser");
        identityService.saveUser(testUser);
        HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_MEMBERSHIP, "testgroup", "testuser"));
        closeResponse(executeRequest(httpDelete, HttpStatus.SC_NOT_FOUND));
    } finally {
        try {
            identityService.deleteGroup("testgroup");
        } catch (Throwable ignore) {
        // Ignore, since the group may not have been created in the test
        // or already deleted
        }
        try {
            identityService.deleteUser("testuser");
        } catch (Throwable ignore) {
        // Ignore, since the group may not have been created in the test
        // or already deleted
        }
    }
}
Also used : Group(org.activiti.engine.identity.Group) User(org.activiti.engine.identity.User) HttpDelete(org.apache.http.client.methods.HttpDelete)

Example 68 with User

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

the class GroupMembershipResourceTest method testDeleteMembership.

public void testDeleteMembership() throws Exception {
    try {
        Group testGroup = identityService.newGroup("testgroup");
        testGroup.setName("Test group");
        testGroup.setType("Test type");
        identityService.saveGroup(testGroup);
        User testUser = identityService.newUser("testuser");
        identityService.saveUser(testUser);
        identityService.createMembership("testuser", "testgroup");
        HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_MEMBERSHIP, "testgroup", "testuser"));
        CloseableHttpResponse response = executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT);
        closeResponse(response);
        // Check if membership is actually deleted
        assertNull(identityService.createUserQuery().memberOfGroup("testgroup").singleResult());
    } finally {
        try {
            identityService.deleteGroup("testgroup");
        } catch (Throwable ignore) {
        // Ignore, since the group may not have been created in the test
        // or already deleted
        }
        try {
            identityService.deleteUser("testuser");
        } catch (Throwable ignore) {
        // Ignore, since the group may not have been created in the test
        // or already deleted
        }
    }
}
Also used : Group(org.activiti.engine.identity.Group) User(org.activiti.engine.identity.User) HttpDelete(org.apache.http.client.methods.HttpDelete) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 69 with User

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

the class DemoDataConfiguration method createUser.

protected void createUser(String userId, String firstName, String lastName, String password, String email, String imageResource, List<String> groups, List<String> userInfo) {
    if (identityService.createUserQuery().userId(userId).count() == 0) {
        // Following data can already be set by demo setup script
        User user = identityService.newUser(userId);
        user.setFirstName(firstName);
        user.setLastName(lastName);
        user.setPassword(password);
        user.setEmail(email);
        identityService.saveUser(user);
        if (groups != null) {
            for (String group : groups) {
                identityService.createMembership(userId, group);
            }
        }
    }
    // image
    if (imageResource != null) {
        byte[] pictureBytes = IoUtil.readInputStream(this.getClass().getClassLoader().getResourceAsStream(imageResource), null);
        Picture picture = new Picture(pictureBytes, "image/jpeg");
        identityService.setUserPicture(userId, picture);
    }
    // user info
    if (userInfo != null) {
        for (int i = 0; i < userInfo.size(); i += 2) {
            identityService.setUserInfo(userId, userInfo.get(i), userInfo.get(i + 1));
        }
    }
}
Also used : User(org.activiti.engine.identity.User) Picture(org.activiti.engine.identity.Picture)

Example 70 with User

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

the class Application method usersAndGroupsInitializer.

@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 joram = identityService.newUser("jbarrez");
            joram.setFirstName("Joram");
            joram.setLastName("Barrez");
            joram.setPassword("password");
            identityService.saveUser(joram);
            User josh = identityService.newUser("jlong");
            josh.setFirstName("Josh");
            josh.setLastName("Long");
            josh.setPassword("password");
            identityService.saveUser(josh);
            identityService.createMembership("jbarrez", "user");
            identityService.createMembership("jlong", "user");
        }
    };
}
Also used : Group(org.activiti.engine.identity.Group) User(org.activiti.engine.identity.User) InitializingBean(org.springframework.beans.factory.InitializingBean) Bean(org.springframework.context.annotation.Bean) InitializingBean(org.springframework.beans.factory.InitializingBean)

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