Search in sources :

Example 26 with XXPolicy

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

the class PatchForKafkaServiceDefUpdate_J10025 method createDefaultPolicyForNewResources.

private void createDefaultPolicyForNewResources() {
    logger.info("==> createDefaultPolicyForNewResources ");
    XXPortalUser xxPortalUser = daoMgr.getXXPortalUser().findByLoginId(LOGIN_ID_ADMIN);
    Long currentUserId = xxPortalUser.getId();
    XXServiceDef xXServiceDefObj = daoMgr.getXXServiceDef().findByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_KAFKA_NAME);
    if (xXServiceDefObj == null) {
        logger.debug("ServiceDef not fount with name :" + EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_KAFKA_NAME);
        return;
    }
    Long xServiceDefId = xXServiceDefObj.getId();
    List<XXService> xxServices = daoMgr.getXXService().findByServiceDefId(xServiceDefId);
    for (XXService xxService : xxServices) {
        int resourceMapOrder = 0;
        for (String newResource : POLICY_NAMES) {
            XXPolicy xxPolicy = new XXPolicy();
            xxPolicy.setName(newResource);
            xxPolicy.setDescription(newResource);
            xxPolicy.setService(xxService.getId());
            xxPolicy.setPolicyPriority(RangerPolicy.POLICY_PRIORITY_NORMAL);
            xxPolicy.setIsAuditEnabled(Boolean.TRUE);
            xxPolicy.setIsEnabled(Boolean.TRUE);
            xxPolicy.setPolicyType(RangerPolicy.POLICY_TYPE_ACCESS);
            xxPolicy.setGuid(guidUtil.genGUID());
            xxPolicy.setAddedByUserId(currentUserId);
            xxPolicy.setUpdatedByUserId(currentUserId);
            RangerPolicy rangerPolicy = getRangerPolicy(newResource, xxPortalUser, xxService);
            xxPolicy.setPolicyText(JsonUtils.objectToJson(rangerPolicy));
            xxPolicy.setResourceSignature(rangerPolicy.getResourceSignature());
            xxPolicy.setZoneId(1L);
            XXPolicy createdPolicy = daoMgr.getXXPolicy().create(xxPolicy);
            XXPolicyItem xxPolicyItem = new XXPolicyItem();
            xxPolicyItem.setIsEnabled(Boolean.TRUE);
            xxPolicyItem.setDelegateAdmin(Boolean.TRUE);
            xxPolicyItem.setItemType(0);
            xxPolicyItem.setOrder(0);
            xxPolicyItem.setAddedByUserId(currentUserId);
            xxPolicyItem.setUpdatedByUserId(currentUserId);
            xxPolicyItem.setPolicyId(createdPolicy.getId());
            XXPolicyItem createdXXPolicyItem = daoMgr.getXXPolicyItem().create(xxPolicyItem);
            List<String> accessTypes = getAccessTypes();
            for (int i = 0; i < accessTypes.size(); i++) {
                XXAccessTypeDef xAccTypeDef = daoMgr.getXXAccessTypeDef().findByNameAndServiceId(accessTypes.get(i), xxPolicy.getService());
                if (xAccTypeDef == null) {
                    throw new RuntimeException(accessTypes.get(i) + ": is not a valid access-type. policy='" + xxPolicy.getName() + "' service='" + xxPolicy.getService() + "'");
                }
                XXPolicyItemAccess xPolItemAcc = new XXPolicyItemAccess();
                xPolItemAcc.setIsAllowed(Boolean.TRUE);
                xPolItemAcc.setType(xAccTypeDef.getId());
                xPolItemAcc.setOrder(i);
                xPolItemAcc.setAddedByUserId(currentUserId);
                xPolItemAcc.setUpdatedByUserId(currentUserId);
                xPolItemAcc.setPolicyitemid(createdXXPolicyItem.getId());
                daoMgr.getXXPolicyItemAccess().create(xPolItemAcc);
            }
            for (int i = 0; i < DEFAULT_POLICY_USERS.size(); i++) {
                String user = DEFAULT_POLICY_USERS.get(i);
                if (StringUtils.isBlank(user)) {
                    continue;
                }
                XXUser xxUser = daoMgr.getXXUser().findByUserName(user);
                if (xxUser == null) {
                    throw new RuntimeException(user + ": user does not exist. policy='" + xxPolicy.getName() + "' service='" + xxPolicy.getService() + "' user='" + user + "'");
                }
                XXPolicyItemUserPerm xUserPerm = new XXPolicyItemUserPerm();
                xUserPerm.setUserId(xxUser.getId());
                xUserPerm.setPolicyItemId(createdXXPolicyItem.getId());
                xUserPerm.setOrder(i);
                xUserPerm.setAddedByUserId(currentUserId);
                xUserPerm.setUpdatedByUserId(currentUserId);
                daoMgr.getXXPolicyItemUserPerm().create(xUserPerm);
            }
            String policyResourceName = KAFKA_RESOURCE_CLUSTER;
            if ("all - delegationtoken".equals(newResource)) {
                policyResourceName = KAFKA_RESOURCE_DELEGATIONTOKEN;
            }
            XXResourceDef xResDef = daoMgr.getXXResourceDef().findByNameAndPolicyId(policyResourceName, createdPolicy.getId());
            if (xResDef == null) {
                throw new RuntimeException(policyResourceName + ": is not a valid resource-type. policy='" + createdPolicy.getName() + "' service='" + createdPolicy.getService() + "'");
            }
            XXPolicyResource xPolRes = new XXPolicyResource();
            xPolRes.setAddedByUserId(currentUserId);
            xPolRes.setUpdatedByUserId(currentUserId);
            xPolRes.setIsExcludes(Boolean.FALSE);
            xPolRes.setIsRecursive(Boolean.FALSE);
            xPolRes.setPolicyId(createdPolicy.getId());
            xPolRes.setResDefId(xResDef.getId());
            xPolRes = daoMgr.getXXPolicyResource().create(xPolRes);
            XXPolicyResourceMap xPolResMap = new XXPolicyResourceMap();
            xPolResMap.setResourceId(xPolRes.getId());
            xPolResMap.setValue("*");
            xPolResMap.setOrder(resourceMapOrder);
            xPolResMap.setAddedByUserId(currentUserId);
            xPolResMap.setUpdatedByUserId(currentUserId);
            daoMgr.getXXPolicyResourceMap().create(xPolResMap);
            resourceMapOrder++;
            logger.info("Creating policy for service id : " + xxService.getId());
        }
    }
    logger.info("<== createDefaultPolicyForNewResources ");
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXUser(org.apache.ranger.entity.XXUser) XXPolicyItemUserPerm(org.apache.ranger.entity.XXPolicyItemUserPerm) XXPolicyResourceMap(org.apache.ranger.entity.XXPolicyResourceMap) XXPolicy(org.apache.ranger.entity.XXPolicy) XXResourceDef(org.apache.ranger.entity.XXResourceDef) XXPortalUser(org.apache.ranger.entity.XXPortalUser) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXPolicyItem(org.apache.ranger.entity.XXPolicyItem) XXPolicyItemAccess(org.apache.ranger.entity.XXPolicyItemAccess) XXPolicyResource(org.apache.ranger.entity.XXPolicyResource) XXAccessTypeDef(org.apache.ranger.entity.XXAccessTypeDef) XXService(org.apache.ranger.entity.XXService)

Example 27 with XXPolicy

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

the class PatchForAtlasResourceAndAccessTypeUpdate_J10016 method createDefaultPolicyToExistingService.

private void createDefaultPolicyToExistingService() {
    logger.info("==> createDefaultPolicyToExistingService ");
    XXPortalUser xxPortalUser = daoMgr.getXXPortalUser().findByLoginId(LOGIN_ID_ADMIN);
    Long currentUserId = xxPortalUser.getId();
    XXServiceDef xXServiceDefObj = daoMgr.getXXServiceDef().findByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME);
    if (xXServiceDefObj == null) {
        logger.debug("ServiceDef not fount with name :" + EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME);
        return;
    }
    Long xServiceDefId = xXServiceDefObj.getId();
    List<XXService> xxServices = daoMgr.getXXService().findByServiceDefId(xServiceDefId);
    for (XXService xxService : xxServices) {
        List<XXPolicy> xxPolicies = daoMgr.getXXPolicy().findByServiceId(xxService.getId());
        Boolean isPolicyPresent = true;
        for (XXPolicy xxPolicy : xxPolicies) {
            if (!xxPolicy.getName().equalsIgnoreCase(RESOURCE_DEF_NAME)) {
                isPolicyPresent = false;
            } else {
                isPolicyPresent = true;
                break;
            }
        }
        if (!isPolicyPresent) {
            XXPolicy xxPolicy = new XXPolicy();
            xxPolicy.setName(RESOURCE_DEF_NAME);
            xxPolicy.setDescription(RESOURCE_DEF_NAME);
            xxPolicy.setService(xxService.getId());
            xxPolicy.setPolicyPriority(RangerPolicy.POLICY_PRIORITY_NORMAL);
            xxPolicy.setIsAuditEnabled(Boolean.TRUE);
            xxPolicy.setIsEnabled(Boolean.TRUE);
            xxPolicy.setPolicyType(RangerPolicy.POLICY_TYPE_ACCESS);
            xxPolicy.setGuid(guidUtil.genGUID());
            xxPolicy.setAddedByUserId(currentUserId);
            xxPolicy.setUpdatedByUserId(currentUserId);
            RangerPolicy rangerPolicy = new RangerPolicy();
            RangerPolicyResourceSignature resourceSignature = new RangerPolicyResourceSignature(rangerPolicy);
            xxPolicy.setResourceSignature(resourceSignature.getSignature());
            xxPolicy.setZoneId(1L);
            XXPolicy createdPolicy = daoMgr.getXXPolicy().create(xxPolicy);
            XXPolicyItem xxPolicyItem = new XXPolicyItem();
            xxPolicyItem.setIsEnabled(Boolean.TRUE);
            xxPolicyItem.setDelegateAdmin(Boolean.TRUE);
            xxPolicyItem.setItemType(0);
            xxPolicyItem.setOrder(0);
            xxPolicyItem.setAddedByUserId(currentUserId);
            xxPolicyItem.setUpdatedByUserId(currentUserId);
            xxPolicyItem.setPolicyId(createdPolicy.getId());
            XXPolicyItem createdXXPolicyItem = daoMgr.getXXPolicyItem().create(xxPolicyItem);
            List<String> accessTypes = Arrays.asList("add-relationship", "update-relationship", "remove-relationship");
            for (int i = 0; i < accessTypes.size(); i++) {
                XXAccessTypeDef xAccTypeDef = daoMgr.getXXAccessTypeDef().findByNameAndServiceId(accessTypes.get(i), xxPolicy.getService());
                if (xAccTypeDef == null) {
                    throw new RuntimeException(accessTypes.get(i) + ": is not a valid access-type. policy='" + xxPolicy.getName() + "' service='" + xxPolicy.getService() + "'");
                }
                XXPolicyItemAccess xPolItemAcc = new XXPolicyItemAccess();
                xPolItemAcc.setIsAllowed(Boolean.TRUE);
                xPolItemAcc.setType(xAccTypeDef.getId());
                xPolItemAcc.setOrder(i);
                xPolItemAcc.setAddedByUserId(currentUserId);
                xPolItemAcc.setUpdatedByUserId(currentUserId);
                xPolItemAcc.setPolicyitemid(createdXXPolicyItem.getId());
                daoMgr.getXXPolicyItemAccess().create(xPolItemAcc);
            }
            List<String> groups = Arrays.asList(GROUP_PUBLIC);
            for (int i = 0; i < groups.size(); i++) {
                String group = groups.get(i);
                if (StringUtils.isBlank(group)) {
                    continue;
                }
                XXGroup xGrp = daoMgr.getXXGroup().findByGroupName(group);
                if (xGrp == null) {
                    throw new RuntimeException(group + ": group does not exist. policy='" + xxPolicy.getName() + "' service='" + xxPolicy.getService() + "' group='" + group + "'");
                }
                XXPolicyItemGroupPerm xGrpPerm = new XXPolicyItemGroupPerm();
                xGrpPerm.setGroupId(xGrp.getId());
                xGrpPerm.setPolicyItemId(createdXXPolicyItem.getId());
                xGrpPerm.setOrder(i);
                xGrpPerm.setAddedByUserId(currentUserId);
                xGrpPerm.setUpdatedByUserId(currentUserId);
                daoMgr.getXXPolicyItemGroupPerm().create(xGrpPerm);
            }
            for (int i = 0; i < ATLAS_RESOURCES.size(); i++) {
                XXResourceDef xResDef = daoMgr.getXXResourceDef().findByNameAndPolicyId(ATLAS_RESOURCES.get(i), createdPolicy.getId());
                if (xResDef == null) {
                    throw new RuntimeException(ATLAS_RESOURCES.get(i) + ": is not a valid resource-type. policy='" + createdPolicy.getName() + "' service='" + createdPolicy.getService() + "'");
                }
                XXPolicyResource xPolRes = new XXPolicyResource();
                xPolRes.setAddedByUserId(currentUserId);
                xPolRes.setUpdatedByUserId(currentUserId);
                xPolRes.setIsExcludes(Boolean.FALSE);
                xPolRes.setIsRecursive(Boolean.FALSE);
                xPolRes.setPolicyId(createdPolicy.getId());
                xPolRes.setResDefId(xResDef.getId());
                xPolRes = daoMgr.getXXPolicyResource().create(xPolRes);
                XXPolicyResourceMap xPolResMap = new XXPolicyResourceMap();
                xPolResMap.setResourceId(xPolRes.getId());
                xPolResMap.setValue("*");
                xPolResMap.setOrder(i);
                xPolResMap.setAddedByUserId(currentUserId);
                xPolResMap.setUpdatedByUserId(currentUserId);
                daoMgr.getXXPolicyResourceMap().create(xPolResMap);
            }
            logger.info("Creating policy for service id : " + xxService.getId());
        }
    }
    logger.info("<== createDefaultPolicyToExistingService ");
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXPolicyItemGroupPerm(org.apache.ranger.entity.XXPolicyItemGroupPerm) XXPolicyResourceMap(org.apache.ranger.entity.XXPolicyResourceMap) XXPolicy(org.apache.ranger.entity.XXPolicy) XXResourceDef(org.apache.ranger.entity.XXResourceDef) XXPortalUser(org.apache.ranger.entity.XXPortalUser) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXPolicyItem(org.apache.ranger.entity.XXPolicyItem) XXPolicyItemAccess(org.apache.ranger.entity.XXPolicyItemAccess) XXGroup(org.apache.ranger.entity.XXGroup) XXPolicyResource(org.apache.ranger.entity.XXPolicyResource) RangerPolicyResourceSignature(org.apache.ranger.plugin.model.RangerPolicyResourceSignature) XXAccessTypeDef(org.apache.ranger.entity.XXAccessTypeDef) XXService(org.apache.ranger.entity.XXService)

Example 28 with XXPolicy

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

the class PatchForAtlasToAddEntityLabelAndBusinessMetadata_J10034 method createDefaultPolicyForEntityLabelAndEntityBusinessMetadata.

private void createDefaultPolicyForEntityLabelAndEntityBusinessMetadata() throws Exception {
    logger.info("==> createDefaultPolicyForEntityLabelAndEntityBusinessMetadata ");
    XXServiceDef xXServiceDefObj = daoMgr.getXXServiceDef().findByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME);
    if (xXServiceDefObj == null) {
        logger.debug("ServiceDef not found with name :" + EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME);
        return;
    }
    Long xServiceDefId = xXServiceDefObj.getId();
    List<XXService> xxServices = daoMgr.getXXService().findByServiceDefId(xServiceDefId);
    for (XXService xxService : xxServices) {
        List<XXPolicy> xxPolicies = daoMgr.getXXPolicy().findByServiceId(xxService.getId());
        Boolean isEntityLabelPolicyPresent = false;
        Boolean isEntityBusinessMetadataPolicyPresent = false;
        for (XXPolicy xxPolicy : xxPolicies) {
            if (xxPolicy.getName().equalsIgnoreCase(RESOURCE_DEF_ENTITY_LABEL)) {
                isEntityLabelPolicyPresent = true;
            }
            if (xxPolicy.getName().equalsIgnoreCase(RESOURCE_DEF_ENTITY_BUSINESS_METADATA)) {
                isEntityBusinessMetadataPolicyPresent = true;
            }
            if (isEntityLabelPolicyPresent && isEntityBusinessMetadataPolicyPresent) {
                break;
            }
        }
        if (!isEntityLabelPolicyPresent) {
            List<String> accessTypesLabel = Arrays.asList("entity-add-label", "entity-remove-label");
            List<String> accessTypesReadEntity = Arrays.asList("entity-read");
            createDefaultRangerPolicy(xServiceDefId, xxService, RESOURCE_DEF_ENTITY_LABEL, accessTypesLabel, accessTypesReadEntity, ATLAS_RESOURCE_LABEL);
        }
        if (!isEntityBusinessMetadataPolicyPresent) {
            List<String> accessTypesBusinessMetadata = Arrays.asList("entity-update-business-metadata");
            List<String> accessTypesReadEntity = Arrays.asList("entity-read");
            createDefaultRangerPolicy(xServiceDefId, xxService, RESOURCE_DEF_ENTITY_BUSINESS_METADATA, accessTypesBusinessMetadata, accessTypesReadEntity, ATLAS_RESOURCE_BUSINESS_METADATA);
        }
    }
    logger.info("<== createDefaultPolicyForEntityLabelAndEntityBusinessMetadata ");
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXService(org.apache.ranger.entity.XXService) XXPolicy(org.apache.ranger.entity.XXPolicy)

Example 29 with XXPolicy

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

the class TestXUserMgr method test126DeleteXGroup.

@Test
public void test126DeleteXGroup() {
    destroySession();
    setup();
    boolean force = true;
    VXGroup vXGroup = vxGroup();
    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);
    List<XXGroupGroup> xXGroupGroups = new ArrayList<XXGroupGroup>();
    XXGroupGroup xXGroupGroup = xxGroupGroup();
    xXGroupGroups.add(xXGroupGroup);
    List<XXGroupPermission> xXGroupPermissions = new ArrayList<XXGroupPermission>();
    XXGroupPermission xGroupPermissionObj = xxGroupPermission();
    xXGroupPermissions.add(xGroupPermissionObj);
    List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
    XXPolicy xXPolicy = getXXPolicy();
    xXPolicyList.add(xXPolicy);
    List<XXResource> xResourceList = new ArrayList<XXResource>();
    XXResource xXResource = new XXResource();
    xXResource.setId(userId);
    xXResource.setName("hadoopdev");
    xXResource.setIsRecursive(AppConstants.BOOL_TRUE);
    xXResource.setResourceStatus(AppConstants.STATUS_ENABLED);
    xResourceList.add(xXResource);
    XXSecurityZoneRefGroup xZoneAdminGroup = new XXSecurityZoneRefGroup();
    xZoneAdminGroup.setZoneId(2L);
    xZoneAdminGroup.setGroupId(vXGroup.getId());
    xZoneAdminGroup.setGroupName(vXGroup.getName());
    xZoneAdminGroup.setGroupType(1);
    List<XXSecurityZoneRefGroup> zoneSecRefGroup = new ArrayList<XXSecurityZoneRefGroup>();
    zoneSecRefGroup.add(xZoneAdminGroup);
    XXSecurityZoneRefGroupDao zoneSecRefGroupDao = Mockito.mock(XXSecurityZoneRefGroupDao.class);
    Mockito.when(daoManager.getXXSecurityZoneRefGroup()).thenReturn(zoneSecRefGroupDao);
    Mockito.when(zoneSecRefGroupDao.findByGroupId(userId)).thenReturn(zoneSecRefGroup);
    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(xZoneAdminGroup.getZoneId())).thenReturn(xxSecurityZone);
    List<XXRoleRefGroup> roleRefGroup = new ArrayList<XXRoleRefGroup>();
    XXRoleRefGroup xRoleRefGroup = new XXRoleRefGroup();
    xRoleRefGroup.setRoleId(userId);
    xRoleRefGroup.setGroupId(userId);
    xRoleRefGroup.setGroupName(groupName);
    xRoleRefGroup.setGroupType(0);
    roleRefGroup.add(xRoleRefGroup);
    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 Group '" + vXGroup.getName().trim() + "' as its present in " + RangerConstants.ROLE_FIELD);
    Mockito.when(restErrorUtil.generateRESTException((VXResponse) Mockito.any())).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    xUserMgr.deleteXGroup(vXGroup.getId(), force);
}
Also used : XXSecurityZoneRefGroup(org.apache.ranger.entity.XXSecurityZoneRefGroup) RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXSecurityZoneDao(org.apache.ranger.db.XXSecurityZoneDao) VXPermMap(org.apache.ranger.view.VXPermMap) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) XXSecurityZoneRefGroupDao(org.apache.ranger.db.XXSecurityZoneRefGroupDao) XXPolicy(org.apache.ranger.entity.XXPolicy) XXRoleRefGroup(org.apache.ranger.entity.XXRoleRefGroup) VXAuditMap(org.apache.ranger.view.VXAuditMap) VXPermMapList(org.apache.ranger.view.VXPermMapList) VXResponse(org.apache.ranger.view.VXResponse) XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) XXResource(org.apache.ranger.entity.XXResource) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone) VXGroup(org.apache.ranger.view.VXGroup) XXGroupGroup(org.apache.ranger.entity.XXGroupGroup) XXRole(org.apache.ranger.entity.XXRole) Test(org.junit.Test)

Example 30 with XXPolicy

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

the class TestXUserMgr method test20DeleteXGroup.

@Test
public void test20DeleteXGroup() {
    setup();
    boolean force = true;
    VXGroup vXGroup = vxGroup();
    XXGroupDao xXGroupDao = Mockito.mock(XXGroupDao.class);
    XXUserDao xXUserDao = Mockito.mock(XXUserDao.class);
    VXUser vxUser = vxUser();
    XXUser xXUser = xxUser(vxUser);
    Mockito.when(daoManager.getXXUser()).thenReturn(xXUserDao);
    Mockito.when(xXUserDao.getById(xXUser.getId())).thenReturn(xXUser);
    XXGroup xXGroup = new XXGroup();
    Mockito.when(daoManager.getXXGroup()).thenReturn(xXGroupDao);
    Mockito.when(xXGroupDao.getById(vXGroup.getId())).thenReturn(xXGroup);
    Mockito.when(xGroupService.populateViewBean(xXGroup)).thenReturn(vXGroup);
    VXGroupUserList vxGroupUserList = vxGroupUserList();
    XXGroupUserDao xGroupUserDao = Mockito.mock(XXGroupUserDao.class);
    Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
    Mockito.when(daoManager.getXXGroupUser()).thenReturn(xGroupUserDao);
    VXPermMapList vXPermMapList = new VXPermMapList();
    VXPermMap vXPermMap1 = getVXPermMap();
    List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
    vXPermMaps.add(vXPermMap1);
    vXPermMapList.setVXPermMaps(vXPermMaps);
    XXPermMapDao xXPermMapDao = Mockito.mock(XXPermMapDao.class);
    Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(vXPermMapList);
    Mockito.when(daoManager.getXXPermMap()).thenReturn(xXPermMapDao);
    VXAuditMapList vXAuditMapList = new VXAuditMapList();
    List<VXAuditMap> vXAuditMaps = new ArrayList<VXAuditMap>();
    VXAuditMap vXAuditMap = getVXAuditMap();
    vXAuditMaps.add(vXAuditMap);
    vXAuditMapList.setVXAuditMaps(vXAuditMaps);
    XXAuditMapDao xXAuditMapDao = Mockito.mock(XXAuditMapDao.class);
    Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(vXAuditMapList);
    Mockito.when(daoManager.getXXAuditMap()).thenReturn(xXAuditMapDao);
    XXGroupGroupDao xXGroupGroupDao = Mockito.mock(XXGroupGroupDao.class);
    List<XXGroupGroup> xXGroupGroups = new ArrayList<XXGroupGroup>();
    XXGroupGroup xXGroupGroup = xxGroupGroup();
    xXGroupGroups.add(xXGroupGroup);
    Mockito.when(daoManager.getXXGroupGroup()).thenReturn(xXGroupGroupDao);
    Mockito.when(xXGroupGroupDao.findByGroupId(userId)).thenReturn(xXGroupGroups);
    XXGroupPermissionDao xXGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
    Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xXGroupPermissionDao);
    List<XXGroupPermission> xXGroupPermissions = new ArrayList<XXGroupPermission>();
    XXGroupPermission xGroupPermissionObj = xxGroupPermission();
    xXGroupPermissions.add(xGroupPermissionObj);
    Mockito.when(xXGroupPermissionDao.findByGroupId(vXGroup.getId())).thenReturn(xXGroupPermissions);
    XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class);
    List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
    XXPolicy xXPolicy = getXXPolicy();
    xXPolicyList.add(xXPolicy);
    Mockito.when(daoManager.getXXPolicy()).thenReturn(xXPolicyDao);
    Mockito.when(xXPolicyDao.findByGroupId(userId)).thenReturn(xXPolicyList);
    List<XXResource> xResourceList = new ArrayList<XXResource>();
    XXResource xXResource = new XXResource();
    xXResource.setId(userId);
    xXResource.setName("hadoopdev");
    xXResource.setIsRecursive(AppConstants.BOOL_TRUE);
    xXResource.setResourceStatus(AppConstants.STATUS_ENABLED);
    xResourceList.add(xXResource);
    XXResourceDao xxResourceDao = Mockito.mock(XXResourceDao.class);
    Mockito.when(daoManager.getXXResource()).thenReturn(xxResourceDao);
    Mockito.when(xxResourceDao.getById(Mockito.anyLong())).thenReturn(xXResource);
    RangerPolicy rangerPolicy = rangerPolicy();
    Mockito.when(policyService.getPopulatedViewObject(xXPolicy)).thenReturn(rangerPolicy);
    XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
    XXModuleDef xModuleDef = xxModuleDef();
    Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
    List<XXSecurityZoneRefGroup> zoneSecRefGroup = new ArrayList<XXSecurityZoneRefGroup>();
    XXSecurityZoneRefGroupDao zoneSecRefGroupDao = Mockito.mock(XXSecurityZoneRefGroupDao.class);
    Mockito.when(daoManager.getXXSecurityZoneRefGroup()).thenReturn(zoneSecRefGroupDao);
    Mockito.when(zoneSecRefGroupDao.findByGroupId(userId)).thenReturn(zoneSecRefGroup);
    List<XXRoleRefGroup> roleRefGroup = new ArrayList<XXRoleRefGroup>();
    XXRoleRefGroupDao roleRefGroupDao = Mockito.mock(XXRoleRefGroupDao.class);
    Mockito.when(daoManager.getXXRoleRefGroup()).thenReturn(roleRefGroupDao);
    Mockito.when(roleRefGroupDao.findByGroupId(userId)).thenReturn(roleRefGroup);
    xUserMgr.deleteXGroup(vXGroup.getId(), force);
}
Also used : XXUser(org.apache.ranger.entity.XXUser) XXSecurityZoneRefGroup(org.apache.ranger.entity.XXSecurityZoneRefGroup) VXGroupUserList(org.apache.ranger.view.VXGroupUserList) VXPermMap(org.apache.ranger.view.VXPermMap) XXUserDao(org.apache.ranger.db.XXUserDao) XXGroupPermissionDao(org.apache.ranger.db.XXGroupPermissionDao) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) XXSecurityZoneRefGroupDao(org.apache.ranger.db.XXSecurityZoneRefGroupDao) XXPolicy(org.apache.ranger.entity.XXPolicy) XXRoleRefGroupDao(org.apache.ranger.db.XXRoleRefGroupDao) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXModuleDef(org.apache.ranger.entity.XXModuleDef) XXRoleRefGroup(org.apache.ranger.entity.XXRoleRefGroup) XXPermMapDao(org.apache.ranger.db.XXPermMapDao) VXAuditMap(org.apache.ranger.view.VXAuditMap) VXPermMapList(org.apache.ranger.view.VXPermMapList) XXGroupGroupDao(org.apache.ranger.db.XXGroupGroupDao) XXResourceDao(org.apache.ranger.db.XXResourceDao) XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) XXResource(org.apache.ranger.entity.XXResource) XXAuditMapDao(org.apache.ranger.db.XXAuditMapDao) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) VXUser(org.apache.ranger.view.VXUser) XXGroup(org.apache.ranger.entity.XXGroup) XXPolicyDao(org.apache.ranger.db.XXPolicyDao) VXGroup(org.apache.ranger.view.VXGroup) XXGroupDao(org.apache.ranger.db.XXGroupDao) XXGroupGroup(org.apache.ranger.entity.XXGroupGroup) Test(org.junit.Test)

Aggregations

XXPolicy (org.apache.ranger.entity.XXPolicy)43 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)25 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)12 XXPolicyDao (org.apache.ranger.db.XXPolicyDao)11 VXAuditMapList (org.apache.ranger.view.VXAuditMapList)10 VXPermMapList (org.apache.ranger.view.VXPermMapList)10 XXPortalUser (org.apache.ranger.entity.XXPortalUser)9 XXService (org.apache.ranger.entity.XXService)9 XXServiceDef (org.apache.ranger.entity.XXServiceDef)9 XXUser (org.apache.ranger.entity.XXUser)9 XXUserDao (org.apache.ranger.db.XXUserDao)8 RangerService (org.apache.ranger.plugin.model.RangerService)8 VXAuditMap (org.apache.ranger.view.VXAuditMap)8 VXPermMap (org.apache.ranger.view.VXPermMap)8 WebApplicationException (javax.ws.rs.WebApplicationException)7 XXAuditMapDao (org.apache.ranger.db.XXAuditMapDao)6 XXGroupUserDao (org.apache.ranger.db.XXGroupUserDao)6 XXPermMapDao (org.apache.ranger.db.XXPermMapDao)6 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)6