@Test void testAddMembership() throws Exception { when(userPermissionEvaluator.hasPermission(new GroupIdentity("devs"), ADD_MEMBERSHIP)) .thenReturn(true); when(groupService.getGroup("devs")).thenReturn(group); when(roleService.getRole("DEVS_EDITOR")).thenReturn(editor); when(userService.getUser("henkie")).thenReturn(user); mockMvc .perform( post(GROUP_END_POINT + "/devs/member") .contentType(APPLICATION_JSON_UTF8) .content(gson.toJson(addGroupMember("henkie", "DEVS_EDITOR")))) .andExpect(status().isCreated()) .andExpect( header() .string("Location", "http: verify(groupService).addMember(group, user, editor); }
@PostMapping(GROUP_MEMBER_END_POINT) @ApiOperation(value = "Add member to group", response = ResponseEntity.class) @Transactional @ApiResponses({ @ApiResponse(code = 201, message = "Member added to group", response = ResponseEntity.class) }) public ResponseEntity addMember( @PathVariable(value = "groupName") String groupName, @RequestBody AddGroupMemberCommand addMemberCommand) { checkGroupPermission(groupName, GroupPermission.ADD_MEMBERSHIP); final Group group = groupService.getGroup(groupName); final String username = addMemberCommand.getUsername(); final String roleName = addMemberCommand.getRoleName(); final Role role = roleService.getRole(roleName); final User user = userService.getUser(username); groupService.addMember(group, user, role); URI location = ServletUriComponentsBuilder.fromCurrentRequest() .path("/{member}") .buildAndExpand(username) .toUri(); return ResponseEntity.created(location).build(); }
IdentitiesApiController { @PostMapping(GROUP_MEMBER_END_POINT) @ApiOperation(value = "Add member to group", response = ResponseEntity.class) @Transactional @ApiResponses({ @ApiResponse(code = 201, message = "Member added to group", response = ResponseEntity.class) }) public ResponseEntity addMember( @PathVariable(value = "groupName") String groupName, @RequestBody AddGroupMemberCommand addMemberCommand) { checkGroupPermission(groupName, GroupPermission.ADD_MEMBERSHIP); final Group group = groupService.getGroup(groupName); final String username = addMemberCommand.getUsername(); final String roleName = addMemberCommand.getRoleName(); final Role role = roleService.getRole(roleName); final User user = userService.getUser(username); groupService.addMember(group, user, role); URI location = ServletUriComponentsBuilder.fromCurrentRequest() .path("/{member}") .buildAndExpand(username) .toUri(); return ResponseEntity.created(location).build(); } }
IdentitiesApiController { @PostMapping(GROUP_MEMBER_END_POINT) @ApiOperation(value = "Add member to group", response = ResponseEntity.class) @Transactional @ApiResponses({ @ApiResponse(code = 201, message = "Member added to group", response = ResponseEntity.class) }) public ResponseEntity addMember( @PathVariable(value = "groupName") String groupName, @RequestBody AddGroupMemberCommand addMemberCommand) { checkGroupPermission(groupName, GroupPermission.ADD_MEMBERSHIP); final Group group = groupService.getGroup(groupName); final String username = addMemberCommand.getUsername(); final String roleName = addMemberCommand.getRoleName(); final Role role = roleService.getRole(roleName); final User user = userService.getUser(username); groupService.addMember(group, user, role); URI location = ServletUriComponentsBuilder.fromCurrentRequest() .path("/{member}") .buildAndExpand(username) .toUri(); return ResponseEntity.created(location).build(); } IdentitiesApiController(
      GroupValueFactory groupValueFactory,
      GroupService groupService,
      RoleMembershipService roleMembershipService,
      RoleService roleService,
      UserService userService,
      UserPermissionEvaluator userPermissionEvaluator); }
IdentitiesApiController { @PostMapping(GROUP_MEMBER_END_POINT) @ApiOperation(value = "Add member to group", response = ResponseEntity.class) @Transactional @ApiResponses({ @ApiResponse(code = 201, message = "Member added to group", response = ResponseEntity.class) }) public ResponseEntity addMember( @PathVariable(value = "groupName") String groupName, @RequestBody AddGroupMemberCommand addMemberCommand) { checkGroupPermission(groupName, GroupPermission.ADD_MEMBERSHIP); final Group group = groupService.getGroup(groupName); final String username = addMemberCommand.getUsername(); final String roleName = addMemberCommand.getRoleName(); final Role role = roleService.getRole(roleName); final User user = userService.getUser(username); groupService.addMember(group, user, role); URI location = ServletUriComponentsBuilder.fromCurrentRequest() .path("/{member}") .buildAndExpand(username) .toUri(); return ResponseEntity.created(location).build(); } IdentitiesApiController(
      GroupValueFactory groupValueFactory,
      GroupService groupService,
      RoleMembershipService roleMembershipService,
      RoleService roleService,
      UserService userService,
      UserPermissionEvaluator userPermissionEvaluator); @PostMapping(GROUP_END_POINT) @ApiOperation(value = "Create a new group", response = ResponseEntity.class) @Transactional @ApiResponses({ @ApiResponse(code = 201, message = "New group created", response = ResponseEntity.class), @ApiResponse(code = 400, message = "Group name not available", response = ResponseEntity.class) }) ResponseEntity createGroup(@RequestBody GroupCommand group); @DeleteMapping(GROUP_END_POINT + "/{groupName}") @ApiOperation(value = "Delete a group", response = ResponseEntity.class) @Transactional @ApiResponses({ @ApiResponse(code = 204, message = "Group deleted", response = ResponseEntity.class), }) ResponseEntity deleteGroup(@PathVariable(value = "groupName") String groupName); @GetMapping(GROUP_END_POINT) @ApiOperation(value = "Get list with groups", response = ResponseEntity.class) @ApiResponses({ @ApiResponse( code = 200, message = "List of groupResponse object available to user", response = List.class) }) @ResponseBody List<GroupResponse> getGroups(); @GetMapping(GROUP_MEMBER_END_POINT) @ApiOperation(value = "Get group members", response = Collection.class) @ResponseBody Collection<GroupMemberResponse> getMembers(
      @PathVariable(value = "groupName") String groupName); @PostMapping(GROUP_MEMBER_END_POINT) @ApiOperation(value = "Add member to group", response = ResponseEntity.class) @Transactional @ApiResponses({ @ApiResponse(code = 201, message = "Member added to group", response = ResponseEntity.class) }) ResponseEntity addMember(
      @PathVariable(value = "groupName") String groupName,
      @RequestBody AddGroupMemberCommand addMemberCommand); @DeleteMapping(GROUP_MEMBER_END_POINT + "/{memberName}") @ApiOperation(value = "Remove member from group", response = ResponseEntity.class) @Transactional @ApiResponses({ @ApiResponse(code = 204, message = "Member removed from group", response = ResponseEntity.class) }) ResponseEntity removeMember(
      @PathVariable(value = "groupName") String groupName,
      @PathVariable(value = "memberName") String memberName); @PutMapping(GROUP_MEMBER_END_POINT + "/{memberName}") @ApiOperation(value = "Change membership role", response = ResponseEntity.class) @Transactional @ResponseStatus(HttpStatus.OK) @ApiResponses({ @ApiResponse(code = 200, message = "Updated membership role", response = ResponseEntity.class) }) void updateMember(
      @PathVariable(value = "groupName") String groupName,
      @PathVariable(value = "memberName") String memberName,
      @RequestBody UpdateGroupMemberCommand groupMember); @PutMapping(ROLE_EXTEND_END_POINT + "/{roleName}") @ApiOperation(value = "Change group role extension", response = ResponseEntity.class) @Transactional @ResponseStatus(HttpStatus.NO_CONTENT) @ApiResponses({ @ApiResponse(code = 204, message = "Updated membership role", response = ResponseEntity.class) }) void updateExtends(
      @PathVariable(value = "groupName") String groupName,
      @PathVariable(value = "roleName") String roleName,
      @RequestBody UpdateIncludeCommand updateExtendsCommand); @DeleteMapping(ROLE_EXTEND_END_POINT + "/{roleName}") @ApiOperation( value = "Remove extension from a grouprole from a role", response = ResponseEntity.class) @Transactional @ApiResponses({ @ApiResponse( code = 204, message = "Group role extension removed from role", response = ResponseEntity.class) }) ResponseEntity removeExtends(
      @PathVariable(value = "groupName") String groupName,
      @PathVariable(value = "roleName") String includingRoleName); @GetMapping(GROUP_END_POINT + "/{groupName}/role") @ApiOperation(value = "Get group roles", response = Collection.class) @ResponseBody Collection<RoleResponse> getGroupRoles(
      @PathVariable(value = "groupName") String groupName); @GetMapping(TEMP_USER_END_POINT) @ApiOperation(value = "Get all users", response = Collection.class) @ResponseBody @PreAuthorize("hasAnyRole('SU', 'MANAGER')") Collection<UserResponse> getUsers(); @GetMapping(GROUP_PERMISSION_END_POINT) @ApiOperation(value = "Get group permissions", response = Collection.class) @ApiResponses({ @ApiResponse( code = 200, message = "List of permissions for current user on group", response = Collection.class) }) @ResponseBody Collection<Permission> getPermissions(
      @PathVariable(value = "groupName") String groupName); }
IdentitiesApiController { @PostMapping(GROUP_MEMBER_END_POINT) @ApiOperation(value = "Add member to group", response = ResponseEntity.class) @Transactional @ApiResponses({ @ApiResponse(code = 201, message = "Member added to group", response = ResponseEntity.class) }) public ResponseEntity addMember( @PathVariable(value = "groupName") String groupName, @RequestBody AddGroupMemberCommand addMemberCommand) { checkGroupPermission(groupName, GroupPermission.ADD_MEMBERSHIP); final Group group = groupService.getGroup(groupName); final String username = addMemberCommand.getUsername(); final String roleName = addMemberCommand.getRoleName(); final Role role = roleService.getRole(roleName); final User user = userService.getUser(username); groupService.addMember(group, user, role); URI location = ServletUriComponentsBuilder.fromCurrentRequest() .path("/{member}") .buildAndExpand(username) .toUri(); return ResponseEntity.created(location).build(); } IdentitiesApiController(
      GroupValueFactory groupValueFactory,
      GroupService groupService,
      RoleMembershipService roleMembershipService,
      RoleService roleService,
      UserService userService,
      UserPermissionEvaluator userPermissionEvaluator); @PostMapping(GROUP_END_POINT) @ApiOperation(value = "Create a new group", response = ResponseEntity.class) @Transactional @ApiResponses({ @ApiResponse(code = 201, message = "New group created", response = ResponseEntity.class), @ApiResponse(code = 400, message = "Group name not available", response = ResponseEntity.class) }) ResponseEntity createGroup(@RequestBody GroupCommand group); @DeleteMapping(GROUP_END_POINT + "/{groupName}") @ApiOperation(value = "Delete a group", response = ResponseEntity.class) @Transactional @ApiResponses({ @ApiResponse(code = 204, message = "Group deleted", response = ResponseEntity.class), }) ResponseEntity deleteGroup(@PathVariable(value = "groupName") String groupName); @GetMapping(GROUP_END_POINT) @ApiOperation(value = "Get list with groups", response = ResponseEntity.class) @ApiResponses({ @ApiResponse( code = 200, message = "List of groupResponse object available to user", response = List.class) }) @ResponseBody List<GroupResponse> getGroups(); @GetMapping(GROUP_MEMBER_END_POINT) @ApiOperation(value = "Get group members", response = Collection.class) @ResponseBody Collection<GroupMemberResponse> getMembers(
      @PathVariable(value = "groupName") String groupName); @PostMapping(GROUP_MEMBER_END_POINT) @ApiOperation(value = "Add member to group", response = ResponseEntity.class) @Transactional @ApiResponses({ @ApiResponse(code = 201, message = "Member added to group", response = ResponseEntity.class) }) ResponseEntity addMember(
      @PathVariable(value = "groupName") String groupName,
      @RequestBody AddGroupMemberCommand addMemberCommand); @DeleteMapping(GROUP_MEMBER_END_POINT + "/{memberName}") @ApiOperation(value = "Remove member from group", response = ResponseEntity.class) @Transactional @ApiResponses({ @ApiResponse(code = 204, message = "Member removed from group", response = ResponseEntity.class) }) ResponseEntity removeMember(
      @PathVariable(value = "groupName") String groupName,
      @PathVariable(value = "memberName") String memberName); @PutMapping(GROUP_MEMBER_END_POINT + "/{memberName}") @ApiOperation(value = "Change membership role", response = ResponseEntity.class) @Transactional @ResponseStatus(HttpStatus.OK) @ApiResponses({ @ApiResponse(code = 200, message = "Updated membership role", response = ResponseEntity.class) }) void updateMember(
      @PathVariable(value = "groupName") String groupName,
      @PathVariable(value = "memberName") String memberName,
      @RequestBody UpdateGroupMemberCommand groupMember); @PutMapping(ROLE_EXTEND_END_POINT + "/{roleName}") @ApiOperation(value = "Change group role extension", response = ResponseEntity.class) @Transactional @ResponseStatus(HttpStatus.NO_CONTENT) @ApiResponses({ @ApiResponse(code = 204, message = "Updated membership role", response = ResponseEntity.class) }) void updateExtends(
      @PathVariable(value = "groupName") String groupName,
      @PathVariable(value = "roleName") String roleName,
      @RequestBody UpdateIncludeCommand updateExtendsCommand); @DeleteMapping(ROLE_EXTEND_END_POINT + "/{roleName}") @ApiOperation( value = "Remove extension from a grouprole from a role", response = ResponseEntity.class) @Transactional @ApiResponses({ @ApiResponse( code = 204, message = "Group role extension removed from role", response = ResponseEntity.class) }) ResponseEntity removeExtends(
      @PathVariable(value = "groupName") String groupName,
      @PathVariable(value = "roleName") String includingRoleName); @GetMapping(GROUP_END_POINT + "/{groupName}/role") @ApiOperation(value = "Get group roles", response = Collection.class) @ResponseBody Collection<RoleResponse> getGroupRoles(
      @PathVariable(value = "groupName") String groupName); @GetMapping(TEMP_USER_END_POINT) @ApiOperation(value = "Get all users", response = Collection.class) @ResponseBody @PreAuthorize("hasAnyRole('SU', 'MANAGER')") Collection<UserResponse> getUsers(); @GetMapping(GROUP_PERMISSION_END_POINT) @ApiOperation(value = "Get group permissions", response = Collection.class) @ApiResponses({ @ApiResponse( code = 200, message = "List of permissions for current user on group", response = Collection.class) }) @ResponseBody Collection<Permission> getPermissions(
      @PathVariable(value = "groupName") String groupName); static final String USER; }