Java Code Examples for org.flowable.idm.api.User#setEmail()

The following examples show how to use org.flowable.idm.api.User#setEmail() . 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 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 2
Source File: IdentityTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testUser() {
    User user = identityService.newUser("johndoe");
    user.setFirstName("John");
    user.setLastName("Doe");
    user.setEmail("[email protected]");
    identityService.saveUser(user);

    user = identityService.createUserQuery().userId("johndoe").singleResult();
    assertThat(user.getId()).isEqualTo("johndoe");
    assertThat(user.getFirstName()).isEqualTo("John");
    assertThat(user.getLastName()).isEqualTo("Doe");
    assertThat(user.getEmail()).isEqualTo("[email protected]");

    identityService.deleteUser("johndoe");
}
 
Example 3
Source File: IdentityServiceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void testUpdateUser() {
    // 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();
    user.setEmail("[email protected]");
    user.setFirstName("Jane");
    user.setLastName("Donnel");
    identityService.saveUser(user);

    user = identityService.createUserQuery().userId("johndoe").singleResult();
    assertEquals("Jane", user.getFirstName());
    assertEquals("Donnel", user.getLastName());
    assertEquals("[email protected]", user.getEmail());

    identityService.deleteUser(user.getId());
}
 
Example 4
Source File: FlowableUserDetailsServiceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private User createUser(String id, String firstName, String lastName, String displayName, String email) {
    User user = idmIdentityService.newUser(id);
    user.setFirstName(firstName);
    user.setLastName(lastName);
    user.setDisplayName(displayName);
    user.setEmail(email);
    user.setPassword(id);
    idmIdentityService.saveUser(user);
    return user;
}
 
Example 5
Source File: UserInfoResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateUserInfo() 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", "Value 1");
        requestNode.put("key", "key1");

        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO_COLLECTION, "testuser"));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertThatJson(responseNode)
                .isEqualTo("{"
                        + "key: 'key1',"
                        + "value: 'Value 1',"
                        + "url: '" + SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, newUser.getId(), "key1") + "'"
                        + "}");

    } finally {

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

        CloseableHttpResponse response = executeRequest(
                new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId())), HttpStatus.SC_OK);

        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertThat(responseNode).isNotNull();
        assertThatJson(responseNode)
                .when(Option.IGNORING_EXTRA_FIELDS)
                .isEqualTo("{"
                        + "id: 'testuser',"
                        + "firstName: 'Fred',"
                        + "lastName: 'McDonald',"
                        + "displayName: 'Fred McDonald',"
                        + "email: '[email protected]',"
                        + "url: '" + SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId()) + "'"
                        + "}");

    } finally {

        // Delete user after test passes or fails
        if (savedUser != null) {
            identityService.deleteUser(savedUser.getId());
        }
    }
}
 
Example 7
Source File: UserInfoResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Test getting info for a user.
 */
@Test
public void testGetUserInfo() 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");

        CloseableHttpResponse response = executeRequest(
                new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, newUser.getId(), "key1")), HttpStatus.SC_OK);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertThatJson(responseNode)
                .isEqualTo("{"
                        + "key: 'key1',"
                        + "value: 'Value 1',"
                        + "url: '" + SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, newUser.getId(), "key1") + "'"
                        + "}");

    } finally {

        // Delete user after test passes or fails
        if (savedUser != null) {
            identityService.deleteUser(savedUser.getId());
        }
    }
}
 
Example 8
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 9
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 10
Source File: UserCollectionResource.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Create a user", tags = { "Users" })
@ApiResponses(value = {
        @ApiResponse(code = 201, message = "Indicates the user was created."),
        @ApiResponse(code = 400, message = "Indicates the id of the user was missing.")

})
@PostMapping(value = "/identity/users", produces = "application/json")
public UserResponse createUser(@RequestBody UserRequest userRequest, HttpServletRequest request, HttpServletResponse response) {
    if (userRequest.getId() == null) {
        throw new FlowableIllegalArgumentException("Id cannot be null.");
    }
    
    if (restApiInterceptor != null) {
        restApiInterceptor.createUser(userRequest);
    }

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

    User created = identityService.newUser(userRequest.getId());
    created.setEmail(userRequest.getEmail());
    created.setFirstName(userRequest.getFirstName());
    created.setLastName(userRequest.getLastName());
    created.setDisplayName(userRequest.getDisplayName());
    created.setPassword(userRequest.getPassword());
    created.setTenantId(userRequest.getTenantId());
    identityService.saveUser(created);

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

    return restResponseFactory.createUserResponse(created, true);
}
 
Example 11
Source File: UserQueryTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private User createUser(String id, String firstName, String lastName, String email) {
    User user = identityService.newUser(id);
    user.setFirstName(firstName);
    user.setLastName(lastName);
    user.setEmail(email);
    identityService.saveUser(user);
    return user;
}
 
Example 12
Source File: IdentityTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void testUser() {
    User user = identityService.newUser("johndoe");
    user.setFirstName("John");
    user.setLastName("Doe");
    user.setEmail("[email protected]");
    identityService.saveUser(user);

    user = identityService.createUserQuery().userId("johndoe").singleResult();
    assertEquals("johndoe", user.getId());
    assertEquals("John", user.getFirstName());
    assertEquals("Doe", user.getLastName());
    assertEquals("[email protected]", user.getEmail());

    identityService.deleteUser("johndoe");
}
 
Example 13
Source File: ProfileServiceImpl.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public User updateProfile(String firstName, String lastName, String email) {
    User currentUser = SecurityUtils.getCurrentUserObject();

    // If user is not externally managed, we need the email address for login, so an empty email is not allowed
    if (StringUtils.isEmpty(email)) {
        throw new BadRequestException("Empty email is not allowed");
    }

    User user = identityService.createUserQuery().userId(currentUser.getId()).singleResult();
    user.setFirstName(firstName);
    user.setLastName(lastName);
    user.setEmail(email);
    identityService.saveUser(user);
    return user;
}
 
Example 14
Source File: UserServiceImpl.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public User createNewUser(String id, String firstName, String lastName, String email, String password, String tenantId) {
    if (StringUtils.isBlank(id) ||
        StringUtils.isBlank(password) ||
        StringUtils.isBlank(firstName)) {
        throw new BadRequestException("Id, password and first name are required");
    }

    if (StringUtils.isNotBlank(email) && identityService.createUserQuery().userEmail(email).count() > 0) {
        throw new ConflictingRequestException("User already registered", "ACCOUNT.SIGNUP.ERROR.ALREADY-REGISTERED");
    }
    
    if (identityService.createUserQuery().userId(id).count() > 0) {
        throw new ConflictingRequestException("User already registered", "ACCOUNT.SIGNUP.ERROR.ALREADY-REGISTERED");
    }

    User user = identityService.newUser(id);
    user.setFirstName(firstName);
    user.setLastName(lastName);
    user.setEmail(email);
    user.setTenantId(tenantId);
    identityService.saveUser(user);

    User savedUser = identityService.createUserQuery().userId(id).singleResult();
    savedUser.setPassword(password);
    identityService.updateUserPassword(savedUser);

    return user;
}
 
Example 15
Source File: UserServiceImpl.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void updateUserDetails(String userId, String firstName, String lastName, String email, String tenantId) {
    User user = identityService.createUserQuery().userId(userId).singleResult();
    if (user != null) {
        user.setFirstName(firstName);
        user.setLastName(lastName);
        user.setEmail(email);
        user.setTenantId(tenantId);
        identityService.saveUser(user);
    }
}
 
Example 16
Source File: UserResource.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Update a user", tags = { "Users" }, notes = "All request values are optional. "
        + "For example, you can only include the firstName attribute in the request body JSON-object, only updating the firstName of the user, leaving all other fields unaffected. "
        + "When an attribute is explicitly included and is set to null, the user-value will be updated to null. "
        + "Example: {\"firstName\" : null} will clear the firstName of the user).")
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Indicates the user was updated."),
        @ApiResponse(code = 404, message = "Indicates the requested user was not found."),
        @ApiResponse(code = 409, message = "Indicates the requested user was updated simultaneously.")
})
@PutMapping(value = "/users/{userId}", produces = "application/json")
public UserResponse updateUser(@ApiParam(name = "userId") @PathVariable String userId, @RequestBody UserRequest userRequest, HttpServletRequest request) {
    User user = getUserFromRequest(userId);
    if (userRequest.isEmailChanged()) {
        user.setEmail(userRequest.getEmail());
    }
    if (userRequest.isFirstNameChanged()) {
        user.setFirstName(userRequest.getFirstName());
    }
    if (userRequest.isLastNameChanged()) {
        user.setLastName(userRequest.getLastName());
    }
    if (userRequest.isDisplayNameChanged()) {
        user.setDisplayName(userRequest.getDisplayName());
    }
    if (userRequest.isPasswordChanged()) {
        user.setPassword(userRequest.getPassword());
        identityService.updateUserPassword(user);
    } else {
        identityService.saveUser(user);
    }

    return restResponseFactory.createUserResponse(user, false);
}
 
Example 17
Source File: UserQueryTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private User createUser(String id, String firstName, String lastName, String displayName, String email) {
    User user = idmIdentityService.newUser(id);
    user.setFirstName(firstName);
    user.setLastName(lastName);
    user.setDisplayName(displayName);
    user.setEmail(email);
    idmIdentityService.saveUser(user);
    return user;
}
 
Example 18
Source File: UserQueryTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private User createUser(String id, String firstName, String lastName, String email, String tenantId) {
    User user = identityService.newUser(id);
    user.setFirstName(firstName);
    user.setLastName(lastName);
    user.setEmail(email);
    user.setTenantId(tenantId);
    identityService.saveUser(user);
    return user;
}
 
Example 19
Source File: UserResourceTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * Test updating a single user passing in no fields in the json, user should remain unchanged.
 */
@Test
public void testUpdateUserNullFields() throws Exception {
    User savedUser = null;
    try {
        User newUser = identityService.newUser("testuser");
        newUser.setFirstName("Fred");
        newUser.setLastName("McDonald");
        newUser.setDisplayName("Fred McDonald");
        newUser.setEmail("[email protected]");
        identityService.saveUser(newUser);
        savedUser = newUser;

        ObjectNode taskUpdateRequest = objectMapper.createObjectNode();
        taskUpdateRequest.putNull("firstName");
        taskUpdateRequest.putNull("lastName");
        taskUpdateRequest.putNull("displayName");
        taskUpdateRequest.putNull("email");
        taskUpdateRequest.putNull("password");

        HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId()));
        httpPut.setEntity(new StringEntity(taskUpdateRequest.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: 'testuser',"
                        + "firstName: null,"
                        + "lastName: null,"
                        + "displayName: null,"
                        + "email: null,"
                        + "url: '" + SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId()) + "'"
                        + "}");

        // Check user is updated in Flowable
        newUser = identityService.createUserQuery().userId(newUser.getId()).singleResult();
        assertThat(newUser.getLastName()).isNull();
        assertThat(newUser.getFirstName()).isNull();
        assertThat(newUser.getDisplayName()).isNull();
        assertThat(newUser.getEmail()).isNull();

    } finally {

        // Delete user after test fails
        if (savedUser != null) {
            identityService.deleteUser(savedUser.getId());
        }
    }
}
 
Example 20
Source File: UserResourceTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * Test updating a single user passing in no fields in the json, user should remain unchanged.
 */
@Test
public void testUpdateUserNoFields() throws Exception {
    User savedUser = null;
    try {
        User newUser = identityService.newUser("testuser");
        newUser.setFirstName("Fred");
        newUser.setLastName("McDonald");
        newUser.setDisplayName("Fred McDonald");
        newUser.setEmail("[email protected]");
        identityService.saveUser(newUser);
        savedUser = newUser;

        ObjectNode taskUpdateRequest = objectMapper.createObjectNode();

        HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId()));
        httpPut.setEntity(new StringEntity(taskUpdateRequest.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: 'testuser',"
                        + "firstName: 'Fred',"
                        + "lastName: 'McDonald',"
                        + "displayName: 'Fred McDonald',"
                        + "email: '[email protected]',"
                        + "url: '" + SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId()) + "'"
                        + "}");

        // Check user is updated in Flowable
        newUser = identityService.createUserQuery().userId(newUser.getId()).singleResult();
        assertThat(newUser.getLastName()).isEqualTo("McDonald");
        assertThat(newUser.getFirstName()).isEqualTo("Fred");
        assertThat(newUser.getDisplayName()).isEqualTo("Fred McDonald");
        assertThat(newUser.getEmail()).isEqualTo("[email protected]");
        assertThat(newUser.getPassword()).isNull();

    } finally {

        // Delete user after test fails
        if (savedUser != null) {
            identityService.deleteUser(savedUser.getId());
        }
    }
}