AssetREST { @GET @Path("/accessAudit") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_ACCESS_LOGS + "\")") public VXAccessAuditList getAccessLogs(@Context HttpServletRequest request){ SearchCriteria searchCriteria = searchUtil.extractCommonCriterias( request, xAccessAuditService.sortFields); searchUtil.extractString(request, searchCriteria, "accessType", "Access Type", StringUtil.VALIDATION_TEXT); searchUtil.extractString(request, searchCriteria, "aclEnforcer", "Access Enforcer", StringUtil.VALIDATION_TEXT); searchUtil.extractString(request, searchCriteria, "agentId", "Application", StringUtil.VALIDATION_TEXT); searchUtil.extractString(request, searchCriteria, "repoName", "Service Name", StringUtil.VALIDATION_TEXT); searchUtil.extractString(request, searchCriteria, "sessionId", "Session ID", StringUtil.VALIDATION_TEXT); searchUtil.extractStringList(request, searchCriteria, "requestUser", "Users", "requestUser", null, StringUtil.VALIDATION_TEXT); searchUtil.extractStringList(request, searchCriteria, "excludeUser", "Exclude Users", "-requestUser", null, StringUtil.VALIDATION_TEXT); searchUtil.extractString(request, searchCriteria, "requestData", "Request Data", StringUtil.VALIDATION_TEXT); searchUtil.extractString(request, searchCriteria, "resourcePath", "Resource Name", StringUtil.VALIDATION_TEXT); searchUtil.extractString(request, searchCriteria, "clientIP", "Client IP", StringUtil.VALIDATION_TEXT); searchUtil.extractString(request, searchCriteria, "resourceType", "Resource Type", StringUtil.VALIDATION_TEXT); searchUtil.extractString(request,searchCriteria,"excludeServiceUser", "Exclude Service User",StringUtil.VALIDATION_TEXT); searchUtil.extractInt(request, searchCriteria, "auditType", "Audit Type"); searchUtil.extractInt(request, searchCriteria, "accessResult", "Result"); searchUtil.extractInt(request, searchCriteria, "assetId", "Asset ID"); searchUtil.extractLong(request, searchCriteria, "policyId", "Policy ID"); searchUtil.extractInt(request, searchCriteria, "repoType", "Service Type"); searchUtil.extractDate(request, searchCriteria, "startDate", "Start Date", "MM/dd/yyyy"); searchUtil.extractDate(request, searchCriteria, "endDate", "End Date", "MM/dd/yyyy"); searchUtil.extractString(request, searchCriteria, "tags", "tags", null); searchUtil.extractString(request, searchCriteria, "cluster", "Cluster Name", StringUtil.VALIDATION_TEXT); searchUtil.extractStringList(request, searchCriteria, "zoneName", "Zone Name List", "zoneName", null, null); searchUtil.extractString(request, searchCriteria, "agentHost", "Agent Host Name", StringUtil.VALIDATION_TEXT); boolean isKeyAdmin = msBizUtil.isKeyAdmin(); boolean isAuditKeyAdmin = msBizUtil.isAuditKeyAdmin(); XXServiceDef xxServiceDef = daoManager.getXXServiceDef().findByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_KMS_NAME); if(isKeyAdmin && xxServiceDef != null || isAuditKeyAdmin && xxServiceDef != null){ searchCriteria.getParamList().put("repoType", xxServiceDef.getId()); } else if (xxServiceDef != null) { searchCriteria.getParamList().put("-repoType", xxServiceDef.getId()); } return assetMgr.getAccessLogs(searchCriteria); }  @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 testGetAccessLogs() { SearchCriteria searchCriteria = new SearchCriteria(); List<SortField> sortFields = null; List<VXAccessAudit> vXAccessAudits = new ArrayList<VXAccessAudit>(); VXAccessAuditList vXAccessAuditList = new VXAccessAuditList(); vXAccessAuditList.setVXAccessAudits(vXAccessAudits); Mockito.when(searchUtil.extractCommonCriterias(request, sortFields)).thenReturn(searchCriteria); Mockito.when(searchUtil.extractString((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn("test"); Mockito.when(searchUtil.extractInt((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString())) .thenReturn((Integer) 8); Mockito.when(searchUtil.extractDate((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(new Date()); Mockito.when(searchUtil.extractLong((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString())).thenReturn((Long) 8l); Mockito.when(msBizUtil.isKeyAdmin()).thenReturn(false); Mockito.when(daoManager.getXXServiceDef()).thenReturn(xxServiceDefDao); XXServiceDef xServiceDef = new XXServiceDef(); xServiceDef.setId(Id); Mockito.when(xxServiceDefDao.findByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_KMS_NAME)) .thenReturn(xServiceDef); Mockito.when(assetMgr.getAccessLogs(searchCriteria)).thenReturn(vXAccessAuditList); VXAccessAuditList expectedVXAccessAuditList = assetREST.getAccessLogs(request); Assert.assertEquals(vXAccessAuditList, expectedVXAccessAuditList); Mockito.verify(msBizUtil).isKeyAdmin(); Mockito.verify(assetMgr).getAccessLogs(searchCriteria); Mockito.verify(daoManager).getXXServiceDef(); Mockito.verify(searchUtil, Mockito.times(13)).extractString((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.nullable(String.class)); Mockito.verify(searchUtil, Mockito.times(4)).extractInt((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString()); Mockito.verify(searchUtil, Mockito.times(2)).extractDate((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); Mockito.verify(searchUtil).extractLong((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString()); Mockito.verify(searchUtil).extractStringList(Mockito.any(HttpServletRequest.class), (SearchCriteria) Mockito.any(), Mockito.eq("requestUser"), Mockito.eq("Users"), Mockito.eq("requestUser"), Mockito.any(), Mockito.eq(StringUtil.VALIDATION_TEXT)); Mockito.verify(searchUtil).extractStringList(Mockito.any(HttpServletRequest.class), (SearchCriteria) Mockito.any(), Mockito.eq("excludeUser"), Mockito.eq("Exclude Users"), Mockito.eq("-requestUser"), Mockito.any(), Mockito.eq(StringUtil.VALIDATION_TEXT)); Mockito.verify(searchUtil).extractStringList(Mockito.any(HttpServletRequest.class), (SearchCriteria) Mockito.any(), Mockito.eq("zoneName"), Mockito.eq("Zone Name List"), Mockito.eq("zoneName"), Mockito.eq(null), Mockito.eq(null)); Mockito.verify(searchUtil).extractCommonCriterias(Mockito.any(HttpServletRequest.class), (List<SortField>) Mockito.any()); Mockito.verifyNoMoreInteractions(searchUtil, assetMgr, daoManager); }
@Test public void testGetAccessLogsForKms() { SearchCriteria searchCriteria = new SearchCriteria(); List<SortField> sortFields = null; List<VXAccessAudit> vXAccessAudits = new ArrayList<VXAccessAudit>(); VXAccessAuditList vXAccessAuditList = new VXAccessAuditList(); vXAccessAuditList.setVXAccessAudits(vXAccessAudits); Mockito.when(searchUtil.extractCommonCriterias(request, sortFields)).thenReturn(searchCriteria); Mockito.when(searchUtil.extractString((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn("test"); Mockito.when(searchUtil.extractInt((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString())) .thenReturn((Integer) 8); Mockito.when(searchUtil.extractDate((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(new Date()); Mockito.when(searchUtil.extractLong((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString())).thenReturn((Long) 8l); Mockito.when(searchUtil.extractLong((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString())).thenReturn((Long) 8l); Mockito.when(msBizUtil.isKeyAdmin()).thenReturn(true); Mockito.when(daoManager.getXXServiceDef()).thenReturn(xxServiceDefDao); XXServiceDef xServiceDef = new XXServiceDef(); xServiceDef.setId(Id); Mockito.when(xxServiceDefDao.findByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_KMS_NAME)) .thenReturn(xServiceDef); Mockito.when(assetMgr.getAccessLogs(searchCriteria)).thenReturn(vXAccessAuditList); VXAccessAuditList expectedVXAccessAuditList = assetREST.getAccessLogs(request); Assert.assertEquals(vXAccessAuditList, expectedVXAccessAuditList); Mockito.verify(msBizUtil).isKeyAdmin(); Mockito.verify(assetMgr).getAccessLogs(searchCriteria); Mockito.verify(daoManager).getXXServiceDef(); Mockito.verify(searchUtil, Mockito.times(13)).extractString((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.nullable(String.class)); Mockito.verify(searchUtil, Mockito.times(4)).extractInt((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString()); Mockito.verify(searchUtil, Mockito.times(2)).extractDate((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); Mockito.verify(searchUtil).extractLong((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString()); Mockito.verify(searchUtil).extractStringList(Mockito.any(HttpServletRequest.class), (SearchCriteria) Mockito.any(), Mockito.eq("requestUser"), Mockito.eq("Users"), Mockito.eq("requestUser"), Mockito.any(), Mockito.eq(StringUtil.VALIDATION_TEXT)); Mockito.verify(searchUtil).extractStringList(Mockito.any(HttpServletRequest.class), (SearchCriteria) Mockito.any(), Mockito.eq("excludeUser"), Mockito.eq("Exclude Users"), Mockito.eq("-requestUser"), Mockito.any(), Mockito.eq(StringUtil.VALIDATION_TEXT)); Mockito.verify(searchUtil).extractStringList(Mockito.any(HttpServletRequest.class), (SearchCriteria) Mockito.any(), Mockito.eq("zoneName"), Mockito.eq("Zone Name List"), Mockito.eq("zoneName"), Mockito.eq(null), Mockito.eq(null)); Mockito.verify(searchUtil).extractCommonCriterias(Mockito.any(HttpServletRequest.class), (List<SortField>) Mockito.any()); Mockito.verifyNoMoreInteractions(searchUtil, assetMgr, daoManager); }