Search in sources :

Example 56 with XXService

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

the class RangerPluginInfoService method searchRangerPluginInfo.

public PList<RangerPluginInfo> searchRangerPluginInfo(SearchFilter searchFilter) {
    PList<RangerPluginInfo> retList = new PList<RangerPluginInfo>();
    List<RangerPluginInfo> objList = new ArrayList<RangerPluginInfo>();
    List<XXService> servicesWithTagService = daoManager.getXXService().getAllServicesWithTagService();
    List<XXPluginInfo> xObjList = searchRangerObjects(searchFilter, searchFields, sortFields, retList);
    List<Object[]> objectsList = null;
    if (CollectionUtils.isNotEmpty(xObjList)) {
        objectsList = daoManager.getXXServiceVersionInfo().getAllWithServiceNames();
    }
    for (XXPluginInfo xObj : xObjList) {
        XXServiceVersionInfo xxServiceVersionInfo = null;
        boolean hasAssociatedTagService = false;
        if (CollectionUtils.isNotEmpty(objectsList)) {
            for (Object[] objects : objectsList) {
                if (objects.length == 2) {
                    if (xObj.getServiceName().equals(objects[1])) {
                        if (objects[0] instanceof XXServiceVersionInfo) {
                            xxServiceVersionInfo = (XXServiceVersionInfo) objects[0];
                            for (XXService service : servicesWithTagService) {
                                if (service.getName().equals(xObj.getServiceName())) {
                                    hasAssociatedTagService = true;
                                    break;
                                }
                            }
                        } else {
                            LOG.warn("Expected first object to be XXServiceVersionInfo, got " + objects[0]);
                        }
                        break;
                    }
                } else {
                    LOG.warn("Expected 2 objects in the list returned by getAllWithServiceNames(), received " + objects.length);
                }
            }
        }
        RangerPluginInfo obj = populateViewObjectWithServiceVersionInfo(xObj, xxServiceVersionInfo, hasAssociatedTagService);
        objList.add(obj);
    }
    retList.setList(objList);
    return retList;
}
Also used : PList(org.apache.ranger.plugin.store.PList) ArrayList(java.util.ArrayList) XXPluginInfo(org.apache.ranger.entity.XXPluginInfo) XXService(org.apache.ranger.entity.XXService) XXServiceVersionInfo(org.apache.ranger.entity.XXServiceVersionInfo) RangerPluginInfo(org.apache.ranger.plugin.model.RangerPluginInfo)

Example 57 with XXService

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

the class RangerPolicyServiceBase method mapViewToEntityBean.

@Override
protected T mapViewToEntityBean(V vObj, T xObj, int OPERATION_CONTEXT) {
    String guid = (StringUtils.isEmpty(vObj.getGuid())) ? guidUtil.genGUID() : vObj.getGuid();
    xObj.setGuid(guid);
    xObj.setVersion(vObj.getVersion());
    XXService xService = daoMgr.getXXService().findByName(vObj.getService());
    if (xService == null) {
        throw restErrorUtil.createRESTException("No corresponding service found for policyName: " + vObj.getName() + "Service Not Found : " + vObj.getService(), MessageEnums.INVALID_INPUT_DATA);
    }
    xObj.setService(xService.getId());
    xObj.setName(StringUtils.trim(vObj.getName()));
    xObj.setPolicyType(vObj.getPolicyType() == null ? RangerPolicy.POLICY_TYPE_ACCESS : vObj.getPolicyType());
    xObj.setPolicyPriority(vObj.getPolicyPriority() == null ? RangerPolicy.POLICY_PRIORITY_NORMAL : vObj.getPolicyPriority());
    xObj.setDescription(vObj.getDescription());
    xObj.setResourceSignature(vObj.getResourceSignature());
    xObj.setIsAuditEnabled(vObj.getIsAuditEnabled());
    xObj.setIsEnabled(vObj.getIsEnabled());
    String validitySchedules = JsonUtils.listToJson(vObj.getValiditySchedules());
    Map<String, Object> options = vObj.getOptions();
    if (options == null) {
        options = new HashMap<>();
    }
    if (StringUtils.isNotBlank(validitySchedules)) {
        options.put(OPTION_POLICY_VALIDITY_SCHEDULES, validitySchedules);
    } else {
        options.remove(OPTION_POLICY_VALIDITY_SCHEDULES);
    }
    xObj.setOptions(JsonUtils.mapToJson(options));
    return xObj;
}
Also used : XXService(org.apache.ranger.entity.XXService)

Example 58 with XXService

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

the class RangerPolicyServiceBase method mapEntityToViewBean.

@Override
protected V mapEntityToViewBean(V vObj, T xObj) {
    XXService xService = daoMgr.getXXService().getById(xObj.getService());
    vObj.setGuid(xObj.getGuid());
    vObj.setVersion(xObj.getVersion());
    vObj.setService(xService.getName());
    vObj.setName(StringUtils.trim(xObj.getName()));
    vObj.setPolicyType(xObj.getPolicyType() == null ? RangerPolicy.POLICY_TYPE_ACCESS : xObj.getPolicyType());
    vObj.setPolicyPriority(xObj.getPolicyPriority() == null ? RangerPolicy.POLICY_PRIORITY_NORMAL : xObj.getPolicyPriority());
    vObj.setDescription(xObj.getDescription());
    vObj.setResourceSignature(xObj.getResourceSignature());
    vObj.setIsEnabled(xObj.getIsEnabled());
    vObj.setIsAuditEnabled(xObj.getIsAuditEnabled());
    Map<String, Object> options = JsonUtils.jsonToObject(xObj.getOptions(), Map.class);
    if (MapUtils.isNotEmpty(options)) {
        String optionPolicyValiditySchedule = (String) options.remove(OPTION_POLICY_VALIDITY_SCHEDULES);
        if (StringUtils.isNotBlank(optionPolicyValiditySchedule)) {
            List<RangerValiditySchedule> validitySchedules = JsonUtils.jsonToRangerValiditySchedule(optionPolicyValiditySchedule);
            vObj.setValiditySchedules(validitySchedules);
        }
    }
    vObj.setOptions(options);
    return vObj;
}
Also used : RangerValiditySchedule(org.apache.ranger.plugin.model.RangerValiditySchedule) XXService(org.apache.ranger.entity.XXService)

Example 59 with XXService

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

the class RangerServiceResourceServiceBase method mapViewToEntityBean.

@Override
protected T mapViewToEntityBean(V vObj, T xObj, int operationContext) {
    String guid = (StringUtils.isEmpty(vObj.getGuid())) ? guidUtil.genGUID() : vObj.getGuid();
    xObj.setGuid(guid);
    xObj.setVersion(vObj.getVersion());
    xObj.setIsEnabled(vObj.getIsEnabled());
    xObj.setResourceSignature(vObj.getResourceSignature());
    XXService xService = daoMgr.getXXService().findByName(vObj.getServiceName());
    if (xService == null) {
        throw restErrorUtil.createRESTException("Error Populating XXServiceResource. No Service found with name: " + vObj.getServiceName(), MessageEnums.INVALID_INPUT_DATA);
    }
    xObj.setServiceId(xService.getId());
    return xObj;
}
Also used : XXService(org.apache.ranger.entity.XXService)

Example 60 with XXService

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

the class RangerServiceResourceServiceBase method mapEntityToViewBean.

@Override
protected V mapEntityToViewBean(V vObj, T xObj) {
    vObj.setGuid(xObj.getGuid());
    vObj.setVersion(xObj.getVersion());
    vObj.setIsEnabled(xObj.getIsEnabled());
    vObj.setResourceSignature(xObj.getResourceSignature());
    XXService xService = daoMgr.getXXService().getById(xObj.getServiceId());
    vObj.setServiceName(xService.getName());
    List<XXServiceResourceElement> resElementList = daoMgr.getXXServiceResourceElement().findByResourceId(xObj.getId());
    Map<String, RangerPolicy.RangerPolicyResource> resourceElements = new HashMap<String, RangerPolicy.RangerPolicyResource>();
    for (XXServiceResourceElement resElement : resElementList) {
        List<String> resValueMapList = daoMgr.getXXServiceResourceElementValue().findValuesByResElementId(resElement.getId());
        XXResourceDef xResDef = daoMgr.getXXResourceDef().getById(resElement.getResDefId());
        RangerPolicyResource policyRes = new RangerPolicyResource();
        policyRes.setIsExcludes(resElement.getIsExcludes());
        policyRes.setIsRecursive(resElement.getIsRecursive());
        policyRes.setValues(resValueMapList);
        resourceElements.put(xResDef.getName(), policyRes);
    }
    vObj.setResourceElements(resourceElements);
    return vObj;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) HashMap(java.util.HashMap) RangerPolicyResource(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource) XXService(org.apache.ranger.entity.XXService) XXResourceDef(org.apache.ranger.entity.XXResourceDef) XXServiceResourceElement(org.apache.ranger.entity.XXServiceResourceElement)

Aggregations

XXService (org.apache.ranger.entity.XXService)73 XXServiceDef (org.apache.ranger.entity.XXServiceDef)34 RangerService (org.apache.ranger.plugin.model.RangerService)23 Test (org.junit.Test)21 XXServiceDao (org.apache.ranger.db.XXServiceDao)19 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)19 VXString (org.apache.ranger.view.VXString)19 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)17 ArrayList (java.util.ArrayList)14 XXServiceVersionInfo (org.apache.ranger.entity.XXServiceVersionInfo)14 Date (java.util.Date)13 WebApplicationException (javax.ws.rs.WebApplicationException)11 IOException (java.io.IOException)9 ServiceTags (org.apache.ranger.plugin.util.ServiceTags)9 XXServiceVersionInfoDao (org.apache.ranger.db.XXServiceVersionInfoDao)7 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)7 UnknownHostException (java.net.UnknownHostException)6 XXServiceConfigMap (org.apache.ranger.entity.XXServiceConfigMap)6 JSONException (org.codehaus.jettison.json.JSONException)6 HashMap (java.util.HashMap)5