Search in sources :

Example 41 with RangerServiceDef

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

the class ServiceREST method validateResourcePoliciesRequest.

private String validateResourcePoliciesRequest(String serviceDefName, String serviceName, HttpServletRequest request, List<RangerService> services, Map<String, Object> resource) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceREST.validatePoliciesForResourceRequest(service-type=" + serviceDefName + ", service-name=" + serviceName + ")");
    }
    final String ret;
    if (MapUtils.isNotEmpty(request.getParameterMap())) {
        for (Map.Entry<String, String[]> e : request.getParameterMap().entrySet()) {
            String name = e.getKey();
            String[] values = e.getValue();
            if (!StringUtils.isEmpty(name) && !ArrayUtils.isEmpty(values) && name.startsWith(SearchFilter.RESOURCE_PREFIX)) {
                resource.put(name.substring(SearchFilter.RESOURCE_PREFIX.length()), values[0]);
            }
        }
    }
    if (MapUtils.isEmpty(resource)) {
        ret = "No resource specified";
    } else {
        RangerServiceDef serviceDef = null;
        try {
            serviceDef = svcStore.getServiceDefByName(serviceDefName);
        } catch (Exception e) {
            LOG.error("Invalid service-type:[" + serviceDefName + "]", e);
        }
        if (serviceDef == null) {
            ret = "Invalid service-type:[" + serviceDefName + "]";
        } else {
            Set<String> resourceDefNames = resource.keySet();
            RangerServiceDefHelper serviceDefHelper = new RangerServiceDefHelper(serviceDef);
            Set<List<RangerServiceDef.RangerResourceDef>> resourceHierarchies = serviceDefHelper.getResourceHierarchies(RangerPolicy.POLICY_TYPE_ACCESS, resourceDefNames);
            if (CollectionUtils.isEmpty(resourceHierarchies)) {
                ret = "Invalid resource specified: resource-names:" + resourceDefNames + " are not part of any valid resource hierarchy for service-type:[" + serviceDefName + "]";
            } else {
                if (StringUtils.isNotBlank(serviceName)) {
                    RangerService service = null;
                    try {
                        service = svcStore.getServiceByName(serviceName);
                    } catch (Exception e) {
                        LOG.error("Invalid service-name:[" + serviceName + "]");
                    }
                    if (service == null || !StringUtils.equals(service.getType(), serviceDefName)) {
                        ret = "Invalid service-name:[" + serviceName + "] or service-name is not of service-type:[" + serviceDefName + "]";
                    } else {
                        services.add(service);
                        ret = StringUtils.EMPTY;
                    }
                } else {
                    SearchFilter filter = new SearchFilter();
                    filter.setParam(SearchFilter.SERVICE_TYPE, serviceDefName);
                    List<RangerService> serviceList = null;
                    try {
                        serviceList = svcStore.getServices(filter);
                    } catch (Exception e) {
                        LOG.error("Cannot find service of service-type:[" + serviceDefName + "]");
                    }
                    if (CollectionUtils.isEmpty(serviceList) || serviceList.size() != 1) {
                        ret = "Either 0 or more than 1 services found for service-type :[" + serviceDefName + "]";
                    } else {
                        services.add(serviceList.get(0));
                        ret = StringUtils.EMPTY;
                    }
                }
            }
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== ServiceREST.validatePoliciesForResourceRequest(service-type=" + serviceDefName + ", service-name=" + serviceName + ") : " + ret);
    }
    return ret;
}
Also used : SearchFilter(org.apache.ranger.plugin.util.SearchFilter) VXString(org.apache.ranger.view.VXString) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) JsonSyntaxException(com.google.gson.JsonSyntaxException) RangerServiceDefHelper(org.apache.ranger.plugin.model.validation.RangerServiceDefHelper) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) RangerPluginInfoList(org.apache.ranger.view.RangerPluginInfoList) RangerServiceList(org.apache.ranger.view.RangerServiceList) ArrayList(java.util.ArrayList) VXPolicyLabelList(org.apache.ranger.view.VXPolicyLabelList) List(java.util.List) RangerExportPolicyList(org.apache.ranger.view.RangerExportPolicyList) RangerPolicyList(org.apache.ranger.view.RangerPolicyList) RangerServiceDefList(org.apache.ranger.view.RangerServiceDefList) RangerAPIList(org.apache.ranger.security.context.RangerAPIList) PList(org.apache.ranger.plugin.store.PList) RangerService(org.apache.ranger.plugin.model.RangerService) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Example 42 with RangerServiceDef

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

the class TestServiceDBStore method test12updateServiceDef.

@Test
public void test12updateServiceDef() throws Exception {
    setup();
    XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
    XXServiceDef xServiceDef = Mockito.mock(XXServiceDef.class);
    XXServiceConfigDefDao xServiceConfigDefDao = Mockito.mock(XXServiceConfigDefDao.class);
    XXResourceDefDao xResourceDefDao = Mockito.mock(XXResourceDefDao.class);
    XXAccessTypeDefDao xAccessTypeDefDao = Mockito.mock(XXAccessTypeDefDao.class);
    XXPolicyConditionDefDao xPolicyConditionDefDao = Mockito.mock(XXPolicyConditionDefDao.class);
    XXContextEnricherDefDao xContextEnricherDefDao = Mockito.mock(XXContextEnricherDefDao.class);
    XXEnumDefDao xEnumDefDao = Mockito.mock(XXEnumDefDao.class);
    XXDataMaskTypeDefDao xDataMaskDefDao = Mockito.mock(XXDataMaskTypeDefDao.class);
    XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
    RangerServiceDef rangerServiceDef = rangerServiceDef();
    Long serviceDefId = rangerServiceDef.getId();
    List<XXServiceConfigDef> svcConfDefList = new ArrayList<XXServiceConfigDef>();
    XXServiceConfigDef serviceConfigDefObj = new XXServiceConfigDef();
    serviceConfigDefObj.setId(Id);
    serviceConfigDefObj.setType("1");
    svcConfDefList.add(serviceConfigDefObj);
    Mockito.when(serviceDefService.populateRangerServiceConfigDefToXX(Mockito.any(RangerServiceConfigDef.class), Mockito.any(XXServiceConfigDef.class), Mockito.any(XXServiceDef.class), Mockito.eq(RangerServiceDefService.OPERATION_CREATE_CONTEXT))).thenReturn(serviceConfigDefObj);
    Mockito.when(xServiceConfigDefDao.create(serviceConfigDefObj)).thenReturn(serviceConfigDefObj);
    List<XXResourceDef> resDefList = new ArrayList<XXResourceDef>();
    XXResourceDef resourceDef = new XXResourceDef();
    resourceDef.setAddedByUserId(Id);
    resourceDef.setCreateTime(new Date());
    resourceDef.setDefid(Id);
    resourceDef.setDescription("test");
    resourceDef.setId(Id);
    resDefList.add(resourceDef);
    List<XXAccessTypeDef> accessTypeDefList = new ArrayList<XXAccessTypeDef>();
    XXAccessTypeDef accessTypeDefObj = new XXAccessTypeDef();
    accessTypeDefObj.setAddedByUserId(Id);
    accessTypeDefObj.setCreateTime(new Date());
    accessTypeDefObj.setDefid(Id);
    accessTypeDefObj.setId(Id);
    accessTypeDefObj.setLabel("Read");
    accessTypeDefObj.setName("read");
    accessTypeDefObj.setOrder(null);
    accessTypeDefObj.setRbkeylabel(null);
    accessTypeDefObj.setUpdatedByUserId(Id);
    accessTypeDefObj.setUpdateTime(new Date());
    accessTypeDefList.add(accessTypeDefObj);
    List<XXPolicyConditionDef> policyConditionDefList = new ArrayList<XXPolicyConditionDef>();
    XXPolicyConditionDef policyConditionDefObj = new XXPolicyConditionDef();
    policyConditionDefObj.setAddedByUserId(Id);
    policyConditionDefObj.setCreateTime(new Date());
    policyConditionDefObj.setDefid(Id);
    policyConditionDefObj.setDescription("policy");
    policyConditionDefObj.setId(Id);
    policyConditionDefObj.setName("country");
    policyConditionDefObj.setOrder(0);
    policyConditionDefObj.setUpdatedByUserId(Id);
    policyConditionDefObj.setUpdateTime(new Date());
    policyConditionDefList.add(policyConditionDefObj);
    List<XXContextEnricherDef> contextEnricherDefList = new ArrayList<XXContextEnricherDef>();
    XXContextEnricherDef contextEnricherDefObj = new XXContextEnricherDef();
    contextEnricherDefObj.setAddedByUserId(Id);
    contextEnricherDefObj.setCreateTime(new Date());
    contextEnricherDefObj.setDefid(Id);
    contextEnricherDefObj.setId(Id);
    contextEnricherDefObj.setName("country-provider");
    contextEnricherDefObj.setEnricherOptions("contextName=COUNTRY;dataFile=/etc/ranger/data/userCountry.properties");
    contextEnricherDefObj.setEnricher("RangerCountryProvider");
    contextEnricherDefObj.setOrder(null);
    contextEnricherDefObj.setUpdatedByUserId(Id);
    contextEnricherDefObj.setUpdateTime(new Date());
    contextEnricherDefList.add(contextEnricherDefObj);
    List<XXEnumDef> enumDefList = new ArrayList<XXEnumDef>();
    XXEnumDef enumDefObj = new XXEnumDef();
    enumDefObj.setAddedByUserId(Id);
    enumDefObj.setCreateTime(new Date());
    enumDefObj.setDefaultindex(0);
    enumDefObj.setDefid(Id);
    enumDefObj.setId(Id);
    enumDefObj.setName("authnType");
    enumDefObj.setUpdatedByUserId(Id);
    enumDefObj.setUpdateTime(new Date());
    enumDefList.add(enumDefObj);
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
    Mockito.when(xServiceDefDao.getById(serviceDefId)).thenReturn(xServiceDef);
    Mockito.when(daoManager.getXXServiceConfigDef()).thenReturn(xServiceConfigDefDao);
    Mockito.when(daoManager.getXXResourceDef()).thenReturn(xResourceDefDao);
    Mockito.when(daoManager.getXXAccessTypeDef()).thenReturn(xAccessTypeDefDao);
    Mockito.when(daoManager.getXXPolicyConditionDef()).thenReturn(xPolicyConditionDefDao);
    Mockito.when(daoManager.getXXContextEnricherDef()).thenReturn(xContextEnricherDefDao);
    Mockito.when(daoManager.getXXEnumDef()).thenReturn(xEnumDefDao);
    Mockito.when(daoManager.getXXDataMaskTypeDef()).thenReturn(xDataMaskDefDao);
    Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
    Mockito.when(xServiceDao.findByServiceDefId(serviceDefId)).thenReturn(null);
    Mockito.when(serviceDefService.read(Id)).thenReturn(rangerServiceDef);
    RangerServiceDef dbServiceDef = serviceDBStore.updateServiceDef(rangerServiceDef);
    Assert.assertNotNull(dbServiceDef);
    Assert.assertEquals(dbServiceDef, rangerServiceDef);
    Assert.assertEquals(dbServiceDef.getId(), rangerServiceDef.getId());
    Assert.assertEquals(dbServiceDef.getCreatedBy(), rangerServiceDef.getCreatedBy());
    Assert.assertEquals(dbServiceDef.getDescription(), rangerServiceDef.getDescription());
    Assert.assertEquals(dbServiceDef.getGuid(), rangerServiceDef.getGuid());
    Assert.assertEquals(dbServiceDef.getImplClass(), rangerServiceDef.getImplClass());
    Assert.assertEquals(dbServiceDef.getLabel(), rangerServiceDef.getLabel());
    Assert.assertEquals(dbServiceDef.getName(), rangerServiceDef.getName());
    Assert.assertEquals(dbServiceDef.getRbKeyDescription(), rangerServiceDef.getRbKeyDescription());
    Assert.assertEquals(dbServiceDef.getConfigs(), rangerServiceDef.getConfigs());
    Assert.assertEquals(dbServiceDef.getVersion(), rangerServiceDef.getVersion());
    Assert.assertEquals(dbServiceDef.getResources(), rangerServiceDef.getResources());
}
Also used : ArrayList(java.util.ArrayList) RangerServiceConfigDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef) Date(java.util.Date) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) Test(org.junit.Test)

Example 43 with RangerServiceDef

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

the class TestServiceDBStore method test11createServiceDef.

@Test
public void test11createServiceDef() throws Exception {
    XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
    XXResourceDefDao xResourceDefDao = Mockito.mock(XXResourceDefDao.class);
    XXServiceConfigDefDao xServiceConfigDefDao = Mockito.mock(XXServiceConfigDefDao.class);
    XXAccessTypeDefDao xAccessTypeDefDao = Mockito.mock(XXAccessTypeDefDao.class);
    XXPolicyConditionDefDao xPolicyConditionDefDao = Mockito.mock(XXPolicyConditionDefDao.class);
    XXContextEnricherDefDao xContextEnricherDefDao = Mockito.mock(XXContextEnricherDefDao.class);
    XXEnumDefDao xEnumDefDao = Mockito.mock(XXEnumDefDao.class);
    XXServiceDef xServiceDef = Mockito.mock(XXServiceDef.class);
    XXResourceDef xResourceDef = Mockito.mock(XXResourceDef.class);
    XXAccessTypeDef xAccessTypeDef = Mockito.mock(XXAccessTypeDef.class);
    List<XXAccessTypeDef> xAccessTypeDefs = new ArrayList<XXAccessTypeDef>();
    xAccessTypeDefs.add(xAccessTypeDef);
    List<XXResourceDef> xResourceDefs = new ArrayList<XXResourceDef>();
    xResourceDefs.add(xResourceDef);
    RangerServiceDef serviceDef = new RangerServiceDef();
    Mockito.when(serviceDefService.create(serviceDef)).thenReturn(serviceDef);
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
    Mockito.when(xServiceDefDao.getById(null)).thenReturn(xServiceDef);
    Mockito.when(daoManager.getXXServiceConfigDef()).thenReturn(xServiceConfigDefDao);
    Mockito.when(daoManager.getXXResourceDef()).thenReturn(xResourceDefDao);
    Mockito.when(xResourceDefDao.findByServiceDefId(xServiceDef.getId())).thenReturn(xResourceDefs);
    Mockito.when(daoManager.getXXAccessTypeDef()).thenReturn(xAccessTypeDefDao);
    Mockito.when(xAccessTypeDefDao.findByServiceDefId(xServiceDef.getId())).thenReturn(xAccessTypeDefs);
    Mockito.when(daoManager.getXXPolicyConditionDef()).thenReturn(xPolicyConditionDefDao);
    Mockito.when(daoManager.getXXContextEnricherDef()).thenReturn(xContextEnricherDefDao);
    Mockito.when(daoManager.getXXEnumDef()).thenReturn(xEnumDefDao);
    Mockito.when(serviceDefService.getPopulatedViewObject(xServiceDef)).thenReturn(serviceDef);
    RangerServiceDef dbServiceDef = serviceDBStore.createServiceDef(serviceDef);
    Assert.assertNotNull(dbServiceDef);
    Assert.assertEquals(dbServiceDef, serviceDef);
    Assert.assertEquals(dbServiceDef.getId(), serviceDef.getId());
    Assert.assertEquals(dbServiceDef.getCreatedBy(), serviceDef.getCreatedBy());
    Assert.assertEquals(dbServiceDef.getDescription(), serviceDef.getDescription());
    Assert.assertEquals(dbServiceDef.getGuid(), serviceDef.getGuid());
    Assert.assertEquals(dbServiceDef.getImplClass(), serviceDef.getImplClass());
    Assert.assertEquals(dbServiceDef.getLabel(), serviceDef.getLabel());
    Assert.assertEquals(dbServiceDef.getName(), serviceDef.getName());
    Assert.assertEquals(dbServiceDef.getRbKeyDescription(), serviceDef.getRbKeyDescription());
    Assert.assertEquals(dbServiceDef.getRbKeyLabel(), serviceDef.getLabel());
    Assert.assertEquals(dbServiceDef.getConfigs(), serviceDef.getConfigs());
    Assert.assertEquals(dbServiceDef.getVersion(), serviceDef.getVersion());
    Assert.assertEquals(dbServiceDef.getResources(), serviceDef.getResources());
    Mockito.verify(serviceDefService).getPopulatedViewObject(xServiceDef);
    Mockito.verify(serviceDefService).create(serviceDef);
    Mockito.verify(daoManager).getXXServiceConfigDef();
    Mockito.verify(daoManager).getXXEnumDef();
    Mockito.verify(daoManager).getXXAccessTypeDef();
}
Also used : ArrayList(java.util.ArrayList) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) Test(org.junit.Test)

Example 44 with RangerServiceDef

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

the class TestServiceDBStore method test13deleteServiceDef.

@Test
public void test13deleteServiceDef() throws Exception {
    XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
    XXDataMaskTypeDefDao xDataMaskDefDao = Mockito.mock(XXDataMaskTypeDefDao.class);
    XXAccessTypeDefDao xAccessTypeDefDao = Mockito.mock(XXAccessTypeDefDao.class);
    XXAccessTypeDefGrantsDao xAccessTypeDefGrantsDao = Mockito.mock(XXAccessTypeDefGrantsDao.class);
    XXPolicyItemAccessDao xPolicyItemAccessDao = Mockito.mock(XXPolicyItemAccessDao.class);
    XXContextEnricherDefDao xContextEnricherDefDao = Mockito.mock(XXContextEnricherDefDao.class);
    XXEnumDefDao xEnumDefDao = Mockito.mock(XXEnumDefDao.class);
    XXEnumElementDefDao xEnumElementDefDao = Mockito.mock(XXEnumElementDefDao.class);
    XXPolicyConditionDefDao xPolicyConditionDefDao = Mockito.mock(XXPolicyConditionDefDao.class);
    XXPolicyItemConditionDao xPolicyItemConditionDao = Mockito.mock(XXPolicyItemConditionDao.class);
    XXResourceDefDao xResourceDefDao = Mockito.mock(XXResourceDefDao.class);
    XXPolicyResourceDao xPolicyResourceDao = Mockito.mock(XXPolicyResourceDao.class);
    XXPolicyResourceMapDao xPolicyResourceMapDao = Mockito.mock(XXPolicyResourceMapDao.class);
    XXServiceConfigDefDao xServiceConfigDefDao = Mockito.mock(XXServiceConfigDefDao.class);
    RangerServiceDef rangerServiceDef = rangerServiceDef();
    RangerService rangerService = rangerService();
    String name = "fdfdfds";
    Long serviceDefId = rangerServiceDef.getId();
    List<XXService> xServiceList = new ArrayList<XXService>();
    XXService xService = new XXService();
    xService.setAddedByUserId(Id);
    xService.setCreateTime(new Date());
    xService.setDescription("Hdfs service");
    xService.setGuid("serviceguid");
    xService.setId(Id);
    xService.setIsEnabled(true);
    xService.setName("Hdfs");
    xService.setPolicyUpdateTime(new Date());
    xService.setPolicyVersion(1L);
    xService.setType(1L);
    xService.setUpdatedByUserId(Id);
    xService.setUpdateTime(new Date());
    xServiceList.add(xService);
    List<XXAccessTypeDef> accessTypeDefList = new ArrayList<XXAccessTypeDef>();
    XXAccessTypeDef accessTypeDefObj = new XXAccessTypeDef();
    accessTypeDefObj.setAddedByUserId(Id);
    accessTypeDefObj.setCreateTime(new Date());
    accessTypeDefObj.setDefid(Id);
    accessTypeDefObj.setId(Id);
    accessTypeDefObj.setLabel("Read");
    accessTypeDefObj.setName("read");
    accessTypeDefObj.setOrder(null);
    accessTypeDefObj.setRbkeylabel(null);
    accessTypeDefObj.setUpdatedByUserId(Id);
    accessTypeDefObj.setUpdateTime(new Date());
    accessTypeDefList.add(accessTypeDefObj);
    List<XXAccessTypeDefGrants> accessTypeDefGrantslist = new ArrayList<XXAccessTypeDefGrants>();
    XXAccessTypeDefGrants accessTypeDefGrantsObj = new XXAccessTypeDefGrants();
    accessTypeDefGrantsObj.setAddedByUserId(Id);
    accessTypeDefGrantsObj.setAtdId(Id);
    accessTypeDefGrantsObj.setCreateTime(new Date());
    accessTypeDefGrantsObj.setId(Id);
    accessTypeDefGrantsObj.setUpdatedByUserId(Id);
    accessTypeDefGrantsObj.setUpdateTime(new Date());
    accessTypeDefGrantsObj.setImpliedGrant("read");
    accessTypeDefGrantslist.add(accessTypeDefGrantsObj);
    List<XXPolicyItemAccess> policyItemAccessList = new ArrayList<XXPolicyItemAccess>();
    XXPolicyItemAccess policyItemAccess = new XXPolicyItemAccess();
    policyItemAccess.setAddedByUserId(Id);
    policyItemAccess.setCreateTime(new Date());
    policyItemAccess.setPolicyitemid(Id);
    policyItemAccess.setId(Id);
    policyItemAccess.setOrder(1);
    policyItemAccess.setUpdatedByUserId(Id);
    policyItemAccess.setUpdateTime(new Date());
    policyItemAccessList.add(policyItemAccess);
    List<XXContextEnricherDef> contextEnricherDefList = new ArrayList<XXContextEnricherDef>();
    XXContextEnricherDef contextEnricherDefObj = new XXContextEnricherDef();
    contextEnricherDefObj.setAddedByUserId(Id);
    contextEnricherDefObj.setCreateTime(new Date());
    contextEnricherDefObj.setDefid(Id);
    contextEnricherDefObj.setId(Id);
    contextEnricherDefObj.setName("country-provider");
    contextEnricherDefObj.setEnricherOptions("contextName=COUNTRY;dataFile=/etc/ranger/data/userCountry.properties");
    contextEnricherDefObj.setEnricher("RangerCountryProvider");
    contextEnricherDefObj.setOrder(null);
    contextEnricherDefObj.setUpdatedByUserId(Id);
    contextEnricherDefObj.setUpdateTime(new Date());
    contextEnricherDefList.add(contextEnricherDefObj);
    List<XXEnumDef> enumDefList = new ArrayList<XXEnumDef>();
    XXEnumDef enumDefObj = new XXEnumDef();
    enumDefObj.setAddedByUserId(Id);
    enumDefObj.setCreateTime(new Date());
    enumDefObj.setDefaultindex(0);
    enumDefObj.setDefid(Id);
    enumDefObj.setId(Id);
    enumDefObj.setName("authnType");
    enumDefObj.setUpdatedByUserId(Id);
    enumDefObj.setUpdateTime(new Date());
    enumDefList.add(enumDefObj);
    List<XXEnumElementDef> xElementsList = new ArrayList<XXEnumElementDef>();
    XXEnumElementDef enumElementDefObj = new XXEnumElementDef();
    enumElementDefObj.setAddedByUserId(Id);
    enumElementDefObj.setCreateTime(new Date());
    enumElementDefObj.setEnumdefid(Id);
    enumElementDefObj.setId(Id);
    enumElementDefObj.setLabel("Authentication");
    enumElementDefObj.setName("authentication");
    enumElementDefObj.setUpdateTime(new Date());
    enumElementDefObj.setUpdatedByUserId(Id);
    enumElementDefObj.setRbkeylabel(null);
    enumElementDefObj.setOrder(0);
    xElementsList.add(enumElementDefObj);
    List<XXPolicyConditionDef> xConditionDefList = new ArrayList<XXPolicyConditionDef>();
    XXPolicyConditionDef policyConditionDefObj = new XXPolicyConditionDef();
    policyConditionDefObj.setAddedByUserId(Id);
    policyConditionDefObj.setCreateTime(new Date());
    policyConditionDefObj.setDefid(Id);
    policyConditionDefObj.setDescription("policy conditio");
    policyConditionDefObj.setId(Id);
    policyConditionDefObj.setName(name);
    policyConditionDefObj.setOrder(1);
    policyConditionDefObj.setLabel("label");
    xConditionDefList.add(policyConditionDefObj);
    List<XXPolicyItemCondition> policyItemConditionList = new ArrayList<XXPolicyItemCondition>();
    XXPolicyItemCondition policyItemCondition = new XXPolicyItemCondition();
    policyItemCondition.setAddedByUserId(Id);
    policyItemCondition.setCreateTime(new Date());
    policyItemCondition.setType(1L);
    policyItemCondition.setId(Id);
    policyItemCondition.setOrder(1);
    policyItemCondition.setPolicyItemId(Id);
    policyItemCondition.setUpdatedByUserId(Id);
    policyItemCondition.setUpdateTime(new Date());
    policyItemConditionList.add(policyItemCondition);
    List<XXResourceDef> resDefList = new ArrayList<XXResourceDef>();
    XXResourceDef resourceDef = new XXResourceDef();
    resourceDef.setAddedByUserId(Id);
    resourceDef.setCreateTime(new Date());
    resourceDef.setDefid(Id);
    resourceDef.setDescription("test");
    resourceDef.setId(Id);
    resDefList.add(resourceDef);
    List<XXPolicyResource> policyResourceList = new ArrayList<XXPolicyResource>();
    XXPolicyResource policyResource = new XXPolicyResource();
    policyResource.setId(Id);
    policyResource.setCreateTime(new Date());
    policyResource.setAddedByUserId(Id);
    policyResource.setIsExcludes(false);
    policyResource.setIsRecursive(false);
    policyResource.setPolicyId(Id);
    policyResource.setResDefId(Id);
    policyResource.setUpdatedByUserId(Id);
    policyResource.setUpdateTime(new Date());
    policyResourceList.add(policyResource);
    List<XXPolicyResourceMap> policyResourceMapList = new ArrayList<XXPolicyResourceMap>();
    XXPolicyResourceMap policyResourceMap = new XXPolicyResourceMap();
    policyResourceMap.setAddedByUserId(Id);
    policyResourceMap.setCreateTime(new Date());
    policyResourceMap.setId(Id);
    policyResourceMap.setOrder(1);
    policyResourceMap.setResourceId(Id);
    policyResourceMap.setUpdatedByUserId(Id);
    policyResourceMap.setUpdateTime(new Date());
    policyResourceMap.setValue("1L");
    policyResourceMapList.add(policyResourceMap);
    List<XXServiceConfigDef> serviceConfigDefList = new ArrayList<XXServiceConfigDef>();
    XXServiceConfigDef serviceConfigDefObj = new XXServiceConfigDef();
    serviceConfigDefObj.setAddedByUserId(Id);
    serviceConfigDefObj.setCreateTime(new Date());
    serviceConfigDefObj.setDefaultvalue("simple");
    serviceConfigDefObj.setDescription("service config");
    serviceConfigDefObj.setId(Id);
    serviceConfigDefObj.setIsMandatory(true);
    serviceConfigDefObj.setName(name);
    serviceConfigDefObj.setLabel("username");
    serviceConfigDefObj.setRbkeydescription(null);
    serviceConfigDefObj.setRbkeylabel(null);
    serviceConfigDefObj.setRbKeyValidationMessage(null);
    serviceConfigDefObj.setType("password");
    serviceConfigDefList.add(serviceConfigDefObj);
    List<XXPolicy> policiesList = new ArrayList<XXPolicy>();
    XXPolicy policy = new XXPolicy();
    policy.setAddedByUserId(Id);
    policy.setCreateTime(new Date());
    policy.setDescription("polcy test");
    policy.setGuid("");
    policy.setId(rangerService.getId());
    policy.setIsAuditEnabled(true);
    policy.setName("HDFS_1-1-20150316062453");
    policy.setService(rangerService.getId());
    policiesList.add(policy);
    List<XXPolicyItem> policyItemList = new ArrayList<XXPolicyItem>();
    XXPolicyItem policyItem = new XXPolicyItem();
    policyItem.setAddedByUserId(Id);
    policyItem.setCreateTime(new Date());
    policyItem.setDelegateAdmin(false);
    policyItem.setId(Id);
    policyItem.setOrder(1);
    policyItem.setPolicyId(Id);
    policyItem.setUpdatedByUserId(Id);
    policyItem.setUpdateTime(new Date());
    policyItemList.add(policyItem);
    XXServiceConfigMap xConfMap = new XXServiceConfigMap();
    xConfMap.setAddedByUserId(null);
    xConfMap.setConfigkey(name);
    xConfMap.setConfigvalue(name);
    xConfMap.setCreateTime(new Date());
    xConfMap.setServiceId(Id);
    List<XXPolicyItemGroupPerm> policyItemGroupPermlist = new ArrayList<XXPolicyItemGroupPerm>();
    XXPolicyItemGroupPerm policyItemGroupPermObj = new XXPolicyItemGroupPerm();
    policyItemGroupPermObj.setAddedByUserId(Id);
    policyItemGroupPermObj.setCreateTime(new Date());
    policyItemGroupPermObj.setGroupId(Id);
    policyItemGroupPermObj.setId(Id);
    policyItemGroupPermObj.setOrder(1);
    policyItemGroupPermObj.setPolicyItemId(Id);
    policyItemGroupPermObj.setUpdatedByUserId(Id);
    policyItemGroupPermObj.setUpdateTime(new Date());
    policyItemGroupPermlist.add(policyItemGroupPermObj);
    List<XXPolicyItemUserPerm> policyItemUserPermList = new ArrayList<XXPolicyItemUserPerm>();
    XXPolicyItemUserPerm policyItemUserPermObj = new XXPolicyItemUserPerm();
    policyItemUserPermObj.setAddedByUserId(Id);
    policyItemUserPermObj.setCreateTime(new Date());
    policyItemUserPermObj.setId(Id);
    policyItemUserPermObj.setOrder(1);
    policyItemUserPermObj.setPolicyItemId(Id);
    policyItemUserPermObj.setUpdatedByUserId(serviceDefId);
    policyItemUserPermObj.setUpdateTime(new Date());
    policyItemUserPermObj.setUserId(Id);
    policyItemUserPermList.add(policyItemUserPermObj);
    XXUser xUser = new XXUser();
    xUser.setAddedByUserId(Id);
    xUser.setCreateTime(new Date());
    xUser.setCredStoreId(Id);
    xUser.setDescription("user test");
    xUser.setId(Id);
    xUser.setIsVisible(null);
    xUser.setName(name);
    xUser.setStatus(0);
    xUser.setUpdatedByUserId(Id);
    xUser.setUpdateTime(new Date());
    Mockito.when(serviceDefService.read(Id)).thenReturn(rangerServiceDef);
    Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
    Mockito.when(xServiceDao.findByServiceDefId(serviceDefId)).thenReturn(null);
    // xServiceList);
    Mockito.when(daoManager.getXXAccessTypeDef()).thenReturn(xAccessTypeDefDao);
    Mockito.when(xAccessTypeDefDao.findByServiceDefId(serviceDefId)).thenReturn(accessTypeDefList);
    Mockito.when(daoManager.getXXAccessTypeDefGrants()).thenReturn(xAccessTypeDefGrantsDao);
    Mockito.when(xAccessTypeDefGrantsDao.findByATDId(accessTypeDefObj.getId())).thenReturn(accessTypeDefGrantslist);
    Mockito.when(daoManager.getXXPolicyItemAccess()).thenReturn(xPolicyItemAccessDao);
    Mockito.when(xPolicyItemAccessDao.findByType(accessTypeDefObj.getId())).thenReturn(policyItemAccessList);
    Mockito.when(daoManager.getXXContextEnricherDef()).thenReturn(xContextEnricherDefDao);
    Mockito.when(xContextEnricherDefDao.findByServiceDefId(serviceDefId)).thenReturn(contextEnricherDefList);
    Mockito.when(daoManager.getXXEnumDef()).thenReturn(xEnumDefDao);
    Mockito.when(xEnumDefDao.findByServiceDefId(serviceDefId)).thenReturn(enumDefList);
    Mockito.when(daoManager.getXXEnumElementDef()).thenReturn(xEnumElementDefDao);
    Mockito.when(xEnumElementDefDao.findByEnumDefId(enumDefObj.getId())).thenReturn(xElementsList);
    Mockito.when(daoManager.getXXPolicyConditionDef()).thenReturn(xPolicyConditionDefDao);
    Mockito.when(xPolicyConditionDefDao.findByServiceDefId(serviceDefId)).thenReturn(xConditionDefList);
    Mockito.when(daoManager.getXXPolicyItemCondition()).thenReturn(xPolicyItemConditionDao);
    Mockito.when(xPolicyItemConditionDao.findByPolicyConditionDefId(policyConditionDefObj.getId())).thenReturn(policyItemConditionList);
    Mockito.when(daoManager.getXXResourceDef()).thenReturn(xResourceDefDao);
    Mockito.when(xResourceDefDao.findByServiceDefId(serviceDefId)).thenReturn(resDefList);
    Mockito.when(daoManager.getXXPolicyResource()).thenReturn(xPolicyResourceDao);
    Mockito.when(xPolicyResourceDao.findByResDefId(resourceDef.getId())).thenReturn(policyResourceList);
    Mockito.when(daoManager.getXXPolicyResourceMap()).thenReturn(xPolicyResourceMapDao);
    Mockito.when(xPolicyResourceMapDao.findByPolicyResId(policyResource.getId())).thenReturn(policyResourceMapList);
    Mockito.when(daoManager.getXXServiceConfigDef()).thenReturn(xServiceConfigDefDao);
    Mockito.when(xServiceConfigDefDao.findByServiceDefId(serviceDefId)).thenReturn(serviceConfigDefList);
    Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
    svcServiceWithAssignedId.setPopulateExistingBaseFields(true);
    Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
    Mockito.when(xServiceDao.findByServiceDefId(serviceDefId)).thenReturn(null);
    Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
    Mockito.when(daoManager.getXXDataMaskTypeDef()).thenReturn(xDataMaskDefDao);
    Mockito.when(xDataMaskDefDao.findByServiceDefId(serviceDefId)).thenReturn(new ArrayList<XXDataMaskTypeDef>());
    serviceDBStore.deleteServiceDef(Id, true);
    Mockito.verify(daoManager).getXXContextEnricherDef();
    Mockito.verify(daoManager).getXXEnumDef();
}
Also used : ArrayList(java.util.ArrayList) VXString(org.apache.ranger.view.VXString) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) RangerService(org.apache.ranger.plugin.model.RangerService) Date(java.util.Date) Test(org.junit.Test)

Example 45 with RangerServiceDef

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

the class TestServiceDBStore method rangerServiceDef.

private RangerServiceDef rangerServiceDef() {
    List<RangerServiceConfigDef> configs = new ArrayList<RangerServiceConfigDef>();
    RangerServiceConfigDef serviceConfigDefObj = new RangerServiceConfigDef();
    serviceConfigDefObj.setDefaultValue("xyz");
    serviceConfigDefObj.setDescription("ServiceDef");
    serviceConfigDefObj.setItemId(Id);
    serviceConfigDefObj.setLabel("Username");
    serviceConfigDefObj.setMandatory(true);
    serviceConfigDefObj.setName("username");
    serviceConfigDefObj.setRbKeyDescription(null);
    serviceConfigDefObj.setRbKeyLabel(null);
    serviceConfigDefObj.setRbKeyValidationMessage(null);
    serviceConfigDefObj.setSubType(null);
    configs.add(serviceConfigDefObj);
    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.setName("RangerServiceHdfs");
    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