use of org.apache.ranger.view.VXAuditMap in project ranger by apache.
the class TestXUserREST method test58updateXAuditMapVXResourceNull.
@Test
public void test58updateXAuditMapVXResourceNull() {
VXAuditMap vXAuditMap = null;
VXAuditMap retvXAuditMap = xUserRest.updateXAuditMap(vXAuditMap);
assertNull(retvXAuditMap);
}
use of org.apache.ranger.view.VXAuditMap in project ranger by apache.
the class TestXUserMgr method test126DeleteXGroup.
@Test
public void test126DeleteXGroup() {
destroySession();
setup();
boolean force = true;
VXGroup vXGroup = vxGroup();
VXPermMapList vXPermMapList = new VXPermMapList();
VXPermMap vXPermMap1 = getVXPermMap();
List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
vXPermMaps.add(vXPermMap1);
vXPermMapList.setVXPermMaps(vXPermMaps);
VXAuditMapList vXAuditMapList = new VXAuditMapList();
List<VXAuditMap> vXAuditMaps = new ArrayList<VXAuditMap>();
VXAuditMap vXAuditMap = getVXAuditMap();
vXAuditMaps.add(vXAuditMap);
vXAuditMapList.setVXAuditMaps(vXAuditMaps);
List<XXGroupGroup> xXGroupGroups = new ArrayList<XXGroupGroup>();
XXGroupGroup xXGroupGroup = xxGroupGroup();
xXGroupGroups.add(xXGroupGroup);
List<XXGroupPermission> xXGroupPermissions = new ArrayList<XXGroupPermission>();
XXGroupPermission xGroupPermissionObj = xxGroupPermission();
xXGroupPermissions.add(xGroupPermissionObj);
List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
XXPolicy xXPolicy = getXXPolicy();
xXPolicyList.add(xXPolicy);
List<XXResource> xResourceList = new ArrayList<XXResource>();
XXResource xXResource = new XXResource();
xXResource.setId(userId);
xXResource.setName("hadoopdev");
xXResource.setIsRecursive(AppConstants.BOOL_TRUE);
xXResource.setResourceStatus(AppConstants.STATUS_ENABLED);
xResourceList.add(xXResource);
XXSecurityZoneRefGroup xZoneAdminGroup = new XXSecurityZoneRefGroup();
xZoneAdminGroup.setZoneId(2L);
xZoneAdminGroup.setGroupId(vXGroup.getId());
xZoneAdminGroup.setGroupName(vXGroup.getName());
xZoneAdminGroup.setGroupType(1);
List<XXSecurityZoneRefGroup> zoneSecRefGroup = new ArrayList<XXSecurityZoneRefGroup>();
zoneSecRefGroup.add(xZoneAdminGroup);
XXSecurityZoneRefGroupDao zoneSecRefGroupDao = Mockito.mock(XXSecurityZoneRefGroupDao.class);
Mockito.when(daoManager.getXXSecurityZoneRefGroup()).thenReturn(zoneSecRefGroupDao);
Mockito.when(zoneSecRefGroupDao.findByGroupId(userId)).thenReturn(zoneSecRefGroup);
RangerSecurityZone securityZone = new RangerSecurityZone();
securityZone.setId(2L);
securityZone.setName("sz1");
XXSecurityZone xxSecurityZone = new XXSecurityZone();
xxSecurityZone.setId(2L);
xxSecurityZone.setName("sz1");
XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class);
Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao);
Mockito.when(xXSecurityZoneDao.getById(xZoneAdminGroup.getZoneId())).thenReturn(xxSecurityZone);
List<XXRoleRefGroup> roleRefGroup = new ArrayList<XXRoleRefGroup>();
XXRoleRefGroup xRoleRefGroup = new XXRoleRefGroup();
xRoleRefGroup.setRoleId(userId);
xRoleRefGroup.setGroupId(userId);
xRoleRefGroup.setGroupName(groupName);
xRoleRefGroup.setGroupType(0);
roleRefGroup.add(xRoleRefGroup);
XXRole xRole = new XXRole();
xRole.setId(userId);
xRole.setName("Role1");
VXResponse vXResponse = new VXResponse();
vXResponse.setStatusCode(HttpServletResponse.SC_BAD_REQUEST);
vXResponse.setMsgDesc("Can Not Delete Group '" + vXGroup.getName().trim() + "' as its present in " + RangerConstants.ROLE_FIELD);
Mockito.when(restErrorUtil.generateRESTException((VXResponse) Mockito.any())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
xUserMgr.deleteXGroup(vXGroup.getId(), force);
}
use of org.apache.ranger.view.VXAuditMap in project ranger by apache.
the class TestXUserMgr method test20DeleteXGroup.
@Test
public void test20DeleteXGroup() {
setup();
boolean force = true;
VXGroup vXGroup = vxGroup();
XXGroupDao xXGroupDao = Mockito.mock(XXGroupDao.class);
XXUserDao xXUserDao = Mockito.mock(XXUserDao.class);
VXUser vxUser = vxUser();
XXUser xXUser = xxUser(vxUser);
Mockito.when(daoManager.getXXUser()).thenReturn(xXUserDao);
Mockito.when(xXUserDao.getById(xXUser.getId())).thenReturn(xXUser);
XXGroup xXGroup = new XXGroup();
Mockito.when(daoManager.getXXGroup()).thenReturn(xXGroupDao);
Mockito.when(xXGroupDao.getById(vXGroup.getId())).thenReturn(xXGroup);
Mockito.when(xGroupService.populateViewBean(xXGroup)).thenReturn(vXGroup);
VXGroupUserList vxGroupUserList = vxGroupUserList();
XXGroupUserDao xGroupUserDao = Mockito.mock(XXGroupUserDao.class);
Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
Mockito.when(daoManager.getXXGroupUser()).thenReturn(xGroupUserDao);
VXPermMapList vXPermMapList = new VXPermMapList();
VXPermMap vXPermMap1 = getVXPermMap();
List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
vXPermMaps.add(vXPermMap1);
vXPermMapList.setVXPermMaps(vXPermMaps);
XXPermMapDao xXPermMapDao = Mockito.mock(XXPermMapDao.class);
Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(vXPermMapList);
Mockito.when(daoManager.getXXPermMap()).thenReturn(xXPermMapDao);
VXAuditMapList vXAuditMapList = new VXAuditMapList();
List<VXAuditMap> vXAuditMaps = new ArrayList<VXAuditMap>();
VXAuditMap vXAuditMap = getVXAuditMap();
vXAuditMaps.add(vXAuditMap);
vXAuditMapList.setVXAuditMaps(vXAuditMaps);
XXAuditMapDao xXAuditMapDao = Mockito.mock(XXAuditMapDao.class);
Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(vXAuditMapList);
Mockito.when(daoManager.getXXAuditMap()).thenReturn(xXAuditMapDao);
XXGroupGroupDao xXGroupGroupDao = Mockito.mock(XXGroupGroupDao.class);
List<XXGroupGroup> xXGroupGroups = new ArrayList<XXGroupGroup>();
XXGroupGroup xXGroupGroup = xxGroupGroup();
xXGroupGroups.add(xXGroupGroup);
Mockito.when(daoManager.getXXGroupGroup()).thenReturn(xXGroupGroupDao);
Mockito.when(xXGroupGroupDao.findByGroupId(userId)).thenReturn(xXGroupGroups);
XXGroupPermissionDao xXGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xXGroupPermissionDao);
List<XXGroupPermission> xXGroupPermissions = new ArrayList<XXGroupPermission>();
XXGroupPermission xGroupPermissionObj = xxGroupPermission();
xXGroupPermissions.add(xGroupPermissionObj);
Mockito.when(xXGroupPermissionDao.findByGroupId(vXGroup.getId())).thenReturn(xXGroupPermissions);
XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class);
List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
XXPolicy xXPolicy = getXXPolicy();
xXPolicyList.add(xXPolicy);
Mockito.when(daoManager.getXXPolicy()).thenReturn(xXPolicyDao);
Mockito.when(xXPolicyDao.findByGroupId(userId)).thenReturn(xXPolicyList);
List<XXResource> xResourceList = new ArrayList<XXResource>();
XXResource xXResource = new XXResource();
xXResource.setId(userId);
xXResource.setName("hadoopdev");
xXResource.setIsRecursive(AppConstants.BOOL_TRUE);
xXResource.setResourceStatus(AppConstants.STATUS_ENABLED);
xResourceList.add(xXResource);
XXResourceDao xxResourceDao = Mockito.mock(XXResourceDao.class);
Mockito.when(daoManager.getXXResource()).thenReturn(xxResourceDao);
Mockito.when(xxResourceDao.getById(Mockito.anyLong())).thenReturn(xXResource);
RangerPolicy rangerPolicy = rangerPolicy();
Mockito.when(policyService.getPopulatedViewObject(xXPolicy)).thenReturn(rangerPolicy);
XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
XXModuleDef xModuleDef = xxModuleDef();
Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
List<XXSecurityZoneRefGroup> zoneSecRefGroup = new ArrayList<XXSecurityZoneRefGroup>();
XXSecurityZoneRefGroupDao zoneSecRefGroupDao = Mockito.mock(XXSecurityZoneRefGroupDao.class);
Mockito.when(daoManager.getXXSecurityZoneRefGroup()).thenReturn(zoneSecRefGroupDao);
Mockito.when(zoneSecRefGroupDao.findByGroupId(userId)).thenReturn(zoneSecRefGroup);
List<XXRoleRefGroup> roleRefGroup = new ArrayList<XXRoleRefGroup>();
XXRoleRefGroupDao roleRefGroupDao = Mockito.mock(XXRoleRefGroupDao.class);
Mockito.when(daoManager.getXXRoleRefGroup()).thenReturn(roleRefGroupDao);
Mockito.when(roleRefGroupDao.findByGroupId(userId)).thenReturn(roleRefGroup);
xUserMgr.deleteXGroup(vXGroup.getId(), force);
}
use of org.apache.ranger.view.VXAuditMap in project ranger by apache.
the class TestServiceUtil method testToVXResourceForTablesColumnFamiliesAndColumn.
@Test
public void testToVXResourceForTablesColumnFamiliesAndColumn() {
GUIDUtil guid = new GUIDUtil();
String guidString = guid.genGUID();
List<VXAuditMap> auditList = new ArrayList<VXAuditMap>();
VXAuditMap vxAuditMap = new VXAuditMap();
vxAuditMap.setResourceId(1L);
vxAuditMap.setAuditType(AppConstants.XA_AUDIT_TYPE_ALL);
auditList.add(vxAuditMap);
VXResource expectedVXResource = new VXResource();
expectedVXResource.setName("/myTable/myColumnFamilies/myColumn");
expectedVXResource.setTables("myTable");
expectedVXResource.setColumnFamilies("myColumnFamilies");
expectedVXResource.setColumns("myColumn");
expectedVXResource.setGuid(guidString);
expectedVXResource.setPolicyName("hbase Policy");
expectedVXResource.setDescription("hbase policy description");
expectedVXResource.setResourceType(1);
expectedVXResource.setAssetName("hbase");
expectedVXResource.setAssetType(2);
expectedVXResource.setResourceStatus(1);
expectedVXResource.setTableType(1);
expectedVXResource.setColumnType(1);
expectedVXResource.setAuditList(auditList);
Map<String, RangerPolicyResource> rangerPolicyResourceMap = new HashMap<String, RangerPolicyResource>();
List<String> valuesListForTable = new ArrayList<String>();
valuesListForTable.add("myTable");
List<String> valuesListForColumn = new ArrayList<String>();
valuesListForColumn.add("myColumn");
List<String> valuesListForColumnFamilies = new ArrayList<String>();
valuesListForColumnFamilies.add("myColumnFamilies");
RangerPolicy policy = new RangerPolicy();
policy.setId(1L);
policy.setName("hbase Policy");
policy.setService("hbase");
policy.setDescription("hbase policy description");
policy.setIsEnabled(true);
policy.setGuid(guidString);
policy.setIsAuditEnabled(true);
RangerService rangerService = new RangerService();
rangerService.setName("hbase");
rangerService.setType("hbase");
RangerPolicyResource rangerPolicyResourceForTable = new RangerPolicyResource();
rangerPolicyResourceForTable.setIsExcludes(true);
rangerPolicyResourceForTable.setIsRecursive(true);
rangerPolicyResourceForTable.setValue("table");
rangerPolicyResourceForTable.setValues(valuesListForTable);
rangerPolicyResourceMap.put("table", rangerPolicyResourceForTable);
RangerPolicyResource rangerPolicyResourceForColumn = new RangerPolicyResource();
rangerPolicyResourceForColumn.setIsExcludes(true);
rangerPolicyResourceForColumn.setIsRecursive(true);
rangerPolicyResourceForColumn.setValue("table");
rangerPolicyResourceForColumn.setValues(valuesListForColumn);
rangerPolicyResourceMap.put("column", rangerPolicyResourceForColumn);
RangerPolicyResource rangerPolicyResourceForColumnFamilies = new RangerPolicyResource();
rangerPolicyResourceForColumnFamilies.setIsExcludes(true);
rangerPolicyResourceForColumnFamilies.setIsRecursive(true);
rangerPolicyResourceForColumnFamilies.setValue("table");
rangerPolicyResourceForColumnFamilies.setValues(valuesListForColumnFamilies);
rangerPolicyResourceMap.put("column-family", rangerPolicyResourceForColumnFamilies);
policy.setResources(rangerPolicyResourceMap);
VXResource actualVXResource = serviceUtil.toVXResource(policy, rangerService);
Assert.assertNotNull(actualVXResource);
Assert.assertEquals(expectedVXResource.getName(), actualVXResource.getName());
Assert.assertEquals(expectedVXResource.getGuid(), actualVXResource.getGuid());
Assert.assertEquals(expectedVXResource.getPolicyName(), actualVXResource.getPolicyName());
Assert.assertEquals(expectedVXResource.getResourceType(), actualVXResource.getResourceType());
Assert.assertEquals(expectedVXResource.getDescription(), actualVXResource.getDescription());
Assert.assertEquals(expectedVXResource.getAssetName(), actualVXResource.getAssetName());
Assert.assertEquals(expectedVXResource.getAssetType(), actualVXResource.getAssetType());
Assert.assertEquals(expectedVXResource.getResourceStatus(), actualVXResource.getResourceStatus());
Assert.assertEquals(expectedVXResource.getTableType(), actualVXResource.getTableType());
Assert.assertEquals(expectedVXResource.getColumnType(), actualVXResource.getColumnType());
Assert.assertEquals(expectedVXResource.getTables(), actualVXResource.getTables());
Assert.assertEquals(expectedVXResource.getColumns(), actualVXResource.getColumns());
Assert.assertEquals(expectedVXResource.getColumnFamilies(), actualVXResource.getColumnFamilies());
Assert.assertEquals(expectedVXResource.getAuditList().get(0).getResourceId(), actualVXResource.getAuditList().get(0).getResourceId());
Assert.assertEquals(expectedVXResource.getAuditList().get(0).getAuditType(), actualVXResource.getAuditList().get(0).getAuditType());
}
use of org.apache.ranger.view.VXAuditMap in project ranger by apache.
the class TestServiceUtil method testToRangerPolicyForResourceTypeDatabase.
@Test
public void testToRangerPolicyForResourceTypeDatabase() {
RangerPolicy expectedRangerPolicy = new RangerPolicy();
expectedRangerPolicy.setId(1L);
expectedRangerPolicy.setName("hive Policy");
expectedRangerPolicy.setService("hive");
expectedRangerPolicy.setDescription("hive policy description");
Map<String, RangerPolicyResource> expectedMap = new HashMap<String, RangerPolicyResource>();
List<String> valuesList = new ArrayList<String>();
valuesList.add("databases");
VXAuditMap vXAuditMap = new VXAuditMap();
vXAuditMap.setId(1L);
vXAuditMap.setOwner("rangerAdmin");
List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>();
vXAuditMapList.add(vXAuditMap);
RangerPolicyResource rangerPolicyResource = new RangerPolicyResource();
rangerPolicyResource.setIsExcludes(false);
rangerPolicyResource.setIsRecursive(false);
rangerPolicyResource.setValue("databases");
rangerPolicyResource.setValues(valuesList);
expectedMap.put("database", rangerPolicyResource);
expectedRangerPolicy.setResources(expectedMap);
RangerService rangerService = new RangerService();
rangerService.setName("hive");
VXResource resource = new VXResource();
resource.setId(1L);
resource.setDatabases("databases");
resource.setUpdateDate(new Date());
resource.setCreateDate(new Date());
resource.setOwner("rangerAdmin");
resource.setUpdatedBy("rangerAdmin");
resource.setPolicyName("hive Policy");
resource.setDescription("hive policy description");
resource.setResourceStatus(RangerCommonEnums.STATUS_ENABLED);
resource.setIsRecursive(1);
resource.setTableType(1);
resource.setColumnType(1);
RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(resource, rangerService);
Assert.assertNotNull(actualRangerPolicy);
Assert.assertEquals(expectedRangerPolicy.getId(), actualRangerPolicy.getId());
Assert.assertEquals(expectedRangerPolicy.getName(), actualRangerPolicy.getName());
Assert.assertEquals(expectedRangerPolicy.getService(), actualRangerPolicy.getService());
Assert.assertEquals(expectedRangerPolicy.getDescription(), actualRangerPolicy.getDescription());
Assert.assertEquals(expectedRangerPolicy.getResources(), actualRangerPolicy.getResources());
}
Aggregations