@Test public void testGetEdOrgs() { 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.hasRole(RoleInitializer.LEA_ADMINISTRATOR)).thenReturn(false); Response res = resource.getEdOrgs(); Assert.assertEquals(200, res.getStatus()); Assert.assertEquals(new LinkedList<String>(), res.getEntity()); Mockito.when(secUtil.getTenantId()).thenReturn(TENANT); rights.remove(Right.CRUD_SLC_OPERATOR); Mockito.when(adminService.getAllowedEdOrgs(TENANT, null)).thenReturn( new HashSet<String>(Arrays.asList(EDORG1, EDORG2))); res = resource.getEdOrgs(); Assert.assertEquals(200, res.getStatus()); Assert.assertEquals(Arrays.asList(EDORG1, EDORG2), res.getEntity()); rights.remove(Right.CRUD_SEA_ADMIN); Mockito.when(secUtil.getEdOrg()).thenReturn(EDORG1); Mockito.when(adminService.getAllowedEdOrgs(TENANT, EDORG1)).thenReturn( new HashSet<String>(Arrays.asList(EDORG1, EDORG2))); res = resource.getEdOrgs(); Assert.assertEquals(200, res.getStatus()); Assert.assertEquals(Arrays.asList(EDORG1, EDORG2), res.getEntity()); }
@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 }) public final Response getEdOrgs() { String tenant = secUtil.getTenantId(); Response result = validateAdminRights(secUtil.getAllRights(), tenant); if (result != null) { return result; } if (tenant == null) { List<String> edorgs = new LinkedList<String>(); return Response.status(Status.OK).entity(edorgs).build(); } String restrictByEdOrg = this.isLeaAdmin() ? secUtil.getEdOrg() : null; ArrayList<String> edOrgs = new ArrayList<String>(adminService.getAllowedEdOrgs(tenant, restrictByEdOrg)); Collections.sort(edOrgs); return Response.status(Status.OK).entity(edOrgs).build(); }
UserResource { @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 }) public final Response getEdOrgs() { String tenant = secUtil.getTenantId(); Response result = validateAdminRights(secUtil.getAllRights(), tenant); if (result != null) { return result; } if (tenant == null) { List<String> edorgs = new LinkedList<String>(); return Response.status(Status.OK).entity(edorgs).build(); } String restrictByEdOrg = this.isLeaAdmin() ? secUtil.getEdOrg() : null; ArrayList<String> edOrgs = new ArrayList<String>(adminService.getAllowedEdOrgs(tenant, restrictByEdOrg)); Collections.sort(edOrgs); return Response.status(Status.OK).entity(edOrgs).build(); } }
UserResource { @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 }) public final Response getEdOrgs() { String tenant = secUtil.getTenantId(); Response result = validateAdminRights(secUtil.getAllRights(), tenant); if (result != null) { return result; } if (tenant == null) { List<String> edorgs = new LinkedList<String>(); return Response.status(Status.OK).entity(edorgs).build(); } String restrictByEdOrg = this.isLeaAdmin() ? secUtil.getEdOrg() : null; ArrayList<String> edOrgs = new ArrayList<String>(adminService.getAllowedEdOrgs(tenant, restrictByEdOrg)); Collections.sort(edOrgs); return Response.status(Status.OK).entity(edOrgs).build(); }  }
UserResource { @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 }) public final Response getEdOrgs() { String tenant = secUtil.getTenantId(); Response result = validateAdminRights(secUtil.getAllRights(), tenant); if (result != null) { return result; } if (tenant == null) { List<String> edorgs = new LinkedList<String>(); return Response.status(Status.OK).entity(edorgs).build(); } String restrictByEdOrg = this.isLeaAdmin() ? secUtil.getEdOrg() : null; ArrayList<String> edOrgs = new ArrayList<String>(adminService.getAllowedEdOrgs(tenant, restrictByEdOrg)); Collections.sort(edOrgs); return Response.status(Status.OK).entity(edOrgs).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 @Path("edorgs") @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 getEdOrgs() { String tenant = secUtil.getTenantId(); Response result = validateAdminRights(secUtil.getAllRights(), tenant); if (result != null) { return result; } if (tenant == null) { List<String> edorgs = new LinkedList<String>(); return Response.status(Status.OK).entity(edorgs).build(); } String restrictByEdOrg = this.isLeaAdmin() ? secUtil.getEdOrg() : null; ArrayList<String> edOrgs = new ArrayList<String>(adminService.getAllowedEdOrgs(tenant, restrictByEdOrg)); Collections.sort(edOrgs); return Response.status(Status.OK).entity(edOrgs).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);  }