Search in sources :

Example 1 with XXSecurityZone

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

the class TestXUserMgr method test125DeleteXUser.

@Test
public void test125DeleteXUser() {
    destroySession();
    setup();
    boolean force = true;
    VXUser vXUser = vxUser();
    XXUser xXUser = new XXUser();
    XXUserDao xXUserDao = Mockito.mock(XXUserDao.class);
    Mockito.when(daoManager.getXXUser()).thenReturn(xXUserDao);
    Mockito.when(xXUserDao.getById(vXUser.getId())).thenReturn(xXUser);
    Mockito.when(xUserService.populateViewBean(xXUser)).thenReturn(vXUser);
    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);
    VXPortalUser vXPortalUser = userProfile();
    XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
    XXPortalUserDao xXPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xXPortalUserDao);
    Mockito.when(xXPortalUserDao.findByLoginId(vXUser.getName().trim())).thenReturn(xXPortalUser);
    Mockito.when(xPortalUserService.populateViewBean(xXPortalUser)).thenReturn(vXPortalUser);
    XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
    XXPortalUserRole.setId(userId);
    XXPortalUserRole.setUserId(userId);
    XXPortalUserRole.setUserRole("ROLE_USER");
    List<XXAuthSession> xXAuthSessions = new ArrayList<XXAuthSession>();
    XXAuthSession xXAuthSession = new XXAuthSession();
    xXAuthSession.setId(userId);
    xXAuthSession.setLoginId(vXPortalUser.getLoginId());
    xXAuthSessions.add(xXAuthSession);
    List<XXUserPermission> xXUserPermissions = new ArrayList<XXUserPermission>();
    xXUserPermissions.add(xxUserPermission());
    List<XXPortalUserRole> xXPortalUserRoles = new ArrayList<XXPortalUserRole>();
    xXPortalUserRoles.add(XXPortalUserRole);
    List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
    XXPolicy xXPolicy = getXXPolicy();
    xXPolicyList.add(xXPolicy);
    XXSecurityZoneRefUser xZoneAdminUser = new XXSecurityZoneRefUser();
    xZoneAdminUser.setZoneId(2L);
    xZoneAdminUser.setUserId(userId);
    xZoneAdminUser.setUserName(vXUser.getName());
    xZoneAdminUser.setUserType(1);
    List<XXSecurityZoneRefUser> zoneSecRefUser = new ArrayList<XXSecurityZoneRefUser>();
    zoneSecRefUser.add(xZoneAdminUser);
    XXSecurityZoneRefUserDao zoneSecRefUserDao = Mockito.mock(XXSecurityZoneRefUserDao.class);
    Mockito.when(daoManager.getXXSecurityZoneRefUser()).thenReturn(zoneSecRefUserDao);
    Mockito.when(zoneSecRefUserDao.findByUserId(userId)).thenReturn(zoneSecRefUser);
    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(xZoneAdminUser.getZoneId())).thenReturn(xxSecurityZone);
    List<XXRoleRefUser> roleRefUser = new ArrayList<XXRoleRefUser>();
    XXRoleRefUser xRoleRefUser = new XXRoleRefUser();
    xRoleRefUser.setRoleId(userId);
    xRoleRefUser.setUserId(userId);
    xRoleRefUser.setUserName(vXUser.getName().trim());
    xRoleRefUser.setUserType(0);
    roleRefUser.add(xRoleRefUser);
    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 User '" + vXUser.getName().trim() + "' as its present in " + RangerConstants.ROLE_FIELD);
    Mockito.when(restErrorUtil.generateRESTException((VXResponse) Mockito.any())).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    xUserMgr.deleteXUser(vXUser.getId(), force);
    force = false;
    xUserMgr.deleteXUser(vXUser.getId(), force);
}
Also used : XXRoleRefUser(org.apache.ranger.entity.XXRoleRefUser) XXUser(org.apache.ranger.entity.XXUser) RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXSecurityZoneDao(org.apache.ranger.db.XXSecurityZoneDao) VXPermMap(org.apache.ranger.view.VXPermMap) WebApplicationException(javax.ws.rs.WebApplicationException) XXUserDao(org.apache.ranger.db.XXUserDao) ArrayList(java.util.ArrayList) XXSecurityZoneRefUser(org.apache.ranger.entity.XXSecurityZoneRefUser) XXPolicy(org.apache.ranger.entity.XXPolicy) VXAuditMap(org.apache.ranger.view.VXAuditMap) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) VXPermMapList(org.apache.ranger.view.VXPermMapList) VXResponse(org.apache.ranger.view.VXResponse) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) VXUser(org.apache.ranger.view.VXUser) XXAuthSession(org.apache.ranger.entity.XXAuthSession) XXUserPermission(org.apache.ranger.entity.XXUserPermission) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXSecurityZoneRefUserDao(org.apache.ranger.db.XXSecurityZoneRefUserDao) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) XXRole(org.apache.ranger.entity.XXRole) Test(org.junit.Test)

Example 2 with XXSecurityZone

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

the class SecurityZoneDBStore method deleteSecurityZoneByName.

@Override
public void deleteSecurityZoneByName(String zoneName) throws Exception {
    XXSecurityZone xxSecurityZone = daoMgr.getXXSecurityZoneDao().findByZoneName(zoneName);
    if (xxSecurityZone == null) {
        throw restErrorUtil.createRESTException("security-zone with name: " + zoneName + " does not exist");
    }
    RangerSecurityZone securityZone = securityZoneService.read(xxSecurityZone.getId());
    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) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone)

Example 3 with XXSecurityZone

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

the class SecurityZoneDBStore method getSecurityZones.

@Override
public List<RangerSecurityZone> getSecurityZones(SearchFilter filter) throws Exception {
    List<RangerSecurityZone> ret = new ArrayList<>();
    List<XXSecurityZone> xxSecurityZones = daoMgr.getXXSecurityZoneDao().getAll();
    for (XXSecurityZone xxSecurityZone : xxSecurityZones) {
        if (!xxSecurityZone.getId().equals(RangerSecurityZone.RANGER_UNZONED_SECURITY_ZONE_ID)) {
            ret.add(securityZoneService.read(xxSecurityZone.getId()));
        }
    }
    if (CollectionUtils.isNotEmpty(ret) && filter != null && !filter.isEmpty()) {
        List<RangerSecurityZone> copy = new ArrayList<>(ret);
        predicateUtil.applyFilter(copy, filter);
        ret = copy;
    }
    return ret;
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) ArrayList(java.util.ArrayList) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone)

Example 4 with XXSecurityZone

use of org.apache.ranger.entity.XXSecurityZone 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 5 with XXSecurityZone

use of org.apache.ranger.entity.XXSecurityZone 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)

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