use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class RangerSecurityZoneServiceService method mapEntityToViewBean.
@Override
protected RangerSecurityZone mapEntityToViewBean(RangerSecurityZone securityZone, XXSecurityZone xxSecurityZone) {
RangerSecurityZone ret = super.mapEntityToViewBean(securityZone, xxSecurityZone);
if (StringUtils.isNotEmpty(xxSecurityZone.getJsonData())) {
RangerSecurityZone zoneFromJsonData = gsonBuilder.fromJson(xxSecurityZone.getJsonData(), RangerSecurityZone.class);
if (zoneFromJsonData == null) {
logger.info("Cannot read jsonData into RangerSecurityZone object in [" + xxSecurityZone.getJsonData() + "]!!");
} else {
ret.setName(zoneFromJsonData.getName());
ret.setServices(zoneFromJsonData.getServices());
ret.setAdminUsers(zoneFromJsonData.getAdminUsers());
ret.setAdminUserGroups(zoneFromJsonData.getAdminUserGroups());
ret.setAuditUsers(zoneFromJsonData.getAuditUsers());
ret.setAuditUserGroups(zoneFromJsonData.getAuditUserGroups());
ret.setTagServices(zoneFromJsonData.getTagServices());
}
} else {
logger.info("Empty string representing jsonData in [" + xxSecurityZone + "]!!");
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerSecurityZone 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.plugin.model.RangerSecurityZone in project ranger by apache.
the class TestSecurityZoneREST method testDeleteSecurityZoneByName.
@Test
public void testDeleteSecurityZoneByName() throws Exception {
RangerSecurityZone securityZone = createRangerSecurityZone();
Long securityZoneId = 2L;
securityZone.setId(securityZoneId);
String securityZoneName = securityZone.getName();
when(rangerBizUtil.isAdmin()).thenReturn(true);
when(validatorFactory.getSecurityZoneValidator(svcStore, securityZoneStore)).thenReturn(validator);
doNothing().when(validator).validate(securityZoneName, RangerValidator.Action.DELETE);
securityZoneREST.deleteSecurityZone(securityZoneName);
verify(securityZoneStore, times(1)).deleteSecurityZoneByName(securityZoneName);
}
use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class TestSecurityZoneREST method testUpdateSecurityZoneWithMisMatchId.
@Test
public void testUpdateSecurityZoneWithMisMatchId() throws Exception {
RangerSecurityZone rangerSecurityZoneToUpdate = createRangerSecurityZone();
Long securityZoneId = 2L;
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
XXService xService = Mockito.mock(XXService.class);
rangerSecurityZoneToUpdate.setId(securityZoneId);
when(rangerBizUtil.isAdmin()).thenReturn(true);
when(daoManager.getXXService()).thenReturn(xServiceDao);
when(xServiceDao.findByName("test_service_1")).thenReturn(xService);
when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
when(xServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
when(validatorFactory.getSecurityZoneValidator(svcStore, securityZoneStore)).thenReturn(validator);
doNothing().when(validator).validate(rangerSecurityZoneToUpdate, RangerValidator.Action.UPDATE);
when(securityZoneStore.updateSecurityZoneById(rangerSecurityZoneToUpdate)).thenReturn(rangerSecurityZoneToUpdate);
when(restErrorUtil.createRESTException(Mockito.anyString())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
RangerSecurityZone updatedRangerSecurityZone = securityZoneREST.updateSecurityZone(9L, rangerSecurityZoneToUpdate);
assertEquals(rangerSecurityZoneToUpdate.getId(), updatedRangerSecurityZone.getId());
verify(validator, times(1)).validate(rangerSecurityZoneToUpdate, RangerValidator.Action.UPDATE);
}
use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class TestSecurityZoneREST method testCreateSecurityZone.
@Test
public void testCreateSecurityZone() throws Exception {
RangerSecurityZone rangerSecurityZone = createRangerSecurityZone();
XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
XXService xService = Mockito.mock(XXService.class);
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
when(rangerBizUtil.isAdmin()).thenReturn(true);
when(daoManager.getXXService()).thenReturn(xServiceDao);
when(xServiceDao.findByName("test_service_1")).thenReturn(xService);
when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
when(xServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
when(validatorFactory.getSecurityZoneValidator(svcStore, securityZoneStore)).thenReturn(validator);
doNothing().when(validator).validate(rangerSecurityZone, RangerValidator.Action.CREATE);
when(securityZoneStore.createSecurityZone(rangerSecurityZone)).thenReturn(rangerSecurityZone);
RangerSecurityZone createdRangerSecurityZone = securityZoneREST.createSecurityZone(rangerSecurityZone);
assertEquals(createdRangerSecurityZone.getName(), rangerSecurityZone.getName());
verify(validator, times(1)).validate(rangerSecurityZone, RangerValidator.Action.CREATE);
}
Aggregations