@Test public void usersByPrivilegeAndGroupTest() throws Exception { String privilege = "acm-privilege"; String role1 = "ROLE_ADMINISTRATOR"; String role2 = "ROLE_INVESTIGATOR_SUPERVISOR"; Set<AcmUser> membersGroup1 = new HashSet<>(); AcmUser user1 = new AcmUser(); user1.setUserId("user1"); user1.setUserState(AcmUserState.VALID); AcmUser user2 = new AcmUser(); user2.setUserId("user2"); user2.setUserState(AcmUserState.VALID); membersGroup1.addAll(Arrays.asList(user1, user2)); AcmGroup group1 = new AcmGroup(); group1.setName("acm_administrator_dev"); group1.setUserMembers(membersGroup1); Set<AcmUser> membersGroup2 = new HashSet<>(); AcmUser user3 = new AcmUser(); user3.setUserId("user3"); AcmUser user4 = new AcmUser(); user4.setUserId("user4"); membersGroup2.addAll(Arrays.asList(user3, user4)); AcmGroup group2 = new AcmGroup(); group2.setName("acm_supervisor_dev"); group2.setUserMembers(membersGroup2); List<AcmUser> expectedUserList = Arrays.asList(user1, user2); List<String> rolesForPrivilege = Arrays.asList(role1, role2); Map<String, List<String>> rolesToGroups = new HashMap<>(); rolesToGroups.put(role1, Arrays.asList(group1.getName())); rolesToGroups.put(role2, Arrays.asList(group2.getName())); expect(mockAuthentication.getName()).andReturn("user"); expect(mockPluginManager.getRolesForPrivilege(privilege)).andReturn(rolesForPrivilege); expect(mockFunctionalAccessService.getApplicationRolesToGroups()).andReturn(rolesToGroups); expect(mockFunctionalAccessService.getUsersByRolesAndGroups(rolesForPrivilege, rolesToGroups, group1.getName(), null)) .andReturn(group1.getUserMembers(true)); replayAll(); MvcResult result = mockMvc.perform( get("/api/latest/service/functionalaccess/users/{privilege}/{group}", privilege, group1.getName()) .accept(MediaType.parseMediaType("application/json;charset=UTF-8")) .contentType(MediaType.APPLICATION_JSON) .principal(mockAuthentication)) .andReturn(); verifyAll(); LOG.info("Results: " + result.getResponse().getContentAsString()); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); List<AcmUser> resultUserList = mapper.readValue(result.getResponse().getContentAsString(), new TypeReference<ArrayList<AcmUser>>() { }); assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus()); assertEquals(expectedUserList.size(), resultUserList.size()); for (AcmUser expected : expectedUserList) { assertTrue(resultUserList.contains(expected)); } }
@RequestMapping(method = RequestMethod.GET, value = "/users/{privilege}/{group}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List<AcmUser> usersByPrivilegeAndGroup(@PathVariable(value = "privilege") String privilege, @PathVariable(value = "group") String group) { if (log.isDebugEnabled()) { log.debug("Looking for users for privilege '" + privilege + "' and group " + group); } List<AcmUser> retval = new ArrayList<>(); List<String> rolesForPrivilege = getPluginManager().getRolesForPrivilege(privilege); Map<String, List<String>> rolesToGroups = getFunctionalAccessService().getApplicationRolesToGroups(); Set<AcmUser> users = getFunctionalAccessService().getUsersByRolesAndGroups(rolesForPrivilege, rolesToGroups, group, null); retval.addAll(users); return retval; }
GetUsersByPrivilegeAndGroupAPIController { @RequestMapping(method = RequestMethod.GET, value = "/users/{privilege}/{group}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List<AcmUser> usersByPrivilegeAndGroup(@PathVariable(value = "privilege") String privilege, @PathVariable(value = "group") String group) { if (log.isDebugEnabled()) { log.debug("Looking for users for privilege '" + privilege + "' and group " + group); } List<AcmUser> retval = new ArrayList<>(); List<String> rolesForPrivilege = getPluginManager().getRolesForPrivilege(privilege); Map<String, List<String>> rolesToGroups = getFunctionalAccessService().getApplicationRolesToGroups(); Set<AcmUser> users = getFunctionalAccessService().getUsersByRolesAndGroups(rolesForPrivilege, rolesToGroups, group, null); retval.addAll(users); return retval; } }
GetUsersByPrivilegeAndGroupAPIController { @RequestMapping(method = RequestMethod.GET, value = "/users/{privilege}/{group}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List<AcmUser> usersByPrivilegeAndGroup(@PathVariable(value = "privilege") String privilege, @PathVariable(value = "group") String group) { if (log.isDebugEnabled()) { log.debug("Looking for users for privilege '" + privilege + "' and group " + group); } List<AcmUser> retval = new ArrayList<>(); List<String> rolesForPrivilege = getPluginManager().getRolesForPrivilege(privilege); Map<String, List<String>> rolesToGroups = getFunctionalAccessService().getApplicationRolesToGroups(); Set<AcmUser> users = getFunctionalAccessService().getUsersByRolesAndGroups(rolesForPrivilege, rolesToGroups, group, null); retval.addAll(users); return retval; }  }
GetUsersByPrivilegeAndGroupAPIController { @RequestMapping(method = RequestMethod.GET, value = "/users/{privilege}/{group}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List<AcmUser> usersByPrivilegeAndGroup(@PathVariable(value = "privilege") String privilege, @PathVariable(value = "group") String group) { if (log.isDebugEnabled()) { log.debug("Looking for users for privilege '" + privilege + "' and group " + group); } List<AcmUser> retval = new ArrayList<>(); List<String> rolesForPrivilege = getPluginManager().getRolesForPrivilege(privilege); Map<String, List<String>> rolesToGroups = getFunctionalAccessService().getApplicationRolesToGroups(); Set<AcmUser> users = getFunctionalAccessService().getUsersByRolesAndGroups(rolesForPrivilege, rolesToGroups, group, null); retval.addAll(users); return retval; }  @RequestMapping(method = RequestMethod.GET, value = "/users/{privilege}", produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody List<AcmUser> usersByPrivilege(@PathVariable(value = "privilege") String privilege); @RequestMapping(method = RequestMethod.GET, value = "/users/{privilege}/{group}", produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody List<AcmUser> usersByPrivilegeAndGroup(@PathVariable(value = "privilege") String privilege,
            @PathVariable(value = "group") String group); @RequestMapping(method = RequestMethod.GET, value = "/users/{privilege}/{group}/{currentAssignee}", produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody List<AcmUser> usersByPrivilegeAndGroupPlusCurrentAssignee(@PathVariable(value = "privilege") String privilege,
            @PathVariable(value = "group") String group,
            @PathVariable(value = "currentAssignee") String currentAssignee); AcmPluginManager getPluginManager(); void setPluginManager(AcmPluginManager pluginManager); FunctionalAccessService getFunctionalAccessService(); void setFunctionalAccessService(
            FunctionalAccessService functionalAccessService); }
GetUsersByPrivilegeAndGroupAPIController { @RequestMapping(method = RequestMethod.GET, value = "/users/{privilege}/{group}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List<AcmUser> usersByPrivilegeAndGroup(@PathVariable(value = "privilege") String privilege, @PathVariable(value = "group") String group) { if (log.isDebugEnabled()) { log.debug("Looking for users for privilege '" + privilege + "' and group " + group); } List<AcmUser> retval = new ArrayList<>(); List<String> rolesForPrivilege = getPluginManager().getRolesForPrivilege(privilege); Map<String, List<String>> rolesToGroups = getFunctionalAccessService().getApplicationRolesToGroups(); Set<AcmUser> users = getFunctionalAccessService().getUsersByRolesAndGroups(rolesForPrivilege, rolesToGroups, group, null); retval.addAll(users); return retval; }  @RequestMapping(method = RequestMethod.GET, value = "/users/{privilege}", produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody List<AcmUser> usersByPrivilege(@PathVariable(value = "privilege") String privilege); @RequestMapping(method = RequestMethod.GET, value = "/users/{privilege}/{group}", produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody List<AcmUser> usersByPrivilegeAndGroup(@PathVariable(value = "privilege") String privilege,
            @PathVariable(value = "group") String group); @RequestMapping(method = RequestMethod.GET, value = "/users/{privilege}/{group}/{currentAssignee}", produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody List<AcmUser> usersByPrivilegeAndGroupPlusCurrentAssignee(@PathVariable(value = "privilege") String privilege,
            @PathVariable(value = "group") String group,
            @PathVariable(value = "currentAssignee") String currentAssignee); AcmPluginManager getPluginManager(); void setPluginManager(AcmPluginManager pluginManager); FunctionalAccessService getFunctionalAccessService(); void setFunctionalAccessService(
            FunctionalAccessService functionalAccessService);  }