Search in sources :

Example 1 with RangerServiceDef

use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.

the class ServiceDBStore method getServiceDefByName.

@Override
public RangerServiceDef getServiceDefByName(String name) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceDBStore.getServiceDefByName(" + name + ")");
    }
    RangerServiceDef ret = null;
    XXServiceDef xServiceDef = daoMgr.getXXServiceDef().findByName(name);
    if (xServiceDef != null) {
        ret = serviceDefService.getPopulatedViewObject(xServiceDef);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("== ServiceDBStore.getServiceDefByName(" + name + "): " + ret);
    }
    return ret;
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef)

Example 2 with RangerServiceDef

use of org.apache.ranger.plugin.model.RangerServiceDef 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);
        }
    }
    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<XXPolicyItemCondition> policyItemCondList = daoMgr.getXXPolicyItemCondition().findByPolicyConditionDefId(policyCond.getId());
        for (XXPolicyItemCondition policyItemCond : policyItemCondList) {
            daoMgr.getXXPolicyItemCondition().remove(policyItemCond);
        }
        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);
    }
    if (CollectionUtils.isNotEmpty(serviceList)) {
        for (XXService service : serviceList) {
            deleteService(service.getId());
        }
    }
    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) XXPolicyItemCondition(org.apache.ranger.entity.XXPolicyItemCondition) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXDataMaskTypeDef(org.apache.ranger.entity.XXDataMaskTypeDef) XXEnumDefDao(org.apache.ranger.db.XXEnumDefDao) XXPolicyConditionDef(org.apache.ranger.entity.XXPolicyConditionDef) 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 3 with RangerServiceDef

use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.

the class ServiceDBStore method getServiceDefs.

@Override
public List<RangerServiceDef> getServiceDefs(SearchFilter filter) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceDBStore.getServiceDefs(" + filter + ")");
    }
    RangerServiceDefList svcDefList = serviceDefService.searchRangerServiceDefs(filter);
    predicateUtil.applyFilter(svcDefList.getServiceDefs(), filter);
    List<RangerServiceDef> ret = svcDefList.getServiceDefs();
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceDBStore.getServiceDefs(" + filter + "): " + ret);
    }
    return ret;
}
Also used : RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) RangerServiceDefList(org.apache.ranger.view.RangerServiceDefList)

Example 4 with RangerServiceDef

use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.

the class ServiceMgr method getRangerServiceByService.

public RangerBaseService getRangerServiceByService(RangerService service, ServiceStore svcStore) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceMgr.getRangerServiceByService(" + service + ")");
    }
    RangerBaseService ret = null;
    String serviceType = service == null ? null : service.getType();
    if (!StringUtils.isEmpty(serviceType)) {
        RangerServiceDef serviceDef = svcStore == null ? null : svcStore.getServiceDefByName(serviceType);
        if (serviceDef != null) {
            Class<RangerBaseService> cls = getClassForServiceType(serviceDef);
            if (cls != null) {
                ret = cls.newInstance();
                ret.init(serviceDef, service);
                if (ret instanceof RangerServiceTag) {
                    ((RangerServiceTag) ret).setTagStore(tagStore);
                }
            } else {
                LOG.warn("ServiceMgr.getRangerServiceByService(" + service + "): could not find service class '" + serviceDef.getImplClass() + "' for the service type '" + serviceType + "'");
            }
        } else {
            LOG.warn("ServiceMgr.getRangerServiceByService(" + service + "): could not find the service-def for the service type '" + serviceType + "'");
        }
    } else {
        LOG.warn("ServiceMgr.getRangerServiceByService(" + service + "): could not find the service-type '" + serviceType + "'");
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== ServiceMgr.getRangerServiceByService(" + service + "): " + ret);
    }
    return ret;
}
Also used : RangerBaseService(org.apache.ranger.plugin.service.RangerBaseService) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) RangerServiceTag(org.apache.ranger.services.tag.RangerServiceTag)

Example 5 with RangerServiceDef

use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.

the class TestRangerServiceDefService method rangerServiceDef.

private RangerServiceDef rangerServiceDef() {
    List<RangerServiceConfigDef> configs = new ArrayList<RangerServiceConfigDef>();
    List<RangerResourceDef> resources = new ArrayList<RangerResourceDef>();
    List<RangerAccessTypeDef> accessTypes = new ArrayList<RangerAccessTypeDef>();
    List<RangerPolicyConditionDef> policyConditions = new ArrayList<RangerPolicyConditionDef>();
    List<RangerContextEnricherDef> contextEnrichers = new ArrayList<RangerContextEnricherDef>();
    List<RangerEnumDef> enums = new ArrayList<RangerEnumDef>();
    RangerServiceDef rangerServiceDef = new RangerServiceDef();
    rangerServiceDef.setId(Id);
    rangerServiceDef.setImplClass("RangerServiceHdfs");
    rangerServiceDef.setLabel("HDFS Repository");
    rangerServiceDef.setDescription("HDFS Repository");
    rangerServiceDef.setRbKeyDescription(null);
    rangerServiceDef.setUpdatedBy("Admin");
    rangerServiceDef.setUpdateTime(new Date());
    rangerServiceDef.setConfigs(configs);
    rangerServiceDef.setResources(resources);
    rangerServiceDef.setAccessTypes(accessTypes);
    rangerServiceDef.setPolicyConditions(policyConditions);
    rangerServiceDef.setContextEnrichers(contextEnrichers);
    rangerServiceDef.setEnums(enums);
    return rangerServiceDef;
}
Also used : RangerServiceConfigDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef) ArrayList(java.util.ArrayList) RangerEnumDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef) RangerPolicyConditionDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerPolicyConditionDef) Date(java.util.Date) RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) RangerContextEnricherDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerContextEnricherDef) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) RangerResourceDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef)

Aggregations

RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)105 Test (org.junit.Test)52 ArrayList (java.util.ArrayList)38 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)19 XXServiceDef (org.apache.ranger.entity.XXServiceDef)18 Date (java.util.Date)15 HashMap (java.util.HashMap)13 ServicePolicies (org.apache.ranger.plugin.util.ServicePolicies)13 RangerService (org.apache.ranger.plugin.model.RangerService)12 RangerResourceDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef)12 RangerServiceConfigDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef)12 RangerAccessTypeDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef)11 VXString (org.apache.ranger.view.VXString)10 RangerPolicyItem (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem)9 RangerContextEnricherDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerContextEnricherDef)9 RangerPolicyConditionDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerPolicyConditionDef)9 RangerPolicyItemAccess (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess)8 RangerPolicyResource (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)8 RangerEnumDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef)8 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)7