@Override public UserQuery createUserQuery() { return getIdmIdentityService().createUserQuery(); }
@Override public UserQuery createUserQuery() { return getIdmIdentityService().createUserQuery(); }
protected UserQuery createUsersForGroupQuery(String groupId, String filter) { UserQuery userQuery = identityService.createUserQuery().memberOfGroup(groupId); if (StringUtils.isNotEmpty(filter)) { userQuery.userFullNameLikeIgnoreCase("%" + filter + "%"); } return userQuery; }
@ApiOperation(value = "Delete a member from a group", tags = { "Groups" }) @ApiResponses(value = { @ApiResponse(code = 204, message = "Indicates the group was found and the member has been deleted. The response body is left empty intentionally."), @ApiResponse(code = 404, message = "Indicates the requested group was not found or that the user is not a member of the group. The status description contains additional information about the error.") }) @DeleteMapping("/groups/{groupId}/members/{userId}") public void deleteMembership(@ApiParam(name = "groupId") @PathVariable("groupId") String groupId, @ApiParam(name = "userId") @PathVariable("userId") String userId, HttpServletRequest request, HttpServletResponse response) { Group group = getGroupFromRequest(groupId); // Check if user is not a member of group since API doesn't return typed exception if (identityService.createUserQuery().memberOfGroup(group.getId()).userId(userId).count() != 1) { throw new FlowableObjectNotFoundException("User '" + userId + "' is not part of group '" + group.getId() + "'.", null); } identityService.deleteMembership(userId, group.getId()); response.setStatus(HttpStatus.NO_CONTENT.value()); } }
public CachedUser load(final String userId) throws Exception { User userFromDatabase = null; if (ldapProperties == null || !ldapProperties.isEnabled()) { userFromDatabase = identityService.createUserQuery().userIdIgnoreCase(userId.toLowerCase()).singleResult(); } else { userFromDatabase = identityService.createUserQuery().userId(userId).singleResult(); } if (userFromDatabase == null) { throw new UsernameNotFoundException("User " + userId + " was not found in the database"); } Collection<GrantedAuthority> grantedAuthorities = new ArrayList<>(); UserInformation userInformation = userService.getUserInformation(userFromDatabase.getId()); for (String privilege : userInformation.getPrivileges()) { grantedAuthorities.add(new SimpleGrantedAuthority(privilege)); } return new CachedUser(userFromDatabase, grantedAuthorities); }
protected UserQuery createUserQuery(String filter, String sort) { UserQuery userQuery = identityService.createUserQuery(); if (StringUtils.isNotEmpty(filter)) { userQuery.userFullNameLikeIgnoreCase("%" + filter + "%"); } if (StringUtils.isNotEmpty(sort)) { if ("idDesc".equals(sort)) { userQuery.orderByUserId().desc(); } else if ("idAsc".equals(sort)) { userQuery.orderByUserId().asc(); } else if ("emailAsc".equals(sort)) { userQuery.orderByUserEmail().asc(); } else if ("emailDesc".equals(sort)) { userQuery.orderByUserEmail().desc(); } } return userQuery; }
protected User getUserFromRequest(String userId) { User user = identityService.createUserQuery().userId(userId).singleResult(); if (user == null) { throw new FlowableObjectNotFoundException("Could not find a user with id '" + userId + "'.", User.class); } if (restApiInterceptor != null) { restApiInterceptor.accessUserInfoById(user); } return user; }
protected void verifyGroupMemberExists(String groupId, String userId) { // Check existence Group group = identityService.createGroupQuery().groupId(groupId).singleResult(); User user = identityService.createUserQuery().userId(userId).singleResult(); for (User groupMember : identityService.createUserQuery().memberOfGroup(groupId).list()) { if (groupMember.getId().equals(userId)) { user = groupMember; } } if (group == null || user == null) { throw new NotFoundException(); } }
public void bulkUpdatePassword(List<String> userIds, String newPassword) { for (String userId : userIds) { User user = identityService.createUserQuery().userId(userId).singleResult(); if (user != null) { user.setPassword(newPassword); identityService.updateUserPassword(user); } } }
protected boolean isUserPrivilege(String privilegeId, String userId) { User user = identityService.createUserQuery().userId(userId).singleResult(); if (user == null) { throw new IllegalArgumentException("Invalid user id"); } return identityService.createPrivilegeQuery().privilegeId(privilegeId).userId(userId).count() > 0; }
public void changePassword(String originalPassword, String newPassword) { User user = identityService.createUserQuery().userId(SecurityUtils.getCurrentUserId()).singleResult(); if (!user.getPassword().equals(originalPassword)) { throw new NotFoundException(); } user.setPassword(newPassword); identityService.updateUserPassword(user); }
@ApiOperation(value = "Add a member to a group", tags = { "Groups" }) @ApiResponses(value = { @ApiResponse(code = 201, message = "Indicates the group was found and the member has been added."), @ApiResponse(code = 400, message = "Indicates the userId was not included in the request body."), @ApiResponse(code = 404, message = "Indicates the requested group was not found."), @ApiResponse(code = 409, message = "Indicates the requested user is already a member of the group.") }) @PostMapping(value = "/groups/{groupId}/members", produces = "application/json") public MembershipResponse createMembership(@ApiParam(name = "groupId") @PathVariable String groupId, @RequestBody MembershipRequest memberShip, HttpServletRequest request, HttpServletResponse response) { Group group = getGroupFromRequest(groupId); if (memberShip.getUserId() == null) { throw new FlowableIllegalArgumentException("UserId cannot be null."); } // Check if user is member of group since API doesn't return typed exception if (identityService.createUserQuery().memberOfGroup(group.getId()).userId(memberShip.getUserId()).count() > 0) { throw new FlowableConflictException("User '" + memberShip.getUserId() + "' is already part of group '" + group.getId() + "'."); } identityService.createMembership(memberShip.getUserId(), group.getId()); response.setStatus(HttpStatus.CREATED.value()); return restResponseFactory.createMembershipResponse(memberShip.getUserId(), group.getId()); } }
public User createNewUser(String id, String firstName, String lastName, String email, String password) { if (StringUtils.isBlank(id) || StringUtils.isBlank(password) || StringUtils.isBlank(firstName)) { throw new BadRequestException("Id, password and first name are required"); } if (email != null && identityService.createUserQuery().userEmail(email).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); identityService.saveUser(user); User savedUser = identityService.createUserQuery().userEmail(email).singleResult(); savedUser.setPassword(password); identityService.updateUserPassword(savedUser); return user; }
public void updateUserDetails(String userId, String firstName, String lastName, String email) { User user = identityService.createUserQuery().userId(userId).singleResult(); if (user != null) { user.setFirstName(firstName); user.setLastName(lastName); user.setEmail(email); identityService.saveUser(user); } }
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; }
@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); }
@Override public Object 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); } CommandContextUtil.getUserEntityManager(commandContext).setUserPicture(user, picture); return null; }
public void deleteGroupMember(String groupId, String userId) { verifyGroupMemberExists(groupId, userId); Group group = identityService.createGroupQuery().groupId(groupId).singleResult(); if (group == null) { throw new NotFoundException(); } User user = identityService.createUserQuery().userId(userId).singleResult(); if (user == null) { throw new NotFoundException(); } identityService.deleteMembership(userId, groupId); }
public void addGroupMember(String groupId, String userId) { verifyGroupMemberExists(groupId, userId); Group group = identityService.createGroupQuery().groupId(groupId).singleResult(); if (group == null) { throw new NotFoundException(); } User user = identityService.createUserQuery().userId(userId).singleResult(); if (user == null) { throw new NotFoundException(); } identityService.createMembership(userId, groupId); }
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()); } }