Search in sources :

Example 31 with RangerSecurityZone

use of org.apache.ranger.plugin.model.RangerSecurityZone 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 32 with RangerSecurityZone

use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.

the class TestSecurityZoneDBStore method test9updateSecurityZoneByUnknownId.

@Test
public void test9updateSecurityZoneByUnknownId() throws Exception {
    RangerSecurityZone securityZoneToUpdate = new RangerSecurityZone();
    securityZoneToUpdate.setId(2L);
    XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class);
    Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao);
    Mockito.when(xXSecurityZoneDao.findByZoneId(securityZoneToUpdate.getId())).thenReturn(null);
    Mockito.when(restErrorUtil.createRESTException(Mockito.anyString())).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    securityZoneDBStore.updateSecurityZoneById(securityZoneToUpdate);
    Mockito.verify(daoManager, times(1)).getXXSecurityZoneDao();
    Mockito.verify(xXSecurityZoneDao, times(1)).findByZoneId(securityZoneToUpdate.getId());
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXSecurityZoneDao(org.apache.ranger.db.XXSecurityZoneDao) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 33 with RangerSecurityZone

use of org.apache.ranger.plugin.model.RangerSecurityZone 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 34 with RangerSecurityZone

use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.

the class RangerSecurityZoneServiceService method postCreate.

@Override
public RangerSecurityZone postCreate(XXSecurityZone xObj) {
    // Ensure to update ServiceVersionInfo for each service in the zone
    RangerSecurityZone ret = super.postCreate(xObj);
    Set<String> serviceNames = ret.getServices().keySet();
    // Create default zone policies
    try {
        serviceDBStore.createZoneDefaultPolicies(serviceNames, ret);
        updateServiceInfos(serviceNames);
    } catch (Exception exception) {
        logger.error("postCreate processing failed for security-zone:[" + ret + "]", exception);
        ret = null;
    }
    return ret;
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone)

Example 35 with RangerSecurityZone

use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.

the class RangerSecurityZoneServiceService method postUpdate.

@Override
public RangerSecurityZone postUpdate(XXSecurityZone xObj) {
    // Update ServiceVersionInfo for all affected services
    RangerSecurityZone ret = super.postUpdate(xObj);
    Set<String> oldServiceNames = new HashSet(serviceNamesInZones.remove(xObj.getId()));
    Set<String> updatedServiceNames = ret.getServices().keySet();
    Set<String> oldTagServiceNames = new HashSet(tagServiceNamesInZones.remove(xObj.getId()));
    Set<String> updatedTagServiceNames = new HashSet<String>(ret.getTagServices());
    Collection<String> newServiceNames = CollectionUtils.subtract(updatedServiceNames, oldServiceNames);
    Collection<String> deletedServiceNames = CollectionUtils.subtract(oldServiceNames, updatedServiceNames);
    Collection<String> deletedTagServiceNames = CollectionUtils.subtract(oldTagServiceNames, updatedTagServiceNames);
    try {
        serviceDBStore.createZoneDefaultPolicies(newServiceNames, ret);
        serviceDBStore.deleteZonePolicies(deletedServiceNames, ret.getId());
        serviceDBStore.deleteZonePolicies(deletedTagServiceNames, ret.getId());
        oldServiceNames.addAll(updatedServiceNames);
        updateServiceInfos(oldServiceNames);
    } catch (Exception exception) {
        logger.error("postUpdate processing failed for security-zone:[" + ret + "]", exception);
        ret = null;
    }
    return ret;
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) HashSet(java.util.HashSet)

Aggregations

RangerSecurityZone (org.apache.ranger.plugin.model.RangerSecurityZone)68 Test (org.junit.Test)40 ArrayList (java.util.ArrayList)27 XXSecurityZone (org.apache.ranger.entity.XXSecurityZone)16 WebApplicationException (javax.ws.rs.WebApplicationException)14 XXSecurityZoneDao (org.apache.ranger.db.XXSecurityZoneDao)12 RangerService (org.apache.ranger.plugin.model.RangerService)11 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)10 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)10 XXTrxLog (org.apache.ranger.entity.XXTrxLog)9 RangerSecurityZoneService (org.apache.ranger.plugin.model.RangerSecurityZone.RangerSecurityZoneService)7 HashMap (java.util.HashMap)6 ValidationErrorCode (org.apache.ranger.plugin.errors.ValidationErrorCode)5 HashSet (java.util.HashSet)4 List (java.util.List)4 XXGlobalStateDao (org.apache.ranger.db.XXGlobalStateDao)4 Map (java.util.Map)3 Path (javax.ws.rs.Path)3 XXServiceDao (org.apache.ranger.db.XXServiceDao)3 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)3