@ApiOperation(value = "Delete a group", tags = { "Groups" }) @ApiResponses(value = { @ApiResponse(code = 204, message = "Indicates the group was found and has been deleted. Response-body is intentionally empty."), @ApiResponse(code = 404, message = "Indicates the requested group does not exist.") }) @DeleteMapping("/groups/{groupId}") public void deleteGroup(@ApiParam(name = "groupId") @PathVariable String groupId, HttpServletResponse response) { Group group = getGroupFromRequest(groupId); if (restApiInterceptor != null) { restApiInterceptor.deleteGroup(group); } identityService.deleteGroup(group.getId()); response.setStatus(HttpStatus.NO_CONTENT.value()); } }
@Override public List<Group> getGroupsWithPrivilege(String name) { List<Group> groups = new ArrayList<>(); List<PrivilegeMapping> privilegeMappings = getPrivilegeMappingsByPrivilegeId(name); for (PrivilegeMapping privilegeMapping : privilegeMappings) { if (privilegeMapping.getGroupId() != null) { Group group = new GroupEntityImpl(); group.setId(privilegeMapping.getGroupId()); group.setName(privilegeMapping.getGroupId()); groups.add(group); } } return groups; }
@ApiOperation(value = "Update a group", tags = { "Groups" }, notes = "All request values are optional. For example, you can only include the name attribute in the request body JSON-object, only updating the name of the group, leaving all other fields unaffected. When an attribute is explicitly included and is set to null, the group-value will be updated to null.") @ApiResponses(value = { @ApiResponse(code = 200, message = "Indicates the group was updated."), @ApiResponse(code = 404, message = "Indicates the requested group was not found."), @ApiResponse(code = 409, message = "Indicates the requested group was updated simultaneously.") }) @PutMapping(value = "/groups/{groupId}", produces = "application/json") public GroupResponse updateGroup(@ApiParam(name = "groupId") @PathVariable String groupId, @RequestBody GroupRequest groupRequest, HttpServletRequest request) { Group group = getGroupFromRequest(groupId); if (groupRequest.getId() == null || groupRequest.getId().equals(group.getId())) { if (groupRequest.isNameChanged()) { group.setName(groupRequest.getName()); } if (groupRequest.isTypeChanged()) { group.setType(groupRequest.getType()); } identityService.saveGroup(group); } else { throw new FlowableIllegalArgumentException("Key provided in request body doesn't match the key in the resource URL."); } return restResponseFactory.createGroupResponse(group); }
@ApiOperation(value = "Create a group", tags = { "Groups" }) @ApiResponses(value = { @ApiResponse(code = 201, message = "Indicates the group was created."), @ApiResponse(code = 400, message = "Indicates the id of the group was missing.") }) @PostMapping(value = "/groups", produces = "application/json") public GroupResponse createGroup(@RequestBody GroupRequest groupRequest, HttpServletRequest httpRequest, HttpServletResponse response) { if (groupRequest.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.createGroupQuery().groupId(groupRequest.getId()).count() > 0) { throw new FlowableConflictException("A group with id '" + groupRequest.getId() + "' already exists."); } Group created = identityService.newGroup(groupRequest.getId()); created.setId(groupRequest.getId()); created.setName(groupRequest.getName()); created.setType(groupRequest.getType()); if (restApiInterceptor != null) { restApiInterceptor.createNewGroup(created); } identityService.saveGroup(created); response.setStatus(HttpStatus.CREATED.value()); return restResponseFactory.createGroupResponse(created); }
public Group updateGroupName(String groupId, String name) { if (StringUtils.isBlank(name)) { throw new BadRequestException("Group name required"); } Group group = identityService.createGroupQuery().groupId(groupId).singleResult(); if (group == null) { throw new NotFoundException(); } group.setName(name); identityService.saveGroup(group); return group; }
@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 Group createNewGroup(String id, String name, String type) { if (StringUtils.isBlank(name)) { throw new BadRequestException("Group name required"); } Group newGroup = identityService.newGroup(id); newGroup.setName(name); if (type == null) { newGroup.setType(GroupTypes.TYPE_ASSIGNMENT); } else { newGroup.setType(type); } identityService.saveGroup(newGroup); return newGroup; }
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String name = authentication.getName(); String password = authentication.getCredentials().toString(); boolean authenticated = identityService.checkPassword(name, password); if (authenticated) { List<Group> groups = identityService.createGroupQuery().groupMember(name).list(); Collection<GrantedAuthority> grantedAuthorities = new ArrayList<>(); for (Group group : groups) { grantedAuthorities.add(new SimpleGrantedAuthority(group.getId())); } return new UsernamePasswordAuthenticationToken(name, password, grantedAuthorities); } else { throw new BadCredentialsException("Authentication failed for this username and password"); } }
@Override public List<String> getGroupsForCandidateUser(String candidateUser) { IdmIdentityService identityService = cmmnEngineConfiguration.getIdmIdentityService(); List<Group> groups = identityService.createGroupQuery().groupMember(candidateUser).list(); List<String> groupIds = new ArrayList<>(); for (Group group : groups) { groupIds.add(group.getId()); } return groupIds; } }
@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()); } }
@Override public List<String> getGroupsForCandidateUser(String candidateUser) { IdentityService identityService = getProcessEngineConfiguration().getIdentityService(); List<Group> groups = identityService.createGroupQuery().groupMember(candidateUser).list(); List<String> groupIds = new ArrayList<>(); for (Group group : groups) { groupIds.add(group.getId()); } return groupIds; } }
protected List<String> getGroupsForCandidateUser(String candidateUser) { IdentityService identityService = Context.getProcessEngineConfiguration().getIdentityService(); List<Group> groups = identityService.createGroupQuery().groupMember(candidateUser).list(); List<String> groupIds = new ArrayList<>(); for (Group group : groups) { groupIds.add(group.getId()); } return groupIds; }
protected List<String> getGroupsForCandidateUser(String candidateUser) { List<String> groupIds = new ArrayList<>(); IdmIdentityService idmIdentityService = CommandContextUtil.getTaskServiceConfiguration().getIdmIdentityService(); if (idmIdentityService != null) { List<Group> groups = idmIdentityService.createGroupQuery().groupMember(candidateUser).list(); for (Group group : groups) { groupIds.add(group.getId()); } } return groupIds; }
protected List<String> getGroupsForCandidateUser(String candidateUser) { IdentityService identityService = Context.getProcessEngineConfiguration().getIdentityService(); List<Group> groups = identityService.createGroupQuery().groupMember(candidateUser).list(); List<String> groupIds = new ArrayList<>(); for (Group group : groups) { groupIds.add(group.getId()); } return groupIds; }
public List<String> getAuthorizationGroups() { // Similar behaviour as the TaskQuery.taskCandidateUser() which includes the groups the candidate user is part of if (authorizationUserId != null) { IdentityService identityService = Context.getProcessEngineConfiguration().getIdentityService(); List<Group> groups = identityService.createGroupQuery().groupMember(authorizationUserId).list(); List<String> groupIds = new ArrayList<>(); for (Group group : groups) { groupIds.add(group.getId()); } return groupIds; } return null; }
protected List<String> getGroupsForCandidateUser(String candidateUser) { List<String> groupIds = new ArrayList<>(); IdmEngineConfigurationApi idmEngineConfiguration = CommandContextUtil.getIdmEngineConfiguration(); if (idmEngineConfiguration != null) { IdmIdentityService idmIdentityService = idmEngineConfiguration.getIdmIdentityService(); if (idmIdentityService != null) { List<Group> groups = idmIdentityService.createGroupQuery().groupMember(candidateUser).list(); for (Group group : groups) { groupIds.add(group.getId()); } } } return groupIds; }
@Override public UserInformation getUserInformation(String userId) { User user = identityService.createUserQuery().userId(userId).singleResult(); if (user == null) { throw new NotFoundException(); } List<Privilege> userPrivileges = identityService.createPrivilegeQuery().userId(userId).list(); Set<String> privilegeNames = new HashSet<>(); for (Privilege userPrivilege : userPrivileges) { privilegeNames.add(userPrivilege.getName()); } List<Group> groups = identityService.createGroupQuery().groupMember(userId).list(); if (groups.size() > 0) { List<String> groupIds = new ArrayList<>(); for (Group group : groups) { groupIds.add(group.getId()); } List<Privilege> groupPrivileges = identityService.createPrivilegeQuery().groupIds(groupIds).list(); for (Privilege groupPrivilege : groupPrivileges) { privilegeNames.add(groupPrivilege.getName()); } } return new UserInformation(user, groups, new ArrayList<>(privilegeNames)); }