org.flowable.idm.api.User Java Examples

The following examples show how to use org.flowable.idm.api.User. 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: IdentityServiceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateMembershipAlreadyExisting() {
    Group sales = idmIdentityService.newGroup("sales");
    idmIdentityService.saveGroup(sales);
    User johndoe = idmIdentityService.newUser("johndoe");
    idmIdentityService.saveUser(johndoe);

    // Create the membership
    idmIdentityService.createMembership(johndoe.getId(), sales.getId());

    assertThatThrownBy(() -> idmIdentityService.createMembership(johndoe.getId(), sales.getId()))
            .isInstanceOf(RuntimeException.class);

    idmIdentityService.deleteGroup(sales.getId());
    idmIdentityService.deleteUser(johndoe.getId());
}
 
Example #2
Source File: ModelServiceImpl.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public Model createModel(ModelRepresentation model, String editorJson, User createdBy) {
    Model newModel = new Model();
    newModel.setVersion(1);
    newModel.setName(model.getName());
    newModel.setKey(model.getKey());
    newModel.setModelType(model.getModelType());
    newModel.setCreated(Calendar.getInstance().getTime());
    newModel.setCreatedBy(createdBy.getId());
    newModel.setDescription(model.getDescription());
    newModel.setModelEditorJson(editorJson);
    newModel.setLastUpdated(Calendar.getInstance().getTime());
    newModel.setLastUpdatedBy(createdBy.getId());
    newModel.setTenantId(model.getTenantId());

    persistModel(newModel);
    return newModel;
}
 
Example #3
Source File: CallServiceInServiceTaskTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testMultipleServiceInvocationsFromDelegate() {
    runtimeService.startProcessInstanceByKey("multipleServiceInvocations");

    // The service task should have created a user which is part of the admin group
    User user = identityService.createUserQuery().singleResult();
    assertEquals("Kermit", user.getId());
    Group group = identityService.createGroupQuery().groupMember(user.getId()).singleResult();
    assertNotNull(group);
    assertEquals("admin", group.getId());

    // Cleanup
    identityService.deleteUser("Kermit");
    identityService.deleteGroup("admin");
    identityService.deleteMembership("Kermit", "admin");
}
 
Example #4
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 #5
Source File: IdentityServiceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testUserPicture() {
    // First, create a new user
    User user = identityService.newUser("johndoe");
    identityService.saveUser(user);
    String userId = user.getId();

    Picture picture = new Picture("niceface".getBytes(), "image/string");
    identityService.setUserPicture(userId, picture);

    picture = identityService.getUserPicture(userId);

    // Fetch and update the user
    user = identityService.createUserQuery().userId("johndoe").singleResult();
    assertThat(Arrays.equals("niceface".getBytes(), picture.getBytes())).as("byte arrays differ").isTrue();
    assertThat(picture.getMimeType()).isEqualTo("image/string");

    // interface definition states that setting picture to null should delete it
    identityService.setUserPicture(userId, null);
    assertThat(identityService.getUserPicture(userId)).as("it should be possible to nullify user picture").isNull();
    user = identityService.createUserQuery().userId("johndoe").singleResult();
    assertThat(identityService.getUserPicture(userId)).as("it should be possible to delete user picture").isNull();

    identityService.deleteUser(user.getId());
}
 
Example #6
Source File: SpringIdmTransactionsTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateMemberships() {
    Group group = identityService.newGroup("group");
    User tom = identityService.newUser("tom");
    User mat = identityService.newUser("mat");

    // save group
    identityService.saveGroup(group);
    // save users
    identityService.saveUser(tom);
    identityService.saveUser(mat);
    // create memberships
    identityService.createMembership(tom.getId(), group.getId());
    identityService.createMembership(mat.getId(), group.getId());

    // verify that the group has been created
    assertThat(identityService.createGroupQuery().groupId(group.getId()).singleResult()).isNotNull();
    // verify that the users have been created
    assertThat(identityService.createUserQuery().userId(tom.getId()).singleResult()).isNotNull();
    assertThat(identityService.createUserQuery().userId(mat.getId()).singleResult()).isNotNull();
    // verify that the users are members of the group
    assertThat(identityService.createGroupQuery().groupMember(tom.getId()).singleResult()).isNotNull();
    assertThat(identityService.createGroupQuery().groupMember(mat.getId()).singleResult()).isNotNull();
}
 
Example #7
Source File: IdentityServiceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testUserOptimisticLockingException() {
    User user = identityService.newUser("kermit");
    identityService.saveUser(user);

    User user1 = identityService.createUserQuery().singleResult();
    User user2 = identityService.createUserQuery().singleResult();

    user1.setFirstName("name one");
    identityService.saveUser(user1);

    assertThatThrownBy(() -> {
        user2.setFirstName("name two");
        identityService.saveUser(user2);
    })
            .isExactlyInstanceOf(FlowableOptimisticLockingException.class);

    identityService.deleteUser(user.getId());
}
 
Example #8
Source File: FlowableTaskService.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public List<TaskRepresentation> getSubTasks(String taskId) {
    User currentUser = SecurityUtils.getCurrentUserObject();
    HistoricTaskInstance parentTask = permissionService.validateReadPermissionOnTask(currentUser, taskId);
    
    List<Task> subTasks = this.taskService.getSubTasks(taskId);
    List<TaskRepresentation> subTasksRepresentations = new ArrayList<>(subTasks.size());
    for (Task subTask : subTasks) {
        TaskRepresentation representation = new TaskRepresentation(subTask, parentTask);
        
        fillPermissionInformation(representation, subTask, currentUser);
        populateAssignee(subTask, representation);
        representation.setInvolvedPeople(getInvolvedUsers(subTask.getId()));
        
        subTasksRepresentations.add(representation);
    }
    
    return subTasksRepresentations;
}
 
Example #9
Source File: PersistentTokenServiceImpl.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public Token createToken(User user, String remoteAddress, String userAgent) {

    Token token = idmIdentityService.newToken(generateSeriesData());
    token.setTokenValue(generateTokenData());
    token.setTokenDate(new Date());
    token.setIpAddress(remoteAddress);
    token.setUserAgent(userAgent);
    token.setUserId(user.getId());

    try {
        saveAndFlush(token);
        return token;
    } catch (DataAccessException e) {
        LOGGER.error("Failed to save persistent token ", e);
        return token;
    }
}
 
Example #10
Source File: IdentityServiceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@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();
    assertThat(groups)
            .extracting(Group::getId)
            .containsExactly("sales");

    // Delete the membership and check members of sales group
    identityService.deleteMembership(johndoe.getId(), sales.getId());
    groups = identityService.createGroupQuery().groupMember(johndoe.getId()).list();
    assertThat(groups).isEmpty();

    identityService.deleteGroup("sales");
    identityService.deleteUser("johndoe");
}
 
Example #11
Source File: FlowableProcessInstanceQueryService.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected List<ProcessInstanceRepresentation> convertInstanceList(List<HistoricProcessInstance> instances) {
    List<ProcessInstanceRepresentation> result = new ArrayList<>();
    if (CollectionUtils.isNotEmpty(instances)) {

        for (HistoricProcessInstance processInstance : instances) {
            User userRep = null;
            if (processInstance.getStartUserId() != null) {
                CachedUser user = userCache.getUser(processInstance.getStartUserId());
                if (user != null && user.getUser() != null) {
                    userRep = user.getUser();
                }
            }

            ProcessDefinitionEntity procDef = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId());
            ProcessInstanceRepresentation instanceRepresentation = new ProcessInstanceRepresentation(processInstance, procDef, procDef.isGraphicalNotationDefined(), userRep);
            result.add(instanceRepresentation);
        }

    }
    return result;
}
 
Example #12
Source File: IdentityServiceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateUserWithoutTenantId() {
    // First, create a new user
    User user = identityService.newUser("johndoe");
    user.setFirstName("John");
    user.setLastName("Doe");
    user.setEmail("[email protected]");
    identityService.saveUser(user);

    // Fetch and update the user
    user = identityService.createUserQuery().userId("johndoe").singleResult();
    assertThat(user.getFirstName()).isEqualTo("John");
    assertThat(user.getLastName()).isEqualTo("Doe");
    assertThat(user.getEmail()).isEqualTo("[email protected]");
    assertThat(user.getTenantId()).isNull();

    identityService.deleteUser(user.getId());
}
 
Example #13
Source File: FlowableTaskActionService.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void assignTask(User currentUser, Task task, String assigneeIdString) {
    try {
        String oldAssignee = task.getAssignee();
        taskService.setAssignee(task.getId(), assigneeIdString);

        // If the old assignee user wasn't part of the involved users yet, make it so
        addIdentiyLinkForUser(task, oldAssignee, IdentityLinkType.PARTICIPANT);

        // If the current user wasn't part of the involved users yet, make it so
        String currentUserIdString = String.valueOf(currentUser.getId());
        addIdentiyLinkForUser(task, currentUserIdString, IdentityLinkType.PARTICIPANT);

    } catch (FlowableException e) {
        throw new BadRequestException("Task " + task.getId() + " can't be assigned", e);
    }
}
 
Example #14
Source File: UserDetailsService.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Transactional
public UserDetails loadByUserId(final String userId) {
    CachedUser cachedUser = userCache.getUser(userId, true, true, false); // Do not check for validity. This would lead to A LOT of db requests! For login, there is a validity period (see below)
    if (cachedUser == null) {
        throw new UsernameNotFoundException("User " + userId + " was not found in the database");
    }

    long lastDatabaseCheck = cachedUser.getLastDatabaseCheck();
    long currentTime = System.currentTimeMillis(); // No need to create a Date object. The Date constructor simply calls this method too!

    if (userValidityPeriod <= 0L || (currentTime - lastDatabaseCheck >= userValidityPeriod)) {

        userCache.invalidate(userId);
        cachedUser = userCache.getUser(userId, true, true, false); // Fetching it again will refresh data

        cachedUser.setLastDatabaseCheck(currentTime);
    }

    // The Spring security docs clearly state a new instance must be returned on every invocation
    User user = cachedUser.getUser();
    String actualUserId = user.getId();

    return new FlowableAppUser(cachedUser.getUser(), actualUserId, cachedUser.getGrantedAuthorities());
}
 
Example #15
Source File: UserResourceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Test deleting a single user.
 */
@Test
public void testDeleteUser() throws Exception {
    User savedUser = null;
    try {
        User newUser = identityService.newUser("testuser");
        newUser.setFirstName("Fred");
        newUser.setLastName("McDonald");
        newUser.setEmail("[email protected]");
        identityService.saveUser(newUser);
        savedUser = newUser;

        closeResponse(executeRequest(new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId())), HttpStatus.SC_NO_CONTENT));

        // Check if user is deleted
        assertThat(identityService.createUserQuery().userId(newUser.getId()).count()).isZero();
        savedUser = null;

    } finally {

        // Delete user after test fails
        if (savedUser != null) {
            identityService.deleteUser(savedUser.getId());
        }
    }
}
 
Example #16
Source File: GetUserPictureCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public Picture execute(CommandContext commandContext) {
    if (userId == null) {
        throw new FlowableIllegalArgumentException("userId is null");
    }

    User user = CommandContextUtil.getIdmEngineConfiguration().getIdmIdentityService()
            .createUserQuery().userId(userId)
            .singleResult();

    if (user == null) {
        throw new FlowableObjectNotFoundException("user " + userId + " doesn't exist", User.class);
    }

    return CommandContextUtil.getUserEntityManager(commandContext).getUserPicture(user);
}
 
Example #17
Source File: PluggableFlowableIdmTestCase.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void clearAllUsersAndGroups() {

        // Privileges
        List<Privilege> privileges = idmIdentityService.createPrivilegeQuery().list();
        for (Privilege privilege : privileges) {
            idmIdentityService.deletePrivilege(privilege.getId());
        }

        // Groups
        List<Group> groups = idmIdentityService.createGroupQuery().list();
        for (Group group : groups) {
            List<User> members = idmIdentityService.createUserQuery().memberOfGroup(group.getId()).list();
            for (User member : members) {
                idmIdentityService.deleteMembership(member.getId(), group.getId());
            }
            idmIdentityService.deleteGroup(group.getId());
        }

        // Users
        List<User> users = idmIdentityService.createUserQuery().list();
        for (User user : users) {
            idmIdentityService.deleteUser(user.getId());
        }

    }
 
Example #18
Source File: UserQueryTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testQuerySorting() {
    // asc
    assertThat(identityService.createUserQuery().orderByUserId().asc().count()).isEqualTo(4);
    assertThat(identityService.createUserQuery().orderByUserEmail().asc().count()).isEqualTo(4);
    assertThat(identityService.createUserQuery().orderByUserFirstName().asc().count()).isEqualTo(4);
    assertThat(identityService.createUserQuery().orderByUserLastName().asc().count()).isEqualTo(4);

    // desc
    assertThat(identityService.createUserQuery().orderByUserId().desc().count()).isEqualTo(4);
    assertThat(identityService.createUserQuery().orderByUserEmail().desc().count()).isEqualTo(4);
    assertThat(identityService.createUserQuery().orderByUserFirstName().desc().count()).isEqualTo(4);
    assertThat(identityService.createUserQuery().orderByUserLastName().desc().count()).isEqualTo(4);

    // Combined with criteria
    UserQuery query = identityService.createUserQuery().userLastNameLike("%ea%").orderByUserFirstName().asc();
    List<User> users = query.list();
    assertThat(users)
            .extracting(User::getFirstName)
            .containsExactly("Fozzie", "Gonzo");
}
 
Example #19
Source File: IdentityServiceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateUser() {
    // First, create a new user
    User user = idmIdentityService.newUser("johndoe");
    user.setFirstName("John");
    user.setLastName("Doe");
    user.setEmail("[email protected]");
    idmIdentityService.saveUser(user);

    // Fetch and update the user
    user = idmIdentityService.createUserQuery().userId("johndoe").singleResult();
    user.setEmail("[email protected]");
    user.setFirstName("Jane");
    user.setLastName("Donnel");
    idmIdentityService.saveUser(user);

    user = idmIdentityService.createUserQuery().userId("johndoe").singleResult();
    assertThat(user.getFirstName()).isEqualTo("Jane");
    assertThat(user.getLastName()).isEqualTo("Donnel");
    assertThat(user.getEmail()).isEqualTo("[email protected]");

    idmIdentityService.deleteUser(user.getId());
}
 
Example #20
Source File: IdentityServiceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testUserPicture() {
    // First, create a new user
    User user = idmIdentityService.newUser("johndoe");
    idmIdentityService.saveUser(user);
    String userId = user.getId();

    Picture picture = new Picture("niceface".getBytes(), "image/string");
    idmIdentityService.setUserPicture(userId, picture);

    picture = idmIdentityService.getUserPicture(userId);

    // Fetch and update the user
    user = idmIdentityService.createUserQuery().userId("johndoe").singleResult();
    assertThat(picture.getBytes()).as("byte arrays differ").isEqualTo("niceface".getBytes());
    assertThat(picture.getMimeType()).isEqualTo("image/string");

    // interface definition states that setting picture to null should delete it
    idmIdentityService.setUserPicture(userId, null);
    assertThat(idmIdentityService.getUserPicture(userId)).as("it should be possible to nullify user picture").isNull();
    user = idmIdentityService.createUserQuery().userId("johndoe").singleResult();
    assertThat(idmIdentityService.getUserPicture(userId)).as("it should be possible to delete user picture").isNull();

    idmIdentityService.deleteUser(user.getId());
}
 
Example #21
Source File: IdmPrivilegesResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@GetMapping(value = "/rest/admin/privileges/{privilegeId}")
public PrivilegeRepresentation getPrivilege(@PathVariable String privilegeId) {

    Privilege privilege = privilegeService.findPrivilege(privilegeId);

    if (privilege != null) {
        PrivilegeRepresentation privilegeRepresentation = new PrivilegeRepresentation();
        privilegeRepresentation.setId(privilege.getId());
        privilegeRepresentation.setName(privilege.getName());

        List<User> users = privilegeService.findUsersWithPrivilege(privilegeId);
        for (User user : users) {
            privilegeRepresentation.addUser(new UserRepresentation(user));
        }

        List<Group> groups = privilegeService.findGroupsWithPrivilege(privilegeId);
        for (Group group : groups) {
            privilegeRepresentation.addGroup(new GroupRepresentation(group));
        }

        return privilegeRepresentation;
    } else {
        throw new NotFoundException();
    }
}
 
Example #22
Source File: HistoricTaskQueryResource.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@PostMapping(value = "/rest/query/history/tasks", produces = "application/json")
public ResultListDataRepresentation listTasks(@RequestBody ObjectNode requestNode) {
    if (requestNode == null) {
        throw new BadRequestException("No request found");
    }

    HistoricTaskInstanceQuery taskQuery = historyService.createHistoricTaskInstanceQuery();

    User currentUser = SecurityUtils.getCurrentUserObject();

    JsonNode processInstanceIdNode = requestNode.get("processInstanceId");
    if (processInstanceIdNode != null && !processInstanceIdNode.isNull()) {
        String processInstanceId = processInstanceIdNode.asText();
        if (permissionService.hasReadPermissionOnProcessInstance(currentUser, processInstanceId)) {
            taskQuery.processInstanceId(processInstanceId);
        } else {
            throw new NotPermittedException();
        }
    }

    JsonNode finishedNode = requestNode.get("finished");
    if (finishedNode != null && !finishedNode.isNull()) {
        boolean isFinished = finishedNode.asBoolean();
        if (isFinished) {
            taskQuery.finished();
        } else {
            taskQuery.unfinished();
        }
    }

    List<HistoricTaskInstance> tasks = taskQuery.list();

    // get all users to have the user object available in the task on the client side
    ResultListDataRepresentation result = new ResultListDataRepresentation(convertTaskInfoList(tasks));
    return result;
}
 
Example #23
Source File: BaseGroupResource.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected Group getGroupFromRequest(String groupId) {
    Group group = identityService.createGroupQuery().groupId(groupId).singleResult();

    if (group == null) {
        throw new FlowableObjectNotFoundException("Could not find a group with id '" + groupId + "'.", User.class);
    }
    
    if (restApiInterceptor != null) {
        restApiInterceptor.accessGroupInfoById(group);
    }
    
    return group;
}
 
Example #24
Source File: UserInfoResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Test deleting the info for a user who does not have that info set
 */
@Test
public void testUpdateUnexistingInfo() throws Exception {
    User savedUser = null;
    try {
        User newUser = identityService.newUser("testuser");
        newUser.setFirstName("Fred");
        newUser.setLastName("McDonald");
        newUser.setEmail("[email protected]");
        identityService.saveUser(newUser);
        savedUser = newUser;

        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("value", "Updated value");

        HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, "testuser", "key1"));
        httpPut.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPut, HttpStatus.SC_NOT_FOUND));

    } finally {

        // Delete user after test passes or fails
        if (savedUser != null) {
            identityService.deleteUser(savedUser.getId());
        }
    }
}
 
Example #25
Source File: SampleLdapIntegrationTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void userQueryByFullNameLike() {
    assertThat(identityService.createUserQuery().userFullNameLike("ermi").list())
        .extracting(User::getId, User::getFirstName, User::getLastName)
        .containsExactly(tuple("kermit", "Kermit", "The Frog"));
    assertThat(identityService.createUserQuery().userFullNameLike("ermi").count()).isEqualTo(1);

    assertThat(identityService.createUserQuery().userFullNameLike("rog").list())
        .extracting(User::getId, User::getFirstName, User::getLastName)
        .containsExactly(tuple("kermit", "Kermit", "The Frog"));
    assertThat(identityService.createUserQuery().userFullNameLike("rog").count()).isEqualTo(1);

    assertThat(identityService.createUserQuery().userFullNameLike("e").list())
        .extracting(User::getId, User::getFirstName, User::getLastName)
        .containsExactlyInAnyOrder(
            tuple("kermit", "Kermit", "The Frog"),
            tuple("pepe", "Pepe", "The King Prawn"),
            tuple("fozzie", "Fozzie", "Bear"),
            tuple("gonzo", "Gonzo", "The Great"),
            tuple("bunsen", "Dr\\, Bunsen", "Honeydew")
        );
    assertThat(identityService.createUserQuery().userFullNameLike("e").count()).isEqualTo(5);

    assertThat(identityService.createUserQuery().userFullNameLike("The").list())
        .extracting(User::getId, User::getFirstName, User::getLastName)
        .containsExactlyInAnyOrder(
            tuple("kermit", "Kermit", "The Frog"),
            tuple("pepe", "Pepe", "The King Prawn"),
            tuple("gonzo", "Gonzo", "The Great")
        );
    assertThat(identityService.createUserQuery().userFullNameLike("The").count()).isEqualTo(3);
}
 
Example #26
Source File: FlowableIdmApplicationDefaultAuthenticationTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Bean
public CommandLineRunner initTestUsers(IdmIdentityService idmIdentityService) {
    return args -> {
        User testUser = idmIdentityService.createUserQuery().userId("my-admin").singleResult();
        if (testUser == null) {
            createTestUser(idmIdentityService);
        }
    };
}
 
Example #27
Source File: UserPictureResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdatePicture() throws Exception {
    User savedUser = null;
    try {
        User newUser = identityService.newUser("testuser");
        newUser.setFirstName("Fred");
        newUser.setLastName("McDonald");
        newUser.setEmail("[email protected]");
        identityService.saveUser(newUser);
        savedUser = newUser;

        HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_PICTURE, newUser.getId()));
        httpPut.setEntity(HttpMultipartHelper
                .getMultiPartEntity("myPicture.png", "image/png", new ByteArrayInputStream("this is the picture raw byte stream".getBytes()), null));
        closeResponse(executeBinaryRequest(httpPut, HttpStatus.SC_NO_CONTENT));

        Picture picture = identityService.getUserPicture(newUser.getId());
        assertThat(picture).isNotNull();
        assertThat(picture.getMimeType()).isEqualTo("image/png");
        assertThat(new String(picture.getBytes())).isEqualTo("this is the picture raw byte stream");

    } finally {

        // Delete user after test passes or fails
        if (savedUser != null) {
            identityService.deleteUser(savedUser.getId());
        }
    }
}
 
Example #28
Source File: UserInfoResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Test getting the collection of info for a user.
 */
@Test
public void testGetUserInfoCollection() throws Exception {
    User savedUser = null;
    try {
        User newUser = identityService.newUser("testuser");
        newUser.setFirstName("Fred");
        newUser.setLastName("McDonald");
        newUser.setEmail("[email protected]");
        identityService.saveUser(newUser);
        savedUser = newUser;

        identityService.setUserInfo(newUser.getId(), "key1", "Value 1");
        identityService.setUserInfo(newUser.getId(), "key2", "Value 2");

        CloseableHttpResponse response = executeRequest(
                new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO_COLLECTION, newUser.getId())), HttpStatus.SC_OK);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertThat(responseNode).isNotNull();
        assertThat(responseNode.isArray()).isTrue();
        assertThatJson(responseNode)
                .isEqualTo("[ {"
                        + "  key: 'key1',"
                        + "  url: '" + SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, newUser.getId(), "key1") + "'"
                        + "},"
                        + "{"
                        + "  key: 'key2',"
                        + "  url: '" + SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, newUser.getId(), "key2") + "'"
                        + "}"
                        + "]");

    } finally {

        // Delete user after test passes or fails
        if (savedUser != null) {
            identityService.deleteUser(savedUser.getId());
        }
    }
}
 
Example #29
Source File: FlowableCommentService.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public ResultListDataRepresentation getTaskComments(String taskId) {

        User currentUser = SecurityUtils.getCurrentUserObject();
        checkReadPermissionOnTask(currentUser, taskId);
        List<Comment> comments = getCommentsForTask(taskId);

        // Create representation for all comments
        List<CommentRepresentation> commentList = new ArrayList<>();
        for (Comment comment : comments) {
            commentList.add(new CommentRepresentation(comment));
        }

        return new ResultListDataRepresentation(commentList);
    }
 
Example #30
Source File: LDAPIdentityServiceImpl.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public List<User> getUsersWithPrivilege(String name) {
    List<User> users = new ArrayList<>();
    List<PrivilegeMapping> privilegeMappings = getPrivilegeMappingsByPrivilegeId(name);
    for (PrivilegeMapping privilegeMapping : privilegeMappings) {
        if (privilegeMapping.getUserId() != null) {
            User user = new UserEntityImpl();
            user.setId(privilegeMapping.getUserId());
            user.setLastName(privilegeMapping.getUserId());
            users.add(user);
        }
    }
    
    return users;
}