AssetREST { @GET @Path("/policyList/{repository}") @Encoded public String getResourceJSON(@Context HttpServletRequest request, @PathParam("repository") String repository) { String epoch = request.getParameter("epoch"); X509Certificate[] certchain = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate"); String ipAddress = request.getHeader("X-FORWARDED-FOR"); boolean isSecure = request.isSecure(); String policyCount = request.getParameter("policyCount"); String agentId = request.getParameter("agentId"); Long lastKnowPolicyVersion = Long.valueOf(-1); String capabilityVector = "0"; if (ipAddress == null) { ipAddress = request.getRemoteAddr(); } boolean httpEnabled = PropertiesUtil.getBooleanProperty("ranger.service.http.enabled",true); ServicePolicies servicePolicies = null; try { servicePolicies = serviceREST.getServicePoliciesIfUpdated(repository, lastKnowPolicyVersion, 0L, agentId, "", "", false, capabilityVector, request); } catch(Exception excp) { logger.error("failed to retrieve policies for repository " + repository, excp); } RangerService service = serviceUtil.getServiceByName(repository); List<RangerPolicy> policies = servicePolicies != null ? servicePolicies.getPolicies() : null; long policyUpdTime = (servicePolicies != null && servicePolicies.getPolicyUpdateTime() != null) ? servicePolicies.getPolicyUpdateTime().getTime() : 0l; VXAsset vAsset = serviceUtil.toVXAsset(service); List<VXResource> vResourceList = new ArrayList<VXResource>(); if(policies != null) { for(RangerPolicy policy : policies) { vResourceList.add(serviceUtil.toVXResource(policy, service)); } } String file = assetMgr.getLatestRepoPolicy(vAsset, vResourceList, policyUpdTime, certchain, httpEnabled, epoch, ipAddress, isSecure, policyCount, agentId); return file; }  @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);  }
@Test public void testGetResourceJSON() { RangerService rangerService = rangerService(Id); String file = "testGetResourceJSON"; VXAsset vXAsset = vXAsset(Id); Date date = new Date(); String strdt = date.toString(); X509Certificate[] certchain = new X509Certificate[1]; certchain[0] = Mockito.mock(X509Certificate.class); ServicePolicies servicePolicies = servicePolicies(); RangerPolicy rangerPolicy = rangerPolicy(Id); List<RangerPolicy> policies = new ArrayList<RangerPolicy>(); policies.add(rangerPolicy); Mockito.when(request.getParameter("epoch")).thenReturn(strdt); Mockito.when(request.getAttribute("javax.servlet.request.X509Certificate")).thenReturn(certchain); Mockito.when(request.getHeader("X-FORWARDED-FOR")).thenReturn("valid"); Mockito.when(request.isSecure()).thenReturn(true); Mockito.when(request.getParameter("policyCount")).thenReturn("4"); Mockito.when(request.getParameter("agentId")).thenReturn("12"); try { Mockito.when(serviceREST.getServicePoliciesIfUpdated(Mockito.anyString(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyString(), Mockito.anyString() , Mockito.anyString() , Mockito.anyBoolean(), Mockito.anyString(), (HttpServletRequest) Mockito.any())) .thenReturn(servicePolicies); } catch (Exception e) { fail("test failed due to: " + e.getMessage()); } Mockito.when(serviceUtil.getServiceByName("hdfs_dev")).thenReturn(rangerService); Mockito.when(serviceUtil.toVXAsset(rangerService)).thenReturn(vXAsset); Mockito.when(assetMgr.getLatestRepoPolicy((VXAsset) Mockito.any(), Mockito.<VXResource>anyList(), Mockito.anyLong(), (X509Certificate[]) Mockito.any(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyString())).thenReturn(file); String actualFile = assetREST.getResourceJSON(request, "hdfs_dev"); Assert.assertEquals(file, actualFile); Mockito.verify(serviceUtil).getServiceByName("hdfs_dev"); Mockito.verify(serviceUtil).toVXAsset(rangerService); Mockito.verify(request).getParameter("epoch"); Mockito.verify(request).getAttribute("javax.servlet.request.X509Certificate"); Mockito.verify(request).getHeader("X-FORWARDED-FOR"); Mockito.verify(request).isSecure(); Mockito.verify(request).getParameter("policyCount"); Mockito.verify(request).getParameter("agentId"); Mockito.verify(assetMgr).getLatestRepoPolicy((VXAsset) Mockito.any(), Mockito.<VXResource>anyList(), Mockito.anyLong(), (X509Certificate[]) Mockito.any(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyString()); }