@Test @WithMockUser(roles = {"MANAGER"}) void testGetUsers() throws Exception { when(user.getId()).thenReturn("id"); when(user.getUsername()).thenReturn("name"); User anonymousUser = mock(User.class); when(anonymousUser.getUsername()).thenReturn("anonymous"); when(userService.getUsers()).thenReturn(Arrays.asList(user, anonymousUser)); mockMvc .perform(get(TEMP_USER_END_POINT)) .andExpect(status().isOk()) .andExpect(jsonPath("$", hasSize(1))) .andExpect(jsonPath("$[0].id", is("id"))) .andExpect(jsonPath("$[0].username", is("name"))); }
@GetMapping(TEMP_USER_END_POINT) @ApiOperation(value = "Get all users", response = Collection.class) @ResponseBody @PreAuthorize("hasAnyRole('SU', 'MANAGER')") public Collection<UserResponse> getUsers() { return userService.getUsers().stream() .filter(u -> !u.getUsername().equals("anonymous")) .map(UserResponse::fromEntity) .collect(Collectors.toList()); }
IdentitiesApiController { @GetMapping(TEMP_USER_END_POINT) @ApiOperation(value = "Get all users", response = Collection.class) @ResponseBody @PreAuthorize("hasAnyRole('SU', 'MANAGER')") public Collection<UserResponse> getUsers() { return userService.getUsers().stream() .filter(u -> !u.getUsername().equals("anonymous")) .map(UserResponse::fromEntity) .collect(Collectors.toList()); } }
IdentitiesApiController { @GetMapping(TEMP_USER_END_POINT) @ApiOperation(value = "Get all users", response = Collection.class) @ResponseBody @PreAuthorize("hasAnyRole('SU', 'MANAGER')") public Collection<UserResponse> getUsers() { return userService.getUsers().stream() .filter(u -> !u.getUsername().equals("anonymous")) .map(UserResponse::fromEntity) .collect(Collectors.toList()); } IdentitiesApiController(
      GroupValueFactory groupValueFactory,
      GroupService groupService,
      RoleMembershipService roleMembershipService,
      RoleService roleService,
      UserService userService,
      UserPermissionEvaluator userPermissionEvaluator); }
IdentitiesApiController { @GetMapping(TEMP_USER_END_POINT) @ApiOperation(value = "Get all users", response = Collection.class) @ResponseBody @PreAuthorize("hasAnyRole('SU', 'MANAGER')") public Collection<UserResponse> getUsers() { return userService.getUsers().stream() .filter(u -> !u.getUsername().equals("anonymous")) .map(UserResponse::fromEntity) .collect(Collectors.toList()); } 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 { @GetMapping(TEMP_USER_END_POINT) @ApiOperation(value = "Get all users", response = Collection.class) @ResponseBody @PreAuthorize("hasAnyRole('SU', 'MANAGER')") public Collection<UserResponse> getUsers() { return userService.getUsers().stream() .filter(u -> !u.getUsername().equals("anonymous")) .map(UserResponse::fromEntity) .collect(Collectors.toList()); } 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; }