use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class ServiceDBStore method getPaginatedServicePolicies.
public PList<RangerPolicy> getPaginatedServicePolicies(Long serviceId, SearchFilter filter) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceDBStore.getPaginatedServicePolicies(" + serviceId + ")");
}
XXService service = daoMgr.getXXService().getById(serviceId);
if (service == null) {
throw new Exception("service does not exist - id='" + serviceId);
}
PList<RangerPolicy> ret = getPaginatedServicePolicies(service.getName(), filter);
if (LOG.isDebugEnabled()) {
LOG.debug("<== ServiceDBStore.getPaginatedServicePolicies(" + serviceId + ")");
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class ServiceDBStore method deleteService.
@Override
public void deleteService(Long id) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceDBStore.deleteService(" + id + ")");
}
RangerService service = getService(id);
if (service == null) {
throw new Exception("no service exists with ID=" + id);
}
List<XXPolicy> policies = daoMgr.getXXPolicy().findByServiceId(service.getId());
RangerPolicy rangerPolicy = null;
for (XXPolicy policy : policies) {
LOG.info("Deleting Policy, policyName: " + policy.getName());
rangerPolicy = getPolicy(policy.getId());
deletePolicy(rangerPolicy);
}
XXServiceConfigMapDao configDao = daoMgr.getXXServiceConfigMap();
List<XXServiceConfigMap> configs = configDao.findByServiceId(service.getId());
for (XXServiceConfigMap configMap : configs) {
configDao.remove(configMap);
}
Long version = service.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);
}
service.setVersion(version);
svcService.delete(service);
dataHistService.createObjectDataHistory(service, RangerDataHistService.ACTION_DELETE);
List<XXTrxLog> trxLogList = svcService.getTransactionLog(service, RangerServiceService.OPERATION_DELETE_CONTEXT);
bizUtil.createTrxLog(trxLogList);
}
use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class ServiceDBStore method createDefaultPolicies.
void createDefaultPolicies(RangerService createdService) throws Exception {
RangerBaseService svc = serviceMgr.getRangerServiceByService(createdService, this);
if (svc != null) {
List<String> serviceCheckUsers = getServiceCheckUsers(createdService);
List<RangerPolicy> defaultPolicies = svc.getDefaultRangerPolicies();
if (CollectionUtils.isNotEmpty(defaultPolicies)) {
createDefaultPolicyUsersAndGroups(defaultPolicies);
for (RangerPolicy defaultPolicy : defaultPolicies) {
if (CollectionUtils.isNotEmpty(serviceCheckUsers) && StringUtils.equalsIgnoreCase(defaultPolicy.getService(), createdService.getName())) {
RangerPolicyItem defaultAllowPolicyItem = CollectionUtils.isNotEmpty(defaultPolicy.getPolicyItems()) ? defaultPolicy.getPolicyItems().get(0) : null;
if (defaultAllowPolicyItem == null) {
LOG.error("There is no allow-policy-item in the default-policy:[" + defaultPolicy + "]");
} else {
RangerPolicy.RangerPolicyItem policyItem = new RangerPolicy.RangerPolicyItem();
policyItem.setUsers(serviceCheckUsers);
policyItem.setAccesses(defaultAllowPolicyItem.getAccesses());
policyItem.setDelegateAdmin(true);
defaultPolicy.getPolicyItems().add(policyItem);
}
}
boolean isPolicyItemValid = validatePolicyItems(defaultPolicy.getPolicyItems()) && validatePolicyItems(defaultPolicy.getDenyPolicyItems()) && validatePolicyItems(defaultPolicy.getAllowExceptions()) && validatePolicyItems(defaultPolicy.getDenyExceptions()) && validatePolicyItems(defaultPolicy.getDataMaskPolicyItems()) && validatePolicyItems(defaultPolicy.getRowFilterPolicyItems());
if (isPolicyItemValid) {
createPolicy(defaultPolicy);
} else {
LOG.warn("Default policy won't be created,since policyItems not valid-either users/groups not present or access not present in policy.");
}
}
}
}
}
use of org.apache.ranger.plugin.model.RangerPolicy 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);
}
use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class TestServiceDBStore method test31getPaginatedPolicies.
@Test
public void test31getPaginatedPolicies() throws Exception {
SearchFilter filter = new SearchFilter();
filter.setParam(SearchFilter.POLICY_NAME, "policyName");
filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
RangerPolicyList policyListObj = new RangerPolicyList();
policyListObj.setPageSize(0);
policyListObj.setResultSize(1);
policyListObj.setSortBy("asc");
policyListObj.setSortType("1");
policyListObj.setStartIndex(0);
policyListObj.setTotalCount(10);
PList<RangerPolicy> dbRangerPolicyList = serviceDBStore.getPaginatedPolicies(filter);
Assert.assertNotNull(dbRangerPolicyList);
}
Aggregations