@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()); } }
@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()); } }
@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; }
@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); }
public GroupRepresentation(Group group) { setId(group.getId()); setName(group.getName()); setType(group.getType()); }
@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)); }
public GroupResponse createGroupResponse(Group group, RestUrlBuilder urlBuilder) { GroupResponse response = new GroupResponse(); response.setId(group.getId()); response.setName(group.getName()); response.setType(group.getType()); return response; }
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()); } }
public void deleteUser(String userId) { List<Privilege> privileges = identityService.createPrivilegeQuery().userId(userId).list(); for (Privilege privilege : privileges) { identityService.deleteUserPrivilegeMapping(privilege.getId(), userId); } List<Group> groups = identityService.createGroupQuery().groupMember(userId).list(); if (groups != null && groups.size() > 0) { for (Group group : groups) { identityService.deleteMembership(userId, group.getId()); } } identityService.deleteUser(userId); }