Search in sources :

Example 71 with RangerService

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

the class TestServiceDBStore method rangerService.

private RangerService rangerService() {
    Map<String, String> configs = new HashMap<String, String>();
    configs.put("username", "servicemgr");
    configs.put("password", "servicemgr");
    configs.put("namenode", "servicemgr");
    configs.put("hadoop.security.authorization", "No");
    configs.put("hadoop.security.authentication", "Simple");
    configs.put("hadoop.security.auth_to_local", "");
    configs.put("dfs.datanode.kerberos.principal", "");
    configs.put("dfs.namenode.kerberos.principal", "");
    configs.put("dfs.secondary.namenode.kerberos.principal", "");
    configs.put("hadoop.rpc.protection", "Privacy");
    configs.put("commonNameForCertificate", "");
    RangerService rangerService = new RangerService();
    rangerService.setId(Id);
    rangerService.setConfigs(configs);
    rangerService.setCreateTime(new Date());
    rangerService.setDescription("service policy");
    rangerService.setGuid("1427365526516_835_0");
    rangerService.setIsEnabled(true);
    rangerService.setName("HDFS_1");
    rangerService.setPolicyUpdateTime(new Date());
    rangerService.setType("1");
    rangerService.setUpdatedBy("Admin");
    rangerService.setUpdateTime(new Date());
    return rangerService;
}
Also used : HashMap(java.util.HashMap) VXString(org.apache.ranger.view.VXString) RangerService(org.apache.ranger.plugin.model.RangerService) Date(java.util.Date)

Example 72 with RangerService

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

the class TestServiceDBStore method tess29deletePolicy.

@Test
public void tess29deletePolicy() throws Exception {
    setup();
    XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
    XXService xService = Mockito.mock(XXService.class);
    XXServiceVersionInfoDao xServiceVersionInfoDao = Mockito.mock(XXServiceVersionInfoDao.class);
    XXServiceVersionInfo xServiceVersionInfo = Mockito.mock(XXServiceVersionInfo.class);
    XXPolicyLabelMapDao xPolicyLabelMapDao = Mockito.mock(XXPolicyLabelMapDao.class);
    XXPolicyItemDao xPolicyItemDao = Mockito.mock(XXPolicyItemDao.class);
    XXPolicyItemDataMaskInfoDao xPolicyItemDataMaskInfoDao = Mockito.mock(XXPolicyItemDataMaskInfoDao.class);
    XXPolicyItemRowFilterInfoDao xPolicyItemRowFilterInfoDao = Mockito.mock(XXPolicyItemRowFilterInfoDao.class);
    XXPolicyItemConditionDao xPolicyItemConditionDao = Mockito.mock(XXPolicyItemConditionDao.class);
    XXPolicyItemGroupPermDao xPolicyItemGroupPermDao = Mockito.mock(XXPolicyItemGroupPermDao.class);
    XXPolicyItemUserPermDao xPolicyItemUserPermDao = Mockito.mock(XXPolicyItemUserPermDao.class);
    XXPolicyItemAccessDao xPolicyItemAccessDao = Mockito.mock(XXPolicyItemAccessDao.class);
    XXPolicyResourceDao xPolicyResourceDao = Mockito.mock(XXPolicyResourceDao.class);
    XXPolicyResourceMapDao xPolicyResourceMapDao = Mockito.mock(XXPolicyResourceMapDao.class);
    RangerService rangerService = rangerService();
    RangerPolicy rangerPolicy = rangerPolicy();
    String name = "HDFS_1-1-20150316062453";
    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);
    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<XXPolicyItemGroupPerm> policyItemGroupPermList = new ArrayList<XXPolicyItemGroupPerm>();
    XXPolicyItemGroupPerm policyItemGroupPerm = new XXPolicyItemGroupPerm();
    policyItemGroupPerm.setAddedByUserId(Id);
    policyItemGroupPerm.setCreateTime(new Date());
    policyItemGroupPerm.setGroupId(Id);
    List<XXServiceConfigMap> xConfMapList = new ArrayList<XXServiceConfigMap>();
    XXServiceConfigMap xConfMap = new XXServiceConfigMap();
    xConfMap.setAddedByUserId(null);
    xConfMap.setConfigkey(name);
    xConfMap.setConfigvalue(name);
    xConfMap.setCreateTime(new Date());
    xConfMap.setServiceId(null);
    xConfMap.setId(Id);
    xConfMap.setUpdatedByUserId(null);
    xConfMap.setUpdateTime(new Date());
    xConfMapList.add(xConfMap);
    policyItemGroupPerm.setId(Id);
    policyItemGroupPerm.setOrder(1);
    policyItemGroupPerm.setPolicyItemId(Id);
    policyItemGroupPerm.setUpdatedByUserId(Id);
    policyItemGroupPerm.setUpdateTime(new Date());
    policyItemGroupPermList.add(policyItemGroupPerm);
    List<XXPolicyItemUserPerm> policyItemUserPermList = new ArrayList<XXPolicyItemUserPerm>();
    XXPolicyItemUserPerm policyItemUserPerm = new XXPolicyItemUserPerm();
    policyItemUserPerm.setAddedByUserId(Id);
    policyItemUserPerm.setCreateTime(new Date());
    policyItemUserPerm.setPolicyItemId(Id);
    policyItemUserPerm.setId(Id);
    policyItemUserPerm.setOrder(1);
    policyItemUserPerm.setUpdatedByUserId(Id);
    policyItemUserPerm.setUpdateTime(new Date());
    policyItemUserPermList.add(policyItemUserPerm);
    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<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<XXPolicyLabelMap> xxPolicyLabelMapList = new ArrayList<>();
    List<XXServiceConfigDef> xServiceConfigDefList = new ArrayList<XXServiceConfigDef>();
    XXServiceConfigDef serviceConfigDefObj = new XXServiceConfigDef();
    serviceConfigDefObj.setId(Id);
    xServiceConfigDefList.add(serviceConfigDefObj);
    Mockito.when(policyService.read(rangerPolicy.getId())).thenReturn(rangerPolicy);
    Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
    Mockito.when(xServiceDao.findByName(name)).thenReturn(xService);
    Mockito.when(svcService.getPopulatedViewObject(xService)).thenReturn(rangerService);
    Mockito.when(daoManager.getXXPolicyItem()).thenReturn(xPolicyItemDao);
    Mockito.when(xPolicyItemDao.findByPolicyId(policyItem.getId())).thenReturn(policyItemList);
    Mockito.when(daoManager.getXXPolicyItemDataMaskInfo()).thenReturn(xPolicyItemDataMaskInfoDao);
    Mockito.when(daoManager.getXXPolicyItemRowFilterInfo()).thenReturn(xPolicyItemRowFilterInfoDao);
    Mockito.when(daoManager.getXXPolicyItemCondition()).thenReturn(xPolicyItemConditionDao);
    Mockito.when(xPolicyItemConditionDao.findByPolicyItemId(policyItemCondition.getId())).thenReturn(policyItemConditionList);
    Mockito.when(daoManager.getXXPolicyItemGroupPerm()).thenReturn(xPolicyItemGroupPermDao);
    Mockito.when(xPolicyItemGroupPermDao.findByPolicyItemId(policyItem.getId())).thenReturn(policyItemGroupPermList);
    Mockito.when(daoManager.getXXPolicyItemUserPerm()).thenReturn(xPolicyItemUserPermDao);
    Mockito.when(xPolicyItemUserPermDao.findByPolicyItemId(Id)).thenReturn(policyItemUserPermList);
    Mockito.when(daoManager.getXXPolicyItemAccess()).thenReturn(xPolicyItemAccessDao);
    Mockito.when(xPolicyItemAccessDao.findByPolicyItemId(policyItemAccess.getId())).thenReturn(policyItemAccessList);
    Mockito.when(daoManager.getXXPolicyResource()).thenReturn(xPolicyResourceDao);
    Mockito.when(xPolicyResourceDao.findByPolicyId(policyResource.getId())).thenReturn(policyResourceList);
    Mockito.when(daoManager.getXXPolicyResourceMap()).thenReturn(xPolicyResourceMapDao);
    Mockito.when(xPolicyResourceMapDao.findByPolicyResId(policyResourceMap.getId())).thenReturn(policyResourceMapList);
    Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
    Mockito.when(xServiceDao.getById(Id)).thenReturn(xService);
    Mockito.when(daoManager.getXXServiceVersionInfo()).thenReturn(xServiceVersionInfoDao);
    Mockito.when(xServiceVersionInfoDao.findByServiceId(Id)).thenReturn(xServiceVersionInfo);
    Mockito.when(xServiceVersionInfoDao.update(xServiceVersionInfo)).thenReturn(xServiceVersionInfo);
    Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
    Mockito.when(xServiceDao.getById(rangerService.getId())).thenReturn(xService);
    Mockito.when(!bizUtil.hasAccess(xService, null)).thenReturn(true);
    Mockito.when(daoManager.getXXPolicyLabelMap()).thenReturn(xPolicyLabelMapDao);
    Mockito.when(xPolicyLabelMapDao.findByPolicyId(rangerPolicy.getId())).thenReturn(xxPolicyLabelMapList);
    serviceDBStore.deletePolicy(Id);
}
Also used : ArrayList(java.util.ArrayList) VXString(org.apache.ranger.view.VXString) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerService(org.apache.ranger.plugin.model.RangerService) Date(java.util.Date) Test(org.junit.Test)

Example 73 with RangerService

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

the class TestServiceDBStore method test40getPoliciesByResourceSignature.

@Test
public void test40getPoliciesByResourceSignature() throws Exception {
    List<RangerPolicy> rangerPolicyLists = new ArrayList<RangerPolicy>();
    RangerPolicy rangerPolicy = rangerPolicy();
    rangerPolicyLists.add(rangerPolicy);
    String serviceName = "HDFS_1";
    String policySignature = "Repo";
    Boolean isPolicyEnabled = true;
    RangerService rangerService = rangerService();
    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);
    XXPolicyDao xPolicyDao = Mockito.mock(XXPolicyDao.class);
    Mockito.when(daoManager.getXXPolicy()).thenReturn(xPolicyDao);
    Mockito.when(xPolicyDao.findByResourceSignatureByPolicyStatus(serviceName, policySignature, isPolicyEnabled)).thenReturn(policiesList);
    List<RangerPolicy> policyList = serviceDBStore.getPoliciesByResourceSignature(serviceName, policySignature, isPolicyEnabled);
    Assert.assertNotNull(policyList);
    Mockito.verify(daoManager).getXXPolicy();
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) ArrayList(java.util.ArrayList) VXString(org.apache.ranger.view.VXString) RangerService(org.apache.ranger.plugin.model.RangerService) Date(java.util.Date) Test(org.junit.Test)

Example 74 with RangerService

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

the class TestServiceDBStore method test25getPaginatedServiceDefs.

@Test
public void test25getPaginatedServiceDefs() throws Exception {
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.POLICY_NAME, "policyName");
    filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    List<RangerService> serviceList = new ArrayList<RangerService>();
    RangerService rangerService = rangerService();
    serviceList.add(rangerService);
    RangerServiceList serviceListObj = new RangerServiceList();
    serviceListObj.setPageSize(0);
    serviceListObj.setResultSize(1);
    serviceListObj.setSortBy("asc");
    serviceListObj.setSortType("1");
    serviceListObj.setStartIndex(0);
    serviceListObj.setTotalCount(10);
    serviceListObj.setServices(serviceList);
    Mockito.when(svcService.searchRangerServices(filter)).thenReturn(serviceListObj);
    PList<RangerService> dbServiceList = serviceDBStore.getPaginatedServices(filter);
    Assert.assertNotNull(dbServiceList);
    Assert.assertEquals(dbServiceList.getList(), serviceListObj.getServices());
    Mockito.verify(svcService).searchRangerServices(filter);
}
Also used : ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerServiceList(org.apache.ranger.view.RangerServiceList) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 75 with RangerService

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

the class TestServiceDBStore method tess26createPolicy.

@Test
public void tess26createPolicy() throws Exception {
    setup();
    XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
    XXPolicy xPolicy = Mockito.mock(XXPolicy.class);
    XXPolicyDao xPolicyDao = Mockito.mock(XXPolicyDao.class);
    XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
    XXServiceVersionInfoDao xServiceVersionInfoDao = Mockito.mock(XXServiceVersionInfoDao.class);
    XXService xService = Mockito.mock(XXService.class);
    XXServiceVersionInfo xServiceVersionInfo = Mockito.mock(XXServiceVersionInfo.class);
    XXPolicyItemDao xPolicyItemDao = Mockito.mock(XXPolicyItemDao.class);
    XXServiceDef xServiceDef = serviceDef();
    Map<String, String> configs = new HashMap<String, String>();
    configs.put("username", "servicemgr");
    configs.put("password", "servicemgr");
    configs.put("namenode", "servicemgr");
    configs.put("hadoop.security.authorization", "No");
    configs.put("hadoop.security.authentication", "Simple");
    configs.put("hadoop.security.auth_to_local", "");
    configs.put("dfs.datanode.kerberos.principal", "");
    configs.put("dfs.namenode.kerberos.principal", "");
    configs.put("dfs.secondary.namenode.kerberos.principal", "");
    configs.put("hadoop.rpc.protection", "Privacy");
    configs.put("commonNameForCertificate", "");
    RangerService rangerService = new RangerService();
    rangerService.setId(Id);
    rangerService.setConfigs(configs);
    rangerService.setCreateTime(new Date());
    rangerService.setDescription("service policy");
    rangerService.setGuid("1427365526516_835_0");
    rangerService.setIsEnabled(true);
    rangerService.setName("HDFS_1");
    rangerService.setPolicyUpdateTime(new Date());
    rangerService.setType("1");
    rangerService.setUpdatedBy("Admin");
    String policyName = "HDFS_1-1-20150316062345";
    String name = "HDFS_1-1-20150316062453";
    List<RangerPolicyItemAccess> accessesList = new ArrayList<RangerPolicyItemAccess>();
    RangerPolicyItemAccess policyItemAccess = new RangerPolicyItemAccess();
    policyItemAccess.setIsAllowed(true);
    policyItemAccess.setType("1");
    List<String> usersList = new ArrayList<String>();
    List<String> groupsList = new ArrayList<String>();
    List<String> policyLabels = new ArrayList<String>();
    List<RangerPolicyItemCondition> conditionsList = new ArrayList<RangerPolicyItemCondition>();
    RangerPolicyItemCondition policyItemCondition = new RangerPolicyItemCondition();
    policyItemCondition.setType("1");
    policyItemCondition.setValues(usersList);
    conditionsList.add(policyItemCondition);
    List<RangerPolicyItem> policyItems = new ArrayList<RangerPolicy.RangerPolicyItem>();
    RangerPolicyItem rangerPolicyItem = new RangerPolicyItem();
    rangerPolicyItem.setDelegateAdmin(false);
    rangerPolicyItem.setAccesses(accessesList);
    rangerPolicyItem.setConditions(conditionsList);
    rangerPolicyItem.setGroups(groupsList);
    rangerPolicyItem.setUsers(usersList);
    policyItems.add(rangerPolicyItem);
    List<RangerPolicyItem> policyItemsSet = new ArrayList<RangerPolicy.RangerPolicyItem>();
    RangerPolicyItem paramPolicyItem = new RangerPolicyItem(accessesList, usersList, groupsList, conditionsList, false);
    paramPolicyItem.setDelegateAdmin(false);
    paramPolicyItem.setAccesses(accessesList);
    paramPolicyItem.setConditions(conditionsList);
    paramPolicyItem.setGroups(groupsList);
    rangerPolicyItem.setUsers(usersList);
    policyItemsSet.add(paramPolicyItem);
    XXPolicyItem xPolicyItem = new XXPolicyItem();
    xPolicyItem.setDelegateAdmin(false);
    xPolicyItem.setAddedByUserId(null);
    xPolicyItem.setCreateTime(new Date());
    xPolicyItem.setGUID(null);
    xPolicyItem.setId(Id);
    xPolicyItem.setOrder(null);
    xPolicyItem.setPolicyId(Id);
    xPolicyItem.setUpdatedByUserId(null);
    xPolicyItem.setUpdateTime(new Date());
    XXPolicy xxPolicy = new XXPolicy();
    xxPolicy.setId(Id);
    xxPolicy.setName(name);
    xxPolicy.setAddedByUserId(Id);
    xxPolicy.setCreateTime(new Date());
    xxPolicy.setDescription("test");
    xxPolicy.setIsAuditEnabled(true);
    xxPolicy.setIsEnabled(true);
    xxPolicy.setService(1L);
    xxPolicy.setUpdatedByUserId(Id);
    xxPolicy.setUpdateTime(new Date());
    List<XXServiceConfigDef> xServiceConfigDefList = new ArrayList<XXServiceConfigDef>();
    XXServiceConfigDef serviceConfigDefObj = new XXServiceConfigDef();
    serviceConfigDefObj.setId(Id);
    xServiceConfigDefList.add(serviceConfigDefObj);
    List<XXServiceConfigMap> xConfMapList = new ArrayList<XXServiceConfigMap>();
    XXServiceConfigMap xConfMap = new XXServiceConfigMap();
    xConfMap.setAddedByUserId(null);
    xConfMap.setConfigkey(name);
    xConfMap.setConfigvalue(name);
    xConfMap.setCreateTime(new Date());
    xConfMap.setServiceId(null);
    xConfMap.setId(Id);
    xConfMap.setUpdatedByUserId(null);
    xConfMap.setUpdateTime(new Date());
    xConfMapList.add(xConfMap);
    List<String> users = new ArrayList<String>();
    RangerPolicyResource rangerPolicyResource = new RangerPolicyResource();
    rangerPolicyResource.setIsExcludes(true);
    rangerPolicyResource.setIsRecursive(true);
    rangerPolicyResource.setValue("1");
    rangerPolicyResource.setValues(users);
    Map<String, RangerPolicyResource> policyResource = new HashMap<String, RangerPolicyResource>();
    policyResource.put(name, rangerPolicyResource);
    policyResource.put(policyName, rangerPolicyResource);
    RangerPolicy rangerPolicy = new RangerPolicy();
    rangerPolicy.setId(Id);
    rangerPolicy.setCreateTime(new Date());
    rangerPolicy.setDescription("policy");
    rangerPolicy.setGuid("policyguid");
    rangerPolicy.setIsEnabled(true);
    rangerPolicy.setName("HDFS_1-1-20150316062453");
    rangerPolicy.setUpdatedBy("Admin");
    rangerPolicy.setUpdateTime(new Date());
    rangerPolicy.setService("HDFS_1-1-20150316062453");
    rangerPolicy.setIsAuditEnabled(true);
    rangerPolicy.setPolicyItems(policyItems);
    rangerPolicy.setResources(policyResource);
    rangerPolicy.setPolicyLabels(policyLabels);
    XXPolicyResource xPolicyResource = new XXPolicyResource();
    xPolicyResource.setAddedByUserId(Id);
    xPolicyResource.setCreateTime(new Date());
    xPolicyResource.setId(Id);
    xPolicyResource.setIsExcludes(true);
    xPolicyResource.setIsRecursive(true);
    xPolicyResource.setPolicyId(Id);
    xPolicyResource.setResDefId(Id);
    xPolicyResource.setUpdatedByUserId(Id);
    xPolicyResource.setUpdateTime(new Date());
    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);
    Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
    Mockito.when(xServiceDao.findByName(name)).thenReturn(xService);
    Mockito.when(daoManager.getXXServiceVersionInfo()).thenReturn(xServiceVersionInfoDao);
    Mockito.when(xServiceVersionInfoDao.findByServiceId(Id)).thenReturn(xServiceVersionInfo);
    Mockito.when(xServiceVersionInfoDao.update(xServiceVersionInfo)).thenReturn(xServiceVersionInfo);
    Mockito.when(svcService.getPopulatedViewObject(xService)).thenReturn(rangerService);
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
    Mockito.when(xServiceDefDao.findByName(rangerService.getType())).thenReturn(xServiceDef);
    Mockito.when(daoManager.getXXPolicy()).thenReturn(xPolicyDao);
    Mockito.when(policyService.create(rangerPolicy)).thenReturn(rangerPolicy);
    Mockito.when(daoManager.getXXPolicy()).thenReturn(xPolicyDao);
    Mockito.when(xPolicyDao.getById(Id)).thenReturn(xPolicy);
    Mockito.when(rangerAuditFields.populateAuditFields(Mockito.isA(XXPolicyItem.class), Mockito.isA(XXPolicy.class))).thenReturn(xPolicyItem);
    Mockito.when(daoManager.getXXPolicyItem()).thenReturn(xPolicyItemDao);
    Mockito.when(xPolicyItemDao.create(xPolicyItem)).thenReturn(xPolicyItem);
    Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
    Mockito.when(xServiceDao.getById(Id)).thenReturn(xService);
    Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
    Mockito.when(xServiceDao.getById(Id)).thenReturn(xService);
    RangerPolicyResourceSignature signature = Mockito.mock(RangerPolicyResourceSignature.class);
    Mockito.when(factory.createPolicyResourceSignature(rangerPolicy)).thenReturn(signature);
    XXResourceDefDao xResourceDefDao = Mockito.mock(XXResourceDefDao.class);
    XXResourceDef xResourceDef = Mockito.mock(XXResourceDef.class);
    XXPolicyResourceDao xPolicyResourceDao = Mockito.mock(XXPolicyResourceDao.class);
    XXPolicyConditionDefDao xPolicyConditionDefDao = Mockito.mock(XXPolicyConditionDefDao.class);
    Mockito.when(daoManager.getXXResourceDef()).thenReturn(xResourceDefDao);
    Mockito.when(xResourceDefDao.findByNameAndPolicyId(policyName, Id)).thenReturn(xResourceDef);
    Mockito.when(rangerAuditFields.populateAuditFields(Mockito.isA(XXPolicyResource.class), Mockito.isA(XXPolicy.class))).thenReturn(xPolicyResource);
    Mockito.when(daoManager.getXXPolicyResource()).thenReturn(xPolicyResourceDao);
    Mockito.when(xPolicyResourceDao.create(xPolicyResource)).thenReturn(xPolicyResource);
    Mockito.when(daoManager.getXXPolicyConditionDef()).thenReturn(xPolicyConditionDefDao);
    Mockito.when(xPolicyConditionDefDao.findByServiceDefIdAndName(Id, policyItemCondition.getType())).thenReturn(policyConditionDefObj);
    for (Entry<String, RangerPolicyResource> resource : policyResource.entrySet()) {
        Mockito.when(daoManager.getXXResourceDef()).thenReturn(xResourceDefDao);
        Mockito.when(xResourceDefDao.findByNameAndPolicyId(resource.getKey(), rangerPolicy.getId())).thenReturn(xResourceDef);
    }
    Mockito.when(daoManager.getXXPolicyConditionDef()).thenReturn(xPolicyConditionDefDao);
    Mockito.when(xPolicyConditionDefDao.findByServiceDefIdAndName(xServiceDef.getId(), policyItemCondition.getType())).thenReturn(policyConditionDefObj);
    Mockito.when(!bizUtil.hasAccess(xService, null)).thenReturn(true);
    RangerPolicy dbRangerPolicy = serviceDBStore.createPolicy(rangerPolicy);
    Assert.assertNull(dbRangerPolicy);
    Assert.assertEquals(Id, rangerPolicy.getId());
    Mockito.verify(daoManager).getXXServiceDef();
    Mockito.verify(policyService).create(rangerPolicy);
    Mockito.verify(rangerAuditFields).populateAuditFields(Mockito.isA(XXPolicyItem.class), Mockito.isA(XXPolicy.class));
    Mockito.verify(daoManager).getXXPolicyItem();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VXString(org.apache.ranger.view.VXString) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerPolicyResourceSignature(org.apache.ranger.plugin.model.RangerPolicyResourceSignature) RangerService(org.apache.ranger.plugin.model.RangerService) RangerPolicyResource(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource) RangerPolicyItem(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem) Date(java.util.Date) RangerPolicyItemAccess(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess) RangerPolicyItemCondition(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemCondition) Test(org.junit.Test)

Aggregations

RangerService (org.apache.ranger.plugin.model.RangerService)163 Test (org.junit.Test)85 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)52 ArrayList (java.util.ArrayList)39 WebApplicationException (javax.ws.rs.WebApplicationException)30 XXServiceDef (org.apache.ranger.entity.XXServiceDef)26 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)24 VXString (org.apache.ranger.view.VXString)24 XXService (org.apache.ranger.entity.XXService)23 Path (javax.ws.rs.Path)22 Produces (javax.ws.rs.Produces)21 Date (java.util.Date)20 HashMap (java.util.HashMap)16 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)16 HttpServletRequest (javax.servlet.http.HttpServletRequest)15 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)14 IOException (java.io.IOException)12 GET (javax.ws.rs.GET)12 XXTrxLog (org.apache.ranger.entity.XXTrxLog)12 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)12