Search in sources :

Example 6 with XXSecurityZone

use of org.apache.ranger.entity.XXSecurityZone in project ranger by apache.

the class TestSecurityZoneDBStore method test1createSecurityZone.

@Test
public void test1createSecurityZone() throws Exception {
    XXSecurityZone xxSecurityZone = null;
    RangerSecurityZone securityZone = new RangerSecurityZone();
    RangerSecurityZone createdSecurityZone = new RangerSecurityZone();
    createdSecurityZone.setId(2L);
    XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class);
    XXGlobalStateDao xXGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
    Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao);
    Mockito.when(xXSecurityZoneDao.findByZoneName(securityZone.getName())).thenReturn(xxSecurityZone);
    Mockito.when(daoManager.getXXGlobalState()).thenReturn(xXGlobalStateDao);
    Mockito.doNothing().when(xXGlobalStateDao).onGlobalStateChange(RANGER_GLOBAL_STATE_NAME);
    Mockito.when(securityZoneService.create(securityZone)).thenReturn(createdSecurityZone);
    Mockito.doNothing().when(securityZoneRefUpdater).createNewZoneMappingForRefTable(createdSecurityZone);
    List<XXTrxLog> trxLogList = new ArrayList<XXTrxLog>();
    Mockito.doNothing().when(bizUtil).createTrxLog(trxLogList);
    RangerSecurityZone expectedSecurityZone = securityZoneDBStore.createSecurityZone(securityZone);
    Assert.assertNull(xxSecurityZone);
    Assert.assertEquals(createdSecurityZone.getId(), expectedSecurityZone.getId());
    Mockito.verify(daoManager).getXXSecurityZoneDao();
    Mockito.verify(daoManager).getXXGlobalState();
    Mockito.verify(securityZoneService).create(securityZone);
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXSecurityZoneDao(org.apache.ranger.db.XXSecurityZoneDao) XXGlobalStateDao(org.apache.ranger.db.XXGlobalStateDao) ArrayList(java.util.ArrayList) XXTrxLog(org.apache.ranger.entity.XXTrxLog) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone) Test(org.junit.Test)

Example 7 with XXSecurityZone

use of org.apache.ranger.entity.XXSecurityZone in project ranger by apache.

the class TestSecurityZoneDBStore method test4deleteSecurityZoneById.

@Test
public void test4deleteSecurityZoneById() throws Exception {
    XXSecurityZone xxSecurityZone = new XXSecurityZone();
    xxSecurityZone.setId(2L);
    RangerSecurityZone securityZone = new RangerSecurityZone();
    securityZone.setId(2L);
    securityZone.setName("sz1");
    XXGlobalStateDao xXGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
    Mockito.when(securityZoneService.read(securityZone.getId())).thenReturn(securityZone);
    Mockito.when(daoManager.getXXGlobalState()).thenReturn(xXGlobalStateDao);
    Mockito.doNothing().when(xXGlobalStateDao).onGlobalStateChange(RANGER_GLOBAL_STATE_NAME);
    Mockito.when(securityZoneRefUpdater.cleanupRefTables(securityZone)).thenReturn(true);
    Mockito.when(securityZoneService.delete(securityZone)).thenReturn(true);
    List<XXTrxLog> trxLogList = new ArrayList<XXTrxLog>();
    Mockito.doNothing().when(bizUtil).createTrxLog(trxLogList);
    securityZoneDBStore.deleteSecurityZoneById(securityZone.getId());
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXGlobalStateDao(org.apache.ranger.db.XXGlobalStateDao) ArrayList(java.util.ArrayList) XXTrxLog(org.apache.ranger.entity.XXTrxLog) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone) Test(org.junit.Test)

Example 8 with XXSecurityZone

use of org.apache.ranger.entity.XXSecurityZone in project ranger by apache.

the class RangerSecurityZoneServiceService method preDelete.

@Override
public XXSecurityZone preDelete(Long id) {
    // Update ServiceVersionInfo for each service in the zone
    XXSecurityZone ret = super.preDelete(id);
    RangerSecurityZone viewObject = new RangerSecurityZone();
    viewObject = mapEntityToViewBean(viewObject, ret);
    Set<String> allServiceNames = new HashSet<>(viewObject.getTagServices());
    allServiceNames.addAll(viewObject.getServices().keySet());
    try {
        serviceDBStore.deleteZonePolicies(allServiceNames, id);
        updateServiceInfos(allServiceNames);
    } catch (Exception exception) {
        logger.error("preDelete processing failed for security-zone:[" + viewObject + "]", exception);
        ret = null;
    }
    return ret;
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone) HashSet(java.util.HashSet)

Example 9 with XXSecurityZone

use of org.apache.ranger.entity.XXSecurityZone in project ranger by apache.

the class RangerSecurityZoneServiceService method mapViewToEntityBean.

@Override
protected XXSecurityZone mapViewToEntityBean(RangerSecurityZone securityZone, XXSecurityZone xxSecurityZone, int OPERATION_CONTEXT) {
    XXSecurityZone ret = super.mapViewToEntityBean(securityZone, xxSecurityZone, OPERATION_CONTEXT);
    ret.setJsonData(gsonBuilder.toJson(securityZone));
    return ret;
}
Also used : XXSecurityZone(org.apache.ranger.entity.XXSecurityZone)

Example 10 with XXSecurityZone

use of org.apache.ranger.entity.XXSecurityZone 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);
}
Also used : XXSecurityZoneRefGroup(org.apache.ranger.entity.XXSecurityZoneRefGroup) RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXSecurityZoneDao(org.apache.ranger.db.XXSecurityZoneDao) VXPermMap(org.apache.ranger.view.VXPermMap) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) XXSecurityZoneRefGroupDao(org.apache.ranger.db.XXSecurityZoneRefGroupDao) XXPolicy(org.apache.ranger.entity.XXPolicy) XXRoleRefGroup(org.apache.ranger.entity.XXRoleRefGroup) VXAuditMap(org.apache.ranger.view.VXAuditMap) VXPermMapList(org.apache.ranger.view.VXPermMapList) VXResponse(org.apache.ranger.view.VXResponse) XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) XXResource(org.apache.ranger.entity.XXResource) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone) VXGroup(org.apache.ranger.view.VXGroup) XXGroupGroup(org.apache.ranger.entity.XXGroupGroup) XXRole(org.apache.ranger.entity.XXRole) Test(org.junit.Test)

Aggregations

XXSecurityZone (org.apache.ranger.entity.XXSecurityZone)23 RangerSecurityZone (org.apache.ranger.plugin.model.RangerSecurityZone)16 Test (org.junit.Test)13 XXSecurityZoneDao (org.apache.ranger.db.XXSecurityZoneDao)12 ArrayList (java.util.ArrayList)11 XXTrxLog (org.apache.ranger.entity.XXTrxLog)7 WebApplicationException (javax.ws.rs.WebApplicationException)4 XXGlobalStateDao (org.apache.ranger.db.XXGlobalStateDao)4 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)4 XXPolicy (org.apache.ranger.entity.XXPolicy)3 XXSecurityZoneRefService (org.apache.ranger.entity.XXSecurityZoneRefService)3 XXSecurityZoneRefTagService (org.apache.ranger.entity.XXSecurityZoneRefTagService)3 XXService (org.apache.ranger.entity.XXService)3 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)3 VXString (org.apache.ranger.view.VXString)3 FormDataContentDisposition (com.sun.jersey.core.header.FormDataContentDisposition)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2