use of org.apache.ranger.plugin.model.RangerService 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();
}
use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.
the class RangerServiceService method getAllServices.
public List<RangerService> getAllServices() {
List<XXService> xxServiceList = daoMgr.getXXService().getAll();
List<RangerService> serviceList = new ArrayList<RangerService>();
for (XXService xxService : xxServiceList) {
RangerService service = populateViewBean(xxService);
serviceList.add(service);
}
return serviceList;
}
use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.
the class RangerServiceWithAssignedIdService method populateViewBean.
@Override
protected RangerService populateViewBean(XXServiceWithAssignedId xService) {
RangerService vService = super.populateViewBean(xService);
HashMap<String, String> configs = new HashMap<String, String>();
List<XXServiceConfigMap> svcConfigMapList = daoMgr.getXXServiceConfigMap().findByServiceId(xService.getId());
for (XXServiceConfigMap svcConfMap : svcConfigMapList) {
configs.put(svcConfMap.getConfigkey(), svcConfMap.getConfigvalue());
}
vService.setConfigs(configs);
return vService;
}
use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.
the class RangerAdminTagEnricher method init.
@Override
public void init() {
if (LOG.isDebugEnabled()) {
LOG.debug("==> RangerAdminTagEnricher.init()");
}
super.init();
ServiceStore svcStore = tagStore != null ? tagStore.getServiceStore() : null;
if (tagStore == null || svcStore == null) {
LOG.error("ServiceDBStore/TagDBStore is not initialized!! Internal Error!");
} else {
try {
RangerService service = svcStore.getServiceByName(serviceName);
serviceId = service.getId();
} catch (Exception e) {
LOG.error("Cannot find service with name:[" + serviceName + "]", e);
LOG.error("This will cause tag-enricher in Ranger-Admin to fail!!");
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== RangerAdminTagEnricher.init()");
}
}
use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.
the class ServiceUtil method rangerPolicyListToPublic.
public VXPolicyList rangerPolicyListToPublic(List<RangerPolicy> rangerPolicyList, SearchFilter filter) {
RangerService service = null;
List<VXPolicy> vXPolicyList = new ArrayList<VXPolicy>();
VXPolicyList vXPolicyListObj = new VXPolicyList(new ArrayList<VXPolicy>());
if (CollectionUtils.isNotEmpty(rangerPolicyList)) {
int totalCount = rangerPolicyList.size();
int startIndex = filter.getStartIndex();
int pageSize = filter.getMaxRows();
int toIndex = Math.min(startIndex + pageSize, totalCount);
String sortType = filter.getSortType();
String sortBy = filter.getSortBy();
for (int i = startIndex; i < toIndex; i++) {
RangerPolicy policy = rangerPolicyList.get(i);
try {
service = svcStore.getServiceByName(policy.getService());
} catch (Exception excp) {
throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(), true);
}
if (service == null) {
throw restErrorUtil.createRESTException(HttpServletResponse.SC_NOT_FOUND, RangerServiceNotFoundException.buildExceptionMsg(policy.getService()), true);
}
VXPolicy vXPolicy = toVXPolicy(policy, service);
if (vXPolicy != null) {
vXPolicyList.add(vXPolicy);
}
}
vXPolicyListObj = new VXPolicyList(vXPolicyList);
vXPolicyListObj.setPageSize(pageSize);
vXPolicyListObj.setResultSize(vXPolicyList.size());
vXPolicyListObj.setStartIndex(startIndex);
vXPolicyListObj.setTotalCount(totalCount);
vXPolicyListObj.setSortBy(sortBy);
vXPolicyListObj.setSortType(sortType);
}
return vXPolicyListObj;
}
Aggregations