Search in sources :

Example 1 with XXServiceConfigDef

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

the class PatchForDefaultAuidtFilters_J10050 method addDefaultAuditFilters.

private void addDefaultAuditFilters() throws Exception {
    logger.debug("==> PatchForDefaultAuidtFilters_J10050.addDefaultAuditFilters()");
    Map<String, String> defaultAuditFiltersMap = null;
    List<XXService> xxServiceList = daoMgr.getXXService().getAll();
    if (CollectionUtils.isNotEmpty(xxServiceList)) {
        logger.info("Found " + xxServiceList.size() + " services");
        defaultAuditFiltersMap = new HashMap<String, String>();
        for (XXService xservice : xxServiceList) {
            RangerService rangerService = svcStore.getServiceByName(xservice.getName());
            if (rangerService != null && !rangerService.getConfigs().containsKey(ServiceDBStore.RANGER_PLUGIN_AUDIT_FILTERS)) {
                if (!defaultAuditFiltersMap.containsKey(rangerService.getType())) {
                    List<XXServiceConfigDef> svcConfDefList = daoMgr.getXXServiceConfigDef().findByServiceDefName(rangerService.getType());
                    for (XXServiceConfigDef svcConfDef : svcConfDefList) {
                        if (StringUtils.equals(svcConfDef.getName(), ServiceDBStore.RANGER_PLUGIN_AUDIT_FILTERS)) {
                            defaultAuditFiltersMap.put(rangerService.getType(), svcConfDef.getDefaultvalue());
                            continue;
                        }
                    }
                }
                if (defaultAuditFiltersMap.get(rangerService.getType()) != null) {
                    Map<String, String> configs = rangerService.getConfigs();
                    if (!configs.containsKey(ServiceDBStore.RANGER_PLUGIN_AUDIT_FILTERS)) {
                        logger.info("adding default audit-filter to service " + rangerService.getName());
                        addDefaultAuditFilterConfig(xservice, defaultAuditFiltersMap.get(rangerService.getType()));
                    }
                } else {
                    logger.info("No default audit-filter available for service " + rangerService.getName() + ". Skipped");
                }
            }
        }
    }
    logger.info("<== PatchForDefaultAuidtFilters_J10050.addDefaultAuditFilters()");
}
Also used : RangerService(org.apache.ranger.plugin.model.RangerService) XXServiceConfigDef(org.apache.ranger.entity.XXServiceConfigDef) XXService(org.apache.ranger.entity.XXService)

Example 2 with XXServiceConfigDef

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

the class PatchMigration_J10002 method mapXAssetToService.

private RangerService mapXAssetToService(RangerService service, XXAsset xAsset) throws Exception {
    String type = "";
    String name = xAsset.getName();
    String description = xAsset.getDescription();
    Map<String, String> configs = null;
    int typeInt = xAsset.getAssetType();
    XXServiceDef serviceDef = daoMgr.getXXServiceDef().findByName(AppConstants.getLabelFor_AssetType(typeInt).toLowerCase());
    if (serviceDef == null) {
        throw new Exception("No ServiceDefinition found for repository: " + name);
    }
    type = serviceDef.getName();
    configs = jsonUtil.jsonToMap(xAsset.getConfig());
    List<XXServiceConfigDef> mandatoryConfigs = daoMgr.getXXServiceConfigDef().findByServiceDefName(type);
    for (XXServiceConfigDef serviceConf : mandatoryConfigs) {
        if (serviceConf.getIsMandatory()) {
            if (!stringUtil.isEmpty(configs.get(serviceConf.getName()))) {
                continue;
            }
            String dataType = serviceConf.getType();
            String defaultValue = serviceConf.getDefaultvalue();
            if (stringUtil.isEmpty(defaultValue)) {
                defaultValue = getDefaultValueForDataType(dataType);
            }
            configs.put(serviceConf.getName(), defaultValue);
        }
    }
    service.setType(type);
    service.setName(name);
    service.setDescription(description);
    service.setConfigs(configs);
    service.setCreateTime(xAsset.getCreateTime());
    service.setUpdateTime(xAsset.getUpdateTime());
    XXPortalUser createdByUser = daoMgr.getXXPortalUser().getById(xAsset.getAddedByUserId());
    XXPortalUser updByUser = daoMgr.getXXPortalUser().getById(xAsset.getUpdatedByUserId());
    if (createdByUser != null) {
        service.setCreatedBy(createdByUser.getLoginId());
    }
    if (updByUser != null) {
        service.setUpdatedBy(updByUser.getLoginId());
    }
    service.setId(xAsset.getId());
    return service;
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXServiceConfigDef(org.apache.ranger.entity.XXServiceConfigDef)

Example 3 with XXServiceConfigDef

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

the class ServiceDBStore method deleteServiceDef.

public void deleteServiceDef(Long serviceDefId, Boolean forceDelete) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceDBStore.deleteServiceDef(" + serviceDefId + ", " + forceDelete + ")");
    }
    bizUtil.blockAuditorRoleUser();
    UserSessionBase session = ContextUtil.getCurrentUserSession();
    if (session == null) {
        throw restErrorUtil.createRESTException("UserSession cannot be null, only Admin can update service-def", MessageEnums.OPER_NO_PERMISSION);
    }
    if (!session.isKeyAdmin() && !session.isUserAdmin()) {
        throw restErrorUtil.createRESTException("User is not allowed to update service-def, only Admin can update service-def", MessageEnums.OPER_NO_PERMISSION);
    }
    RangerServiceDef serviceDef = getServiceDef(serviceDefId);
    if (serviceDef == null) {
        throw restErrorUtil.createRESTException("No Service Definiton found for Id: " + serviceDefId, MessageEnums.DATA_NOT_FOUND);
    }
    List<XXService> serviceList = daoMgr.getXXService().findByServiceDefId(serviceDefId);
    if (!forceDelete) {
        if (CollectionUtils.isNotEmpty(serviceList)) {
            throw restErrorUtil.createRESTException("Services exists under given service definition, can't delete Service-Def: " + serviceDef.getName(), MessageEnums.OPER_NOT_ALLOWED_FOR_ENTITY);
        }
    }
    if (CollectionUtils.isNotEmpty(serviceList)) {
        for (XXService service : serviceList) {
            deleteService(service.getId());
        }
    }
    XXDataMaskTypeDefDao dataMaskDao = daoMgr.getXXDataMaskTypeDef();
    List<XXDataMaskTypeDef> dataMaskDefs = dataMaskDao.findByServiceDefId(serviceDefId);
    for (XXDataMaskTypeDef dataMaskDef : dataMaskDefs) {
        dataMaskDao.remove(dataMaskDef);
    }
    List<XXAccessTypeDef> accTypeDefs = daoMgr.getXXAccessTypeDef().findByServiceDefId(serviceDefId);
    for (XXAccessTypeDef accessType : accTypeDefs) {
        deleteXXAccessTypeDef(accessType);
    }
    XXContextEnricherDefDao xContextEnricherDao = daoMgr.getXXContextEnricherDef();
    List<XXContextEnricherDef> contextEnrichers = xContextEnricherDao.findByServiceDefId(serviceDefId);
    for (XXContextEnricherDef context : contextEnrichers) {
        xContextEnricherDao.remove(context);
    }
    XXEnumDefDao enumDefDao = daoMgr.getXXEnumDef();
    List<XXEnumDef> enumDefList = enumDefDao.findByServiceDefId(serviceDefId);
    for (XXEnumDef enumDef : enumDefList) {
        List<XXEnumElementDef> enumEleDefList = daoMgr.getXXEnumElementDef().findByEnumDefId(enumDef.getId());
        for (XXEnumElementDef eleDef : enumEleDefList) {
            daoMgr.getXXEnumElementDef().remove(eleDef);
        }
        enumDefDao.remove(enumDef);
    }
    XXPolicyConditionDefDao policyCondDao = daoMgr.getXXPolicyConditionDef();
    List<XXPolicyConditionDef> policyCondList = policyCondDao.findByServiceDefId(serviceDefId);
    for (XXPolicyConditionDef policyCond : policyCondList) {
        List<XXPolicyRefCondition> xxPolicyRefConditions = daoMgr.getXXPolicyRefCondition().findByConditionDefId(policyCond.getId());
        for (XXPolicyRefCondition XXPolicyRefCondition : xxPolicyRefConditions) {
            daoMgr.getXXPolicyRefCondition().remove(XXPolicyRefCondition);
        }
        policyCondDao.remove(policyCond);
    }
    List<XXResourceDef> resDefList = daoMgr.getXXResourceDef().findByServiceDefId(serviceDefId);
    for (XXResourceDef resDef : resDefList) {
        deleteXXResourceDef(resDef);
    }
    XXServiceConfigDefDao configDefDao = daoMgr.getXXServiceConfigDef();
    List<XXServiceConfigDef> configDefList = configDefDao.findByServiceDefId(serviceDefId);
    for (XXServiceConfigDef configDef : configDefList) {
        configDefDao.remove(configDef);
    }
    Long version = serviceDef.getVersion();
    if (version == null) {
        version = Long.valueOf(1);
        LOG.info("Found Version Value: `null`, so setting value of version to 1, While updating object, version should not be null.");
    } else {
        version = Long.valueOf(version.longValue() + 1);
    }
    serviceDef.setVersion(version);
    serviceDefService.delete(serviceDef);
    LOG.info("ServiceDefinition has been deleted successfully. Service-Def Name: " + serviceDef.getName());
    dataHistService.createObjectDataHistory(serviceDef, RangerDataHistService.ACTION_DELETE);
    postDelete(serviceDef);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== ServiceDBStore.deleteServiceDef(" + serviceDefId + ", " + forceDelete + ")");
    }
}
Also used : XXDataMaskTypeDefDao(org.apache.ranger.db.XXDataMaskTypeDefDao) XXPolicyConditionDefDao(org.apache.ranger.db.XXPolicyConditionDefDao) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXDataMaskTypeDef(org.apache.ranger.entity.XXDataMaskTypeDef) XXEnumDefDao(org.apache.ranger.db.XXEnumDefDao) XXPolicyConditionDef(org.apache.ranger.entity.XXPolicyConditionDef) XXPolicyRefCondition(org.apache.ranger.entity.XXPolicyRefCondition) XXAccessTypeDef(org.apache.ranger.entity.XXAccessTypeDef) XXServiceConfigDef(org.apache.ranger.entity.XXServiceConfigDef) XXResourceDef(org.apache.ranger.entity.XXResourceDef) XXEnumElementDef(org.apache.ranger.entity.XXEnumElementDef) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) XXEnumDef(org.apache.ranger.entity.XXEnumDef) XXService(org.apache.ranger.entity.XXService) XXServiceConfigDefDao(org.apache.ranger.db.XXServiceConfigDefDao) XXContextEnricherDef(org.apache.ranger.entity.XXContextEnricherDef) XXContextEnricherDefDao(org.apache.ranger.db.XXContextEnricherDefDao)

Example 4 with XXServiceConfigDef

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

the class ServiceDBStore method validateRequiredConfigParams.

private Map<String, String> validateRequiredConfigParams(RangerService service, Map<String, String> configs) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceDBStore.validateRequiredConfigParams()");
    }
    if (configs == null) {
        return null;
    }
    List<XXServiceConfigDef> svcConfDefList = daoMgr.getXXServiceConfigDef().findByServiceDefName(service.getType());
    for (XXServiceConfigDef svcConfDef : svcConfDefList) {
        String confField = configs.get(svcConfDef.getName());
        if (svcConfDef.getIsMandatory() && stringUtil.isEmpty(confField)) {
            throw restErrorUtil.createRESTException("Please provide value of mandatory: " + svcConfDef.getName(), MessageEnums.INVALID_INPUT_DATA);
        }
        if (StringUtils.equals(svcConfDef.getName(), RANGER_PLUGIN_AUDIT_FILTERS) && !configs.containsKey(RANGER_PLUGIN_AUDIT_FILTERS)) {
            if (svcConfDef.getDefaultvalue() != null) {
                configs.put(RANGER_PLUGIN_AUDIT_FILTERS, svcConfDef.getDefaultvalue());
            }
        }
    }
    Map<String, String> validConfigs = new HashMap<String, String>();
    for (Entry<String, String> config : configs.entrySet()) {
        if (!stringUtil.isEmpty(config.getValue())) {
            validConfigs.put(config.getKey(), config.getValue());
        }
    }
    return validConfigs;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) XXServiceConfigDef(org.apache.ranger.entity.XXServiceConfigDef) VXString(org.apache.ranger.view.VXString)

Example 5 with XXServiceConfigDef

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

the class TestRangerServiceDefServiceBase method test4populateXXToRangerServiceConfigDef.

@Test
public void test4populateXXToRangerServiceConfigDef() {
    XXServiceConfigDef serviceConfigDefObj = new XXServiceConfigDef();
    RangerServiceConfigDef dbserviceConfigDefObj = rangerServiceDefService.populateXXToRangerServiceConfigDef(serviceConfigDefObj);
    Assert.assertNotNull(dbserviceConfigDefObj);
}
Also used : RangerServiceConfigDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef) XXServiceConfigDef(org.apache.ranger.entity.XXServiceConfigDef) Test(org.junit.Test)

Aggregations

XXServiceConfigDef (org.apache.ranger.entity.XXServiceConfigDef)9 XXServiceConfigDefDao (org.apache.ranger.db.XXServiceConfigDefDao)4 RangerServiceConfigDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef)4 XXContextEnricherDefDao (org.apache.ranger.db.XXContextEnricherDefDao)3 XXDataMaskTypeDefDao (org.apache.ranger.db.XXDataMaskTypeDefDao)3 XXEnumDefDao (org.apache.ranger.db.XXEnumDefDao)3 XXPolicyConditionDefDao (org.apache.ranger.db.XXPolicyConditionDefDao)3 XXAccessTypeDef (org.apache.ranger.entity.XXAccessTypeDef)3 XXContextEnricherDef (org.apache.ranger.entity.XXContextEnricherDef)3 XXDataMaskTypeDef (org.apache.ranger.entity.XXDataMaskTypeDef)3 XXEnumDef (org.apache.ranger.entity.XXEnumDef)3 XXEnumElementDef (org.apache.ranger.entity.XXEnumElementDef)3 XXPolicyConditionDef (org.apache.ranger.entity.XXPolicyConditionDef)3 XXResourceDef (org.apache.ranger.entity.XXResourceDef)3 XXServiceDef (org.apache.ranger.entity.XXServiceDef)3 VXString (org.apache.ranger.view.VXString)3 XXAccessTypeDefDao (org.apache.ranger.db.XXAccessTypeDefDao)2 XXAccessTypeDefGrantsDao (org.apache.ranger.db.XXAccessTypeDefGrantsDao)2 XXEnumElementDefDao (org.apache.ranger.db.XXEnumElementDefDao)2 XXResourceDefDao (org.apache.ranger.db.XXResourceDefDao)2