use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class ServiceMgr method isZoneAuditor.
public boolean isZoneAuditor(String zoneName) {
boolean isZoneAuditor = false;
RangerSecurityZone securityZone = null;
try {
securityZone = zoneStore.getSecurityZoneByName(zoneName);
} catch (Exception e) {
LOG.error("Unexpected error when fetching security zone with name:[" + zoneName + "] from database", e);
}
if (securityZone != null) {
String userId = rangerBizUtil.getCurrentUserLoginId();
List<XXGroupUser> groupUsers = groupUserDao.findByUserId(rangerBizUtil.getXUserId());
List<String> loggedInUsersGroups = new ArrayList<>();
for (XXGroupUser groupUser : groupUsers) {
loggedInUsersGroups.add(groupUser.getName());
}
for (String loggedInUsersGroup : loggedInUsersGroups) {
if (securityZone != null && securityZone.getAuditUserGroups() != null && securityZone.getAuditUserGroups().contains(loggedInUsersGroup)) {
isZoneAuditor = true;
break;
}
}
if ((securityZone != null && securityZone.getAuditUsers() != null && securityZone.getAuditUsers().contains(userId))) {
isZoneAuditor = true;
}
}
return isZoneAuditor;
}
use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class SecurityZoneDBStore method deleteSecurityZoneById.
@Override
public void deleteSecurityZoneById(Long zoneId) throws Exception {
RangerSecurityZone securityZone = securityZoneService.read(zoneId);
daoMgr.getXXGlobalState().onGlobalStateChange(RANGER_GLOBAL_STATE_NAME);
securityZoneRefUpdater.cleanupRefTables(securityZone);
securityZoneService.delete(securityZone);
List<XXTrxLog> trxLogList = securityZoneService.getTransactionLog(securityZone, null, "delete");
bizUtil.createTrxLog(trxLogList);
}
use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class SecurityZoneDBStore method createSecurityZone.
@Override
public RangerSecurityZone createSecurityZone(RangerSecurityZone securityZone) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> SecurityZoneDBStore.createSecurityZone()");
}
XXSecurityZone xxSecurityZone = daoMgr.getXXSecurityZoneDao().findByZoneName(securityZone.getName());
if (xxSecurityZone != null) {
throw restErrorUtil.createRESTException("security-zone with name: " + securityZone.getName() + " already exists", MessageEnums.ERROR_DUPLICATE_OBJECT);
}
daoMgr.getXXGlobalState().onGlobalStateChange(RANGER_GLOBAL_STATE_NAME);
RangerSecurityZone createdSecurityZone = securityZoneService.create(securityZone);
if (createdSecurityZone == null) {
throw new Exception("Cannot create security zone:[" + securityZone + "]");
}
securityZoneRefUpdater.createNewZoneMappingForRefTable(createdSecurityZone);
List<XXTrxLog> trxLogList = securityZoneService.getTransactionLog(createdSecurityZone, null, "create");
bizUtil.createTrxLog(trxLogList);
return createdSecurityZone;
}
use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class TestSecurityZoneDBStore method test7getSecurityZonesForService.
@Test
public void test7getSecurityZonesForService() throws Exception {
String serviceName = "hdfs_service";
Map<String, RangerSecurityZone.RangerSecurityZoneService> retMap = null;
SearchFilter filter = new SearchFilter();
filter.setParam(SearchFilter.ZONE_NAME, "sz1");
filter.setParam(SearchFilter.SERVICE_NAME, serviceName);
List<RangerSecurityZone> ret = new ArrayList<>();
List<XXSecurityZone> xxSecurityZones = new ArrayList<XXSecurityZone>();
XXSecurityZone xxSecurityZone = new XXSecurityZone();
xxSecurityZone.setId(2L);
xxSecurityZone.setName("sz1");
xxSecurityZones.add(xxSecurityZone);
RangerSecurityZone rangerSecurityZone = new RangerSecurityZone();
rangerSecurityZone.setId(3L);
ret.add(rangerSecurityZone);
// List<RangerSecurityZone> copy = new ArrayList<>(ret);
XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class);
Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao);
Mockito.when(xXSecurityZoneDao.getAll()).thenReturn(xxSecurityZones);
Mockito.when(securityZoneService.read(xxSecurityZone.getId())).thenReturn(rangerSecurityZone);
// Mockito.doNothing().when(predicateUtil).applyFilter(copy, filter);
retMap = new HashMap<>();
retMap.put(rangerSecurityZone.getName(), rangerSecurityZone.getServices().get(serviceName));
securityZoneDBStore.getSecurityZonesForService(serviceName);
Assert.assertNotNull(xxSecurityZone);
Assert.assertNotNull(xxSecurityZones);
Mockito.verify(daoManager).getXXSecurityZoneDao();
Mockito.verify(securityZoneService).read(xxSecurityZone.getId());
}
use of org.apache.ranger.plugin.model.RangerSecurityZone 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);
}
Aggregations