@SuppressWarnings("unchecked") @Test public void testReadAll() { Collection<GrantedAuthority> rights = new HashSet<GrantedAuthority>(); rights.addAll(Arrays.asList(Right.CRUD_SLC_OPERATOR, Right.CRUD_SEA_ADMIN, Right.CRUD_LEA_ADMIN)); Mockito.when(secUtil.getAllRights()).thenReturn(rights); Mockito.when(secUtil.getUid()).thenReturn("myUid"); Mockito.when(secUtil.hasRole(RoleInitializer.LEA_ADMINISTRATOR)).thenReturn(false); List<User> users = Arrays.asList(new User(), new User()); Mockito.when( ldap.findUsersByGroups(Mockito.eq(REALM), Mockito.anyCollectionOf(String.class), Mockito.anyCollectionOf(String.class), Mockito.anyString(), (Collection<String>) Mockito.isNull())).thenReturn(users); Response res = resource.readAll(); Assert.assertEquals(200, res.getStatus()); Object entity = res.getEntity(); Assert.assertEquals(users, entity); }
@GET @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) public final Response readAll() { String tenant = secUtil.getTenantId(); String edorg = secUtil.getEdOrg(); Response result = validateAdminRights(secUtil.getAllRights(), tenant); if (result != null) { return result; } Collection<String> edorgs = null; if (secUtil.hasRole(RoleInitializer.LEA_ADMINISTRATOR)) { edorgs = new ArrayList<String>(); edorgs.addAll(adminService.getAllowedEdOrgs(tenant, edorg)); } Set<String> groupsToIgnore = new HashSet<String>(); if (isLeaAdmin()) { groupsToIgnore.add(RoleInitializer.SLC_OPERATOR); groupsToIgnore.add(RoleInitializer.SEA_ADMINISTRATOR); } Collection<User> users = ldapService.findUsersByGroups(realm, RightToGroupMapper.getInstance().getGroups(secUtil.getAllRights()), groupsToIgnore, secUtil.getTenantId(), edorgs); if (users != null && users.size() > 0) { for (User user : users) { user.setGroups((List<String>) (RoleToGroupMapper.getInstance().mapGroupToRoles(user.getGroups()))); } } return Response.status(Status.OK).entity(users).build(); }
UserResource { @GET @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) public final Response readAll() { String tenant = secUtil.getTenantId(); String edorg = secUtil.getEdOrg(); Response result = validateAdminRights(secUtil.getAllRights(), tenant); if (result != null) { return result; } Collection<String> edorgs = null; if (secUtil.hasRole(RoleInitializer.LEA_ADMINISTRATOR)) { edorgs = new ArrayList<String>(); edorgs.addAll(adminService.getAllowedEdOrgs(tenant, edorg)); } Set<String> groupsToIgnore = new HashSet<String>(); if (isLeaAdmin()) { groupsToIgnore.add(RoleInitializer.SLC_OPERATOR); groupsToIgnore.add(RoleInitializer.SEA_ADMINISTRATOR); } Collection<User> users = ldapService.findUsersByGroups(realm, RightToGroupMapper.getInstance().getGroups(secUtil.getAllRights()), groupsToIgnore, secUtil.getTenantId(), edorgs); if (users != null && users.size() > 0) { for (User user : users) { user.setGroups((List<String>) (RoleToGroupMapper.getInstance().mapGroupToRoles(user.getGroups()))); } } return Response.status(Status.OK).entity(users).build(); } }
UserResource { @GET @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) public final Response readAll() { String tenant = secUtil.getTenantId(); String edorg = secUtil.getEdOrg(); Response result = validateAdminRights(secUtil.getAllRights(), tenant); if (result != null) { return result; } Collection<String> edorgs = null; if (secUtil.hasRole(RoleInitializer.LEA_ADMINISTRATOR)) { edorgs = new ArrayList<String>(); edorgs.addAll(adminService.getAllowedEdOrgs(tenant, edorg)); } Set<String> groupsToIgnore = new HashSet<String>(); if (isLeaAdmin()) { groupsToIgnore.add(RoleInitializer.SLC_OPERATOR); groupsToIgnore.add(RoleInitializer.SEA_ADMINISTRATOR); } Collection<User> users = ldapService.findUsersByGroups(realm, RightToGroupMapper.getInstance().getGroups(secUtil.getAllRights()), groupsToIgnore, secUtil.getTenantId(), edorgs); if (users != null && users.size() > 0) { for (User user : users) { user.setGroups((List<String>) (RoleToGroupMapper.getInstance().mapGroupToRoles(user.getGroups()))); } } return Response.status(Status.OK).entity(users).build(); }  }
UserResource { @GET @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) public final Response readAll() { String tenant = secUtil.getTenantId(); String edorg = secUtil.getEdOrg(); Response result = validateAdminRights(secUtil.getAllRights(), tenant); if (result != null) { return result; } Collection<String> edorgs = null; if (secUtil.hasRole(RoleInitializer.LEA_ADMINISTRATOR)) { edorgs = new ArrayList<String>(); edorgs.addAll(adminService.getAllowedEdOrgs(tenant, edorg)); } Set<String> groupsToIgnore = new HashSet<String>(); if (isLeaAdmin()) { groupsToIgnore.add(RoleInitializer.SLC_OPERATOR); groupsToIgnore.add(RoleInitializer.SEA_ADMINISTRATOR); } Collection<User> users = ldapService.findUsersByGroups(realm, RightToGroupMapper.getInstance().getGroups(secUtil.getAllRights()), groupsToIgnore, secUtil.getTenantId(), edorgs); if (users != null && users.size() > 0) { for (User user : users) { user.setGroups((List<String>) (RoleToGroupMapper.getInstance().mapGroupToRoles(user.getGroups()))); } } return Response.status(Status.OK).entity(users).build(); }  @POST @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response create(final User newUser); @GET @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response readAll(); @PUT @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response update(final User updateUser); @DELETE @Path("{uid}") @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response delete(@PathParam("uid") final String uid); @GET @Path("edorgs") @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response getEdOrgs(); void setRealm(String realm); }
UserResource { @GET @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) public final Response readAll() { String tenant = secUtil.getTenantId(); String edorg = secUtil.getEdOrg(); Response result = validateAdminRights(secUtil.getAllRights(), tenant); if (result != null) { return result; } Collection<String> edorgs = null; if (secUtil.hasRole(RoleInitializer.LEA_ADMINISTRATOR)) { edorgs = new ArrayList<String>(); edorgs.addAll(adminService.getAllowedEdOrgs(tenant, edorg)); } Set<String> groupsToIgnore = new HashSet<String>(); if (isLeaAdmin()) { groupsToIgnore.add(RoleInitializer.SLC_OPERATOR); groupsToIgnore.add(RoleInitializer.SEA_ADMINISTRATOR); } Collection<User> users = ldapService.findUsersByGroups(realm, RightToGroupMapper.getInstance().getGroups(secUtil.getAllRights()), groupsToIgnore, secUtil.getTenantId(), edorgs); if (users != null && users.size() > 0) { for (User user : users) { user.setGroups((List<String>) (RoleToGroupMapper.getInstance().mapGroupToRoles(user.getGroups()))); } } return Response.status(Status.OK).entity(users).build(); }  @POST @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response create(final User newUser); @GET @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response readAll(); @PUT @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response update(final User updateUser); @DELETE @Path("{uid}") @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response delete(@PathParam("uid") final String uid); @GET @Path("edorgs") @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response getEdOrgs(); void setRealm(String realm);  }