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());
}
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());
}
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;
}
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;
}
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;
}
Aggregations