Search in sources :

Example 26 with RangerSecurityZone

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;
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser) RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) ArrayList(java.util.ArrayList) HadoopException(org.apache.ranger.plugin.client.HadoopException)

Example 27 with RangerSecurityZone

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);
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXTrxLog(org.apache.ranger.entity.XXTrxLog)

Example 28 with RangerSecurityZone

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;
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXTrxLog(org.apache.ranger.entity.XXTrxLog) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone)

Example 29 with RangerSecurityZone

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());
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXSecurityZoneDao(org.apache.ranger.db.XXSecurityZoneDao) ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone) Test(org.junit.Test)

Example 30 with RangerSecurityZone

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

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