Java Code Examples for org.flowable.idm.api.User#setDisplayName()
The following examples show how to use
org.flowable.idm.api.User#setDisplayName() .
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: UserQueryTest.java From flowable-engine with Apache License 2.0 | 5 votes |
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 2
Source File: UserResource.java From flowable-engine with Apache License 2.0 | 5 votes |
@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 = "/identity/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.isDisplayNameChanged()) { user.setDisplayName(userRequest.getDisplayName()); } if (userRequest.isLastNameChanged()) { user.setLastName(userRequest.getLastName()); } if (userRequest.isPasswordChanged()) { user.setPassword(userRequest.getPassword()); identityService.updateUserPassword(user); } else { identityService.saveUser(user); } return restResponseFactory.createUserResponse(user, false); }
Example 3
Source File: UserCollectionResource.java From flowable-engine with Apache License 2.0 | 5 votes |
@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 4
Source File: UserResourceTest.java From flowable-engine with Apache License 2.0 | 5 votes |
/** * 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 5
Source File: UserResource.java From flowable-engine with Apache License 2.0 | 5 votes |
@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 6
Source File: UserCollectionResource.java From flowable-engine with Apache License 2.0 | 5 votes |
@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 = "/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."); } // 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()); if (restApiInterceptor != null) { restApiInterceptor.createNewUser(created); } identityService.saveUser(created); response.setStatus(HttpStatus.CREATED.value()); return idmRestResponseFactory.createUserResponse(created, false); }
Example 7
Source File: FlowableUserDetailsServiceTest.java From flowable-engine with Apache License 2.0 | 5 votes |
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 8
Source File: IdentityServiceTest.java From flowable-engine with Apache License 2.0 | 4 votes |
@Test public void testUpdateUserDeltaOnly() { // First, create a new user User user = idmIdentityService.newUser("testuser"); user.setFirstName("John"); user.setLastName("Doe"); user.setDisplayName("John Doe"); user.setEmail("[email protected]"); user.setPassword("test"); idmIdentityService.saveUser(user); String initialPassword = user.getPassword(); // Fetch and update the user user = idmIdentityService.createUserQuery().userId("testuser").singleResult(); assertThat(user) .returns("John", User::getFirstName) .returns("Doe", User::getLastName) .returns("John Doe", User::getDisplayName) .returns("[email protected]", User::getEmail) .returns(initialPassword, User::getPassword); user.setFirstName("Jane"); idmIdentityService.saveUser(user); user = idmIdentityService.createUserQuery().userId("testuser").singleResult(); assertThat(user) .returns("Jane", User::getFirstName) .returns("Doe", User::getLastName) .returns("John Doe", User::getDisplayName) .returns("[email protected]", User::getEmail) .returns(initialPassword, User::getPassword); user.setLastName("Doelle"); idmIdentityService.saveUser(user); user = idmIdentityService.createUserQuery().userId("testuser").singleResult(); assertThat(user) .returns("Jane", User::getFirstName) .returns("Doelle", User::getLastName) .returns("John Doe", User::getDisplayName) .returns("[email protected]", User::getEmail) .returns(initialPassword, User::getPassword); user.setDisplayName("Jane Doelle"); idmIdentityService.saveUser(user); user = idmIdentityService.createUserQuery().userId("testuser").singleResult(); assertThat(user) .returns("Jane", User::getFirstName) .returns("Doelle", User::getLastName) .returns("Jane Doelle", User::getDisplayName) .returns("[email protected]", User::getEmail) .returns(initialPassword, User::getPassword); user.setEmail("[email protected]"); idmIdentityService.saveUser(user); user = idmIdentityService.createUserQuery().userId("testuser").singleResult(); assertThat(user) .returns("Jane", User::getFirstName) .returns("Doelle", User::getLastName) .returns("Jane Doelle", User::getDisplayName) .returns("[email protected]", User::getEmail) .returns(initialPassword, User::getPassword); user.setPassword("test-pass"); idmIdentityService.saveUser(user); user = idmIdentityService.createUserQuery().userId("testuser").singleResult(); assertThat(user) .returns("Jane", User::getFirstName) .returns("Doelle", User::getLastName) .returns("Jane Doelle", User::getDisplayName) .returns("[email protected]", User::getEmail) .returns(initialPassword, User::getPassword); idmIdentityService.deleteUser(user.getId()); }
Example 9
Source File: UserResourceTest.java From flowable-engine with Apache License 2.0 | 4 votes |
/** * 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()); } } }
Example 10
Source File: UserResourceTest.java From flowable-engine with Apache License 2.0 | 4 votes |
/** * 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 11
Source File: UserCollectionResourceTest.java From flowable-engine with Apache License 2.0 | 4 votes |
/** * Test getting all users. */ @Test @Deployment public void testGetUsers() throws Exception { List<User> savedUsers = new ArrayList<>(); try { User user1 = identityService.newUser("testuser"); user1.setFirstName("Fred"); user1.setLastName("McDonald"); user1.setDisplayName("Fred McDonald"); user1.setEmail("[email protected]"); identityService.saveUser(user1); savedUsers.add(user1); User user2 = identityService.newUser("anotherUser"); user2.setFirstName("Tijs"); user2.setLastName("Barrez"); user2.setEmail("[email protected]"); identityService.saveUser(user2); savedUsers.add(user2); User user3 = identityService.createUserQuery().userId("kermit").singleResult(); assertThat(user3).isNotNull(); User user4 = identityService.createUserQuery().userId("aSalesUser").singleResult(); assertThat(user4).isNotNull(); // Test filter-less String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION); assertResultsPresentInDataResponse(url, user1.getId(), user2.getId(), user3.getId(), user4.getId()); // Test based on userId url = RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION) + "?id=testuser"; assertResultsPresentInDataResponse(url, user1.getId()); // Test based on firstName url = RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION) + "?firstName=Tijs"; assertResultsPresentInDataResponse(url, user2.getId()); // Test based on lastName url = RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION) + "?lastName=Barrez"; assertResultsPresentInDataResponse(url, user2.getId()); // Test based on displayName url = RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION) + "?displayName=Fred%20McDonald"; assertResultsPresentInDataResponse(url, user1.getId()); // Test based on email url = RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION) + "[email protected]"; assertResultsPresentInDataResponse(url, user1.getId()); // Test based on firstNameLike url = RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION) + "?firstNameLike=" + encode("%ij%"); assertResultsPresentInDataResponse(url, user2.getId()); // Test based on lastNameLike url = RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION) + "?lastNameLike=" + encode("%rez"); assertResultsPresentInDataResponse(url, user2.getId()); // Test based on displayNameLike url = RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION) + "?displayNameLike=" + encode("%red Mc%"); assertResultsPresentInDataResponse(url, user1.getId()); // Test based on emailLike url = RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION) + "?emailLike=" + encode("[email protected]%"); assertResultsPresentInDataResponse(url, user1.getId()); // Test based on memberOfGroup url = RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION) + "?memberOfGroup=admin"; assertResultsPresentInDataResponse(url, user3.getId()); } finally { // Delete user after test passes or fails if (!savedUsers.isEmpty()) { for (User user : savedUsers) { identityService.deleteUser(user.getId()); } } } }
Example 12
Source File: FlowableUserDetailsServiceTest.java From flowable-engine with Apache License 2.0 | 4 votes |
@Test public void testLoadingKnownUserWithAllPrivileges() { UserDetails kermit = userDetailsService.loadUserByUsername("kermit"); assertThat(kermit).isNotNull(); assertThat(kermit.isCredentialsNonExpired()).as("credentialsNonExpired").isTrue(); assertThat(kermit.isAccountNonLocked()).as("accountNonLocked").isTrue(); assertThat(kermit.isAccountNonExpired()).as("accountNonExpired").isTrue(); assertThat(kermit.isEnabled()).as("enabled").isTrue(); assertThat(kermit.getUsername()).as("username").isEqualTo("kermit"); assertThat(kermit.getPassword()).as("password").isEqualTo("kermit"); assertThat(kermit.getAuthorities()) .extracting(GrantedAuthority::getAuthority) .as("granted authorities") .containsExactly( "access admin application", "access modeler application", "start processes" ); assertThat(kermit).isInstanceOf(FlowableUserDetails.class); FlowableUserDetails kermitFlowable = (FlowableUserDetails) kermit; User user = kermitFlowable.getUser(); assertThat(user.getId()).isEqualTo("kermit"); assertThat(user.getFirstName()).isEqualTo("Kermit"); assertThat(user.getLastName()).isEqualTo("the Frog"); assertThat(user.getDisplayName()).isEqualTo("Kermit the Frog"); assertThat(user.getEmail()).isEqualTo("[email protected]"); assertThat(user.getPassword()).isEqualTo("kermit"); user.setId("test"); user.setFirstName("test"); user.setLastName("test"); user.setDisplayName("test"); user.setEmail("test"); assertThat(user.getId()).isEqualTo("kermit"); assertThat(user.getFirstName()).isEqualTo("Kermit"); assertThat(user.getLastName()).isEqualTo("the Frog"); assertThat(user.getDisplayName()).isEqualTo("Kermit the Frog"); assertThat(user.getEmail()).isEqualTo("[email protected]"); assertThat(kermitFlowable.getGroups()) .extracting(Group::getId, Group::getName, Group::getType) .as("Groups") .containsExactlyInAnyOrder( tuple("admins", "Admins", "user"), tuple("sales", "Sales", "user"), tuple("engineering", "Engineering", "tech") ); kermitFlowable.getGroups().forEach(group -> { group.setId("test"); group.setType("test"); group.setName("test"); }); assertThat(kermitFlowable.getGroups()) .extracting(Group::getId, Group::getName, Group::getType) .as("Groups") .containsExactlyInAnyOrder( tuple("admins", "Admins", "user"), tuple("sales", "Sales", "user"), tuple("engineering", "Engineering", "tech") ); assertThat(kermit).isInstanceOf(CredentialsContainer.class); CredentialsContainer container = (CredentialsContainer) kermit; container.eraseCredentials(); assertThat(kermit.getPassword()).as("Password after erase").isNull(); assertThat(kermitFlowable.getUser().getPassword()).as("User password after erase").isNull(); }
Example 13
Source File: FlowableUserDetailsServiceTest.java From flowable-engine with Apache License 2.0 | 4 votes |
@Test public void testLoadingKnownUserWithSomePrivileges() { UserDetails fozzie = userDetailsService.loadUserByUsername("fozzie"); assertThat(fozzie).isNotNull(); assertThat(fozzie.isCredentialsNonExpired()).as("credentialsNonExpired").isTrue(); assertThat(fozzie.isAccountNonLocked()).as("accountNonLocked").isTrue(); assertThat(fozzie.isAccountNonExpired()).as("accountNonExpired").isTrue(); assertThat(fozzie.isEnabled()).as("enabled").isTrue(); assertThat(fozzie.getUsername()).as("username").isEqualTo("fozzie"); assertThat(fozzie.getPassword()).as("password").isEqualTo("fozzie"); assertThat(fozzie.getAuthorities()) .extracting(GrantedAuthority::getAuthority) .as("granted authorities") .containsExactly( "start processes" ); assertThat(fozzie).isInstanceOf(FlowableUserDetails.class); FlowableUserDetails fozzieFlowable = (FlowableUserDetails) fozzie; User user = fozzieFlowable.getUser(); assertThat(user.getId()).isEqualTo("fozzie"); assertThat(user.getFirstName()).isEqualTo("Fozzie"); assertThat(user.getLastName()).isEqualTo("Bear"); assertThat(user.getDisplayName()).isEqualTo("Fozzie Bear"); assertThat(user.getEmail()).isEqualTo("[email protected]"); assertThat(user.getPassword()).isEqualTo("fozzie"); user.setId("test"); user.setFirstName("test"); user.setLastName("test"); user.setDisplayName("test"); user.setEmail("test"); assertThat(user.getId()).isEqualTo("fozzie"); assertThat(user.getFirstName()).isEqualTo("Fozzie"); assertThat(user.getLastName()).isEqualTo("Bear"); assertThat(user.getDisplayName()).isEqualTo("Fozzie Bear"); assertThat(user.getEmail()).isEqualTo("[email protected]"); assertThat(fozzieFlowable.getGroups()) .extracting(Group::getId, Group::getName, Group::getType) .as("Groups") .containsExactlyInAnyOrder( tuple("sales", "Sales", "user") ); }