@Test public void testSearchXResource() { List<RangerPolicy> rangerPolicyList = new ArrayList<RangerPolicy>(); List<VXResource> vXResourcesList = new ArrayList<VXResource>(); RangerService rangerService = rangerService(Id); long i; for (i = 1; i <= 2; i++) { RangerPolicy rangerPolicy = rangerPolicy(i); VXResource vXresource = vxResource(i); rangerPolicyList.add(rangerPolicy); vXResourcesList.add(vXresource); Mockito.when(serviceUtil.toVXResource(rangerPolicy, rangerService)).thenReturn(vXresource); } Mockito.when(serviceREST.getServiceByName(rangerPolicyList.get(0).getService())).thenReturn(rangerService); VXResourceList expectedVXResourceList = new VXResourceList(); expectedVXResourceList.setVXResources(vXResourcesList); SearchFilter searchFilter = new SearchFilter(); Mockito.when(searchUtil.getSearchFilterFromLegacyRequest(request, null)).thenReturn(searchFilter); Mockito.when(serviceREST.getPolicies(searchFilter)).thenReturn(rangerPolicyList); VXResourceList actualVXResourceList = assetREST.searchXResources(request); Assert.assertNotNull(actualVXResourceList); Assert.assertEquals(expectedVXResourceList.getVXResources(), actualVXResourceList.getVXResources()); Mockito.verify(searchUtil).getSearchFilterFromLegacyRequest(request, null); Mockito.verify(serviceREST).getPolicies(searchFilter); for (i = 0; i < 2; i++) { Mockito.verify(serviceUtil, Mockito.times(1)).toVXResource(rangerPolicyList.get((int) i), rangerService); } Mockito.verify(serviceREST, Mockito.times(2)).getServiceByName(rangerPolicyList.get(0).getService()); }
@GET @Path("/resources") @Produces({ "application/xml", "application/json" }) public VXResourceList searchXResources(@Context HttpServletRequest request) { if(logger.isDebugEnabled()) { logger.debug("==> AssetREST.searchXResources()"); } VXResourceList ret = new VXResourceList(); SearchFilter filter = searchUtil.getSearchFilterFromLegacyRequest(request, xResourceService.sortFields); List<RangerPolicy> policies = serviceREST.getPolicies(filter); if(policies != null) { List<VXResource> resources = new ArrayList<VXResource>(); for(RangerPolicy policy : policies) { RangerService service = serviceREST.getServiceByName(policy.getService()); VXResource resource = serviceUtil.toVXResource(policy, service); if(resource != null) { resources.add(resource); } } ret.setVXResources(resources); } if(logger.isDebugEnabled()) { logger.debug("<== AssetREST.searchXResources(): count=" + ret.getResultSize()); } return ret; }
AssetREST { @GET @Path("/resources") @Produces({ "application/xml", "application/json" }) public VXResourceList searchXResources(@Context HttpServletRequest request) { if(logger.isDebugEnabled()) { logger.debug("==> AssetREST.searchXResources()"); } VXResourceList ret = new VXResourceList(); SearchFilter filter = searchUtil.getSearchFilterFromLegacyRequest(request, xResourceService.sortFields); List<RangerPolicy> policies = serviceREST.getPolicies(filter); if(policies != null) { List<VXResource> resources = new ArrayList<VXResource>(); for(RangerPolicy policy : policies) { RangerService service = serviceREST.getServiceByName(policy.getService()); VXResource resource = serviceUtil.toVXResource(policy, service); if(resource != null) { resources.add(resource); } } ret.setVXResources(resources); } if(logger.isDebugEnabled()) { logger.debug("<== AssetREST.searchXResources(): count=" + ret.getResultSize()); } return ret; } }
AssetREST { @GET @Path("/resources") @Produces({ "application/xml", "application/json" }) public VXResourceList searchXResources(@Context HttpServletRequest request) { if(logger.isDebugEnabled()) { logger.debug("==> AssetREST.searchXResources()"); } VXResourceList ret = new VXResourceList(); SearchFilter filter = searchUtil.getSearchFilterFromLegacyRequest(request, xResourceService.sortFields); List<RangerPolicy> policies = serviceREST.getPolicies(filter); if(policies != null) { List<VXResource> resources = new ArrayList<VXResource>(); for(RangerPolicy policy : policies) { RangerService service = serviceREST.getServiceByName(policy.getService()); VXResource resource = serviceUtil.toVXResource(policy, service); if(resource != null) { resources.add(resource); } } ret.setVXResources(resources); } if(logger.isDebugEnabled()) { logger.debug("<== AssetREST.searchXResources(): count=" + ret.getResultSize()); } return ret; }  }
AssetREST { @GET @Path("/resources") @Produces({ "application/xml", "application/json" }) public VXResourceList searchXResources(@Context HttpServletRequest request) { if(logger.isDebugEnabled()) { logger.debug("==> AssetREST.searchXResources()"); } VXResourceList ret = new VXResourceList(); SearchFilter filter = searchUtil.getSearchFilterFromLegacyRequest(request, xResourceService.sortFields); List<RangerPolicy> policies = serviceREST.getPolicies(filter); if(policies != null) { List<VXResource> resources = new ArrayList<VXResource>(); for(RangerPolicy policy : policies) { RangerService service = serviceREST.getServiceByName(policy.getService()); VXResource resource = serviceUtil.toVXResource(policy, service); if(resource != null) { resources.add(resource); } } ret.setVXResources(resources); } if(logger.isDebugEnabled()) { logger.debug("<== AssetREST.searchXResources(): count=" + ret.getResultSize()); } return ret; }  @GET @Path("/assets/{id}") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_X_ASSET + "\")") VXAsset getXAsset(@PathParam("id") Long id); @POST @Path("/assets") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.CREATE_X_ASSET + "\")") VXAsset createXAsset(VXAsset vXAsset); @PUT @Path("/assets/{id}") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.UPDATE_X_ASSET + "\")") VXAsset updateXAsset(VXAsset vXAsset); @DELETE @Path("/assets/{id}") @RangerAnnotationClassName(class_name = VXAsset.class) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.DELETE_X_ASSET + "\")") void deleteXAsset(@PathParam("id") Long id,
			@Context HttpServletRequest request); @POST @Path("/assets/testConfig") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.TEST_CONFIG + "\")") VXResponse configTest(VXAsset vXAsset); @GET @Path("/assets") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.SEARCH_X_ASSETS + "\")") VXAssetList searchXAssets(@Context HttpServletRequest request); @GET @Path("/assets/count") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.COUNT_X_ASSETS + "\")") VXLong countXAssets(@Context HttpServletRequest request); @GET @Path("/resources/{id}") @Produces({ "application/xml", "application/json" }) VXResource getXResource(@PathParam("id") Long id); @POST @Path("/resources") @Produces({ "application/xml", "application/json" }) VXResource createXResource(VXResource vXResource); @PUT @Path("/resources/{id}") @Produces({ "application/xml", "application/json" }) VXResource updateXResource(VXResource vXResource); @DELETE @Path("/resources/{id}") @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") @RangerAnnotationClassName(class_name = VXResource.class) void deleteXResource(@PathParam("id") Long id,
			@Context HttpServletRequest request); @GET @Path("/resources") @Produces({ "application/xml", "application/json" }) VXResourceList searchXResources(@Context HttpServletRequest request); @GET @Path("/resources/count") @Produces({ "application/xml", "application/json" }) VXLong countXResources(@Context HttpServletRequest request); @GET @Path("/credstores/{id}") @Produces({ "application/xml", "application/json" }) VXCredentialStore getXCredentialStore(@PathParam("id") Long id); @POST @Path("/credstores") @Produces({ "application/xml", "application/json" }) VXCredentialStore createXCredentialStore(
			VXCredentialStore vXCredentialStore); @PUT @Path("/credstores") @Produces({ "application/xml", "application/json" }) VXCredentialStore updateXCredentialStore(
			VXCredentialStore vXCredentialStore); @DELETE @Path("/credstores/{id}") @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") @RangerAnnotationClassName(class_name = VXCredentialStore.class) void deleteXCredentialStore(@PathParam("id") Long id,
			@Context HttpServletRequest request); @GET @Path("/credstores") @Produces({ "application/xml", "application/json" }) VXCredentialStoreList searchXCredentialStores(
			@Context HttpServletRequest request); @GET @Path("/credstores/count") @Produces({ "application/xml", "application/json" }) VXLong countXCredentialStores(@Context HttpServletRequest request); @GET @Path("/resource/{id}") Response getXResourceFile(@Context HttpServletRequest request,
			@PathParam("id") Long id); @GET @Path("/policyList/{repository}") @Encoded String getResourceJSON(@Context HttpServletRequest request,
			@PathParam("repository") String repository); @GET @Path("/exportAudit") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.SEARCH_X_POLICY_EXPORT_AUDITS + "\")") VXPolicyExportAuditList searchXPolicyExportAudits(
			@Context HttpServletRequest request); @GET @Path("/report") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_REPORT_LOGS + "\")") VXTrxLogList getReportLogs(@Context HttpServletRequest request); @GET @Path("/report/{transactionId}") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_TRANSACTION_REPORT + "\")") VXTrxLogList getTransactionReport(@Context HttpServletRequest request,
			@PathParam("transactionId") String transactionId); @GET @Path("/accessAudit") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_ACCESS_LOGS + "\")") VXAccessAuditList getAccessLogs(@Context HttpServletRequest request); @POST @Path("/resources/grant") @Produces({ "application/xml", "application/json" }) VXPolicy grantPermission(@Context HttpServletRequest request,VXPolicy vXPolicy); @POST @Path("/resources/revoke") @Produces({ "application/xml", "application/json" }) VXPolicy revokePermission(@Context HttpServletRequest request,VXPolicy vXPolicy); @GET @Path("/ugsyncAudits") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_UGSYNC_AUDITS + "\")") VXUgsyncAuditInfoList getUgsyncAudits(@Context HttpServletRequest request); @GET @Path("/ugsyncAudits/{syncSource}") @Encoded @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_UGSYNC_AUDITS_BY_SYNCSOURCE + "\")") VXUgsyncAuditInfoList getUgsyncAuditsBySyncSource(@PathParam("syncSource") String syncSource); }
AssetREST { @GET @Path("/resources") @Produces({ "application/xml", "application/json" }) public VXResourceList searchXResources(@Context HttpServletRequest request) { if(logger.isDebugEnabled()) { logger.debug("==> AssetREST.searchXResources()"); } VXResourceList ret = new VXResourceList(); SearchFilter filter = searchUtil.getSearchFilterFromLegacyRequest(request, xResourceService.sortFields); List<RangerPolicy> policies = serviceREST.getPolicies(filter); if(policies != null) { List<VXResource> resources = new ArrayList<VXResource>(); for(RangerPolicy policy : policies) { RangerService service = serviceREST.getServiceByName(policy.getService()); VXResource resource = serviceUtil.toVXResource(policy, service); if(resource != null) { resources.add(resource); } } ret.setVXResources(resources); } if(logger.isDebugEnabled()) { logger.debug("<== AssetREST.searchXResources(): count=" + ret.getResultSize()); } return ret; }  @GET @Path("/assets/{id}") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_X_ASSET + "\")") VXAsset getXAsset(@PathParam("id") Long id); @POST @Path("/assets") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.CREATE_X_ASSET + "\")") VXAsset createXAsset(VXAsset vXAsset); @PUT @Path("/assets/{id}") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.UPDATE_X_ASSET + "\")") VXAsset updateXAsset(VXAsset vXAsset); @DELETE @Path("/assets/{id}") @RangerAnnotationClassName(class_name = VXAsset.class) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.DELETE_X_ASSET + "\")") void deleteXAsset(@PathParam("id") Long id,
			@Context HttpServletRequest request); @POST @Path("/assets/testConfig") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.TEST_CONFIG + "\")") VXResponse configTest(VXAsset vXAsset); @GET @Path("/assets") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.SEARCH_X_ASSETS + "\")") VXAssetList searchXAssets(@Context HttpServletRequest request); @GET @Path("/assets/count") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.COUNT_X_ASSETS + "\")") VXLong countXAssets(@Context HttpServletRequest request); @GET @Path("/resources/{id}") @Produces({ "application/xml", "application/json" }) VXResource getXResource(@PathParam("id") Long id); @POST @Path("/resources") @Produces({ "application/xml", "application/json" }) VXResource createXResource(VXResource vXResource); @PUT @Path("/resources/{id}") @Produces({ "application/xml", "application/json" }) VXResource updateXResource(VXResource vXResource); @DELETE @Path("/resources/{id}") @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") @RangerAnnotationClassName(class_name = VXResource.class) void deleteXResource(@PathParam("id") Long id,
			@Context HttpServletRequest request); @GET @Path("/resources") @Produces({ "application/xml", "application/json" }) VXResourceList searchXResources(@Context HttpServletRequest request); @GET @Path("/resources/count") @Produces({ "application/xml", "application/json" }) VXLong countXResources(@Context HttpServletRequest request); @GET @Path("/credstores/{id}") @Produces({ "application/xml", "application/json" }) VXCredentialStore getXCredentialStore(@PathParam("id") Long id); @POST @Path("/credstores") @Produces({ "application/xml", "application/json" }) VXCredentialStore createXCredentialStore(
			VXCredentialStore vXCredentialStore); @PUT @Path("/credstores") @Produces({ "application/xml", "application/json" }) VXCredentialStore updateXCredentialStore(
			VXCredentialStore vXCredentialStore); @DELETE @Path("/credstores/{id}") @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") @RangerAnnotationClassName(class_name = VXCredentialStore.class) void deleteXCredentialStore(@PathParam("id") Long id,
			@Context HttpServletRequest request); @GET @Path("/credstores") @Produces({ "application/xml", "application/json" }) VXCredentialStoreList searchXCredentialStores(
			@Context HttpServletRequest request); @GET @Path("/credstores/count") @Produces({ "application/xml", "application/json" }) VXLong countXCredentialStores(@Context HttpServletRequest request); @GET @Path("/resource/{id}") Response getXResourceFile(@Context HttpServletRequest request,
			@PathParam("id") Long id); @GET @Path("/policyList/{repository}") @Encoded String getResourceJSON(@Context HttpServletRequest request,
			@PathParam("repository") String repository); @GET @Path("/exportAudit") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.SEARCH_X_POLICY_EXPORT_AUDITS + "\")") VXPolicyExportAuditList searchXPolicyExportAudits(
			@Context HttpServletRequest request); @GET @Path("/report") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_REPORT_LOGS + "\")") VXTrxLogList getReportLogs(@Context HttpServletRequest request); @GET @Path("/report/{transactionId}") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_TRANSACTION_REPORT + "\")") VXTrxLogList getTransactionReport(@Context HttpServletRequest request,
			@PathParam("transactionId") String transactionId); @GET @Path("/accessAudit") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_ACCESS_LOGS + "\")") VXAccessAuditList getAccessLogs(@Context HttpServletRequest request); @POST @Path("/resources/grant") @Produces({ "application/xml", "application/json" }) VXPolicy grantPermission(@Context HttpServletRequest request,VXPolicy vXPolicy); @POST @Path("/resources/revoke") @Produces({ "application/xml", "application/json" }) VXPolicy revokePermission(@Context HttpServletRequest request,VXPolicy vXPolicy); @GET @Path("/ugsyncAudits") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_UGSYNC_AUDITS + "\")") VXUgsyncAuditInfoList getUgsyncAudits(@Context HttpServletRequest request); @GET @Path("/ugsyncAudits/{syncSource}") @Encoded @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_UGSYNC_AUDITS_BY_SYNCSOURCE + "\")") VXUgsyncAuditInfoList getUgsyncAuditsBySyncSource(@PathParam("syncSource") String syncSource);  }