use of org.apache.ranger.entity.XXResourceDef in project ranger by apache.
the class ServiceDBStore method deleteServiceDef.
public void deleteServiceDef(Long serviceDefId, Boolean forceDelete) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceDBStore.deleteServiceDef(" + serviceDefId + ", " + forceDelete + ")");
}
bizUtil.blockAuditorRoleUser();
UserSessionBase session = ContextUtil.getCurrentUserSession();
if (session == null) {
throw restErrorUtil.createRESTException("UserSession cannot be null, only Admin can update service-def", MessageEnums.OPER_NO_PERMISSION);
}
if (!session.isKeyAdmin() && !session.isUserAdmin()) {
throw restErrorUtil.createRESTException("User is not allowed to update service-def, only Admin can update service-def", MessageEnums.OPER_NO_PERMISSION);
}
RangerServiceDef serviceDef = getServiceDef(serviceDefId);
if (serviceDef == null) {
throw restErrorUtil.createRESTException("No Service Definiton found for Id: " + serviceDefId, MessageEnums.DATA_NOT_FOUND);
}
List<XXService> serviceList = daoMgr.getXXService().findByServiceDefId(serviceDefId);
if (!forceDelete) {
if (CollectionUtils.isNotEmpty(serviceList)) {
throw restErrorUtil.createRESTException("Services exists under given service definition, can't delete Service-Def: " + serviceDef.getName(), MessageEnums.OPER_NOT_ALLOWED_FOR_ENTITY);
}
}
XXDataMaskTypeDefDao dataMaskDao = daoMgr.getXXDataMaskTypeDef();
List<XXDataMaskTypeDef> dataMaskDefs = dataMaskDao.findByServiceDefId(serviceDefId);
for (XXDataMaskTypeDef dataMaskDef : dataMaskDefs) {
dataMaskDao.remove(dataMaskDef);
}
List<XXAccessTypeDef> accTypeDefs = daoMgr.getXXAccessTypeDef().findByServiceDefId(serviceDefId);
for (XXAccessTypeDef accessType : accTypeDefs) {
deleteXXAccessTypeDef(accessType);
}
XXContextEnricherDefDao xContextEnricherDao = daoMgr.getXXContextEnricherDef();
List<XXContextEnricherDef> contextEnrichers = xContextEnricherDao.findByServiceDefId(serviceDefId);
for (XXContextEnricherDef context : contextEnrichers) {
xContextEnricherDao.remove(context);
}
XXEnumDefDao enumDefDao = daoMgr.getXXEnumDef();
List<XXEnumDef> enumDefList = enumDefDao.findByServiceDefId(serviceDefId);
for (XXEnumDef enumDef : enumDefList) {
List<XXEnumElementDef> enumEleDefList = daoMgr.getXXEnumElementDef().findByEnumDefId(enumDef.getId());
for (XXEnumElementDef eleDef : enumEleDefList) {
daoMgr.getXXEnumElementDef().remove(eleDef);
}
enumDefDao.remove(enumDef);
}
XXPolicyConditionDefDao policyCondDao = daoMgr.getXXPolicyConditionDef();
List<XXPolicyConditionDef> policyCondList = policyCondDao.findByServiceDefId(serviceDefId);
for (XXPolicyConditionDef policyCond : policyCondList) {
List<XXPolicyItemCondition> policyItemCondList = daoMgr.getXXPolicyItemCondition().findByPolicyConditionDefId(policyCond.getId());
for (XXPolicyItemCondition policyItemCond : policyItemCondList) {
daoMgr.getXXPolicyItemCondition().remove(policyItemCond);
}
policyCondDao.remove(policyCond);
}
List<XXResourceDef> resDefList = daoMgr.getXXResourceDef().findByServiceDefId(serviceDefId);
for (XXResourceDef resDef : resDefList) {
deleteXXResourceDef(resDef);
}
XXServiceConfigDefDao configDefDao = daoMgr.getXXServiceConfigDef();
List<XXServiceConfigDef> configDefList = configDefDao.findByServiceDefId(serviceDefId);
for (XXServiceConfigDef configDef : configDefList) {
configDefDao.remove(configDef);
}
if (CollectionUtils.isNotEmpty(serviceList)) {
for (XXService service : serviceList) {
deleteService(service.getId());
}
}
Long version = serviceDef.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);
}
serviceDef.setVersion(version);
serviceDefService.delete(serviceDef);
LOG.info("ServiceDefinition has been deleted successfully. Service-Def Name: " + serviceDef.getName());
dataHistService.createObjectDataHistory(serviceDef, RangerDataHistService.ACTION_DELETE);
postDelete(serviceDef);
if (LOG.isDebugEnabled()) {
LOG.debug("<== ServiceDBStore.deleteServiceDef(" + serviceDefId + ", " + forceDelete + ")");
}
}
use of org.apache.ranger.entity.XXResourceDef in project ranger by apache.
the class ServiceDBStore method deleteXXResourceDef.
public void deleteXXResourceDef(XXResourceDef xRes) {
List<XXResourceDef> xChildObjs = daoMgr.getXXResourceDef().findByParentResId(xRes.getId());
for (XXResourceDef childRes : xChildObjs) {
deleteXXResourceDef(childRes);
}
List<XXPolicyResource> xxResources = daoMgr.getXXPolicyResource().findByResDefId(xRes.getId());
for (XXPolicyResource xPolRes : xxResources) {
deleteXXPolicyResource(xPolRes);
}
daoMgr.getXXResourceDef().remove(xRes);
}
use of org.apache.ranger.entity.XXResourceDef in project ranger by apache.
the class TagDBStore method createResourceForServiceResource.
private void createResourceForServiceResource(Long resourceId, RangerServiceResource serviceResource) {
String serviceName = serviceResource.getServiceName();
XXService xService = daoManager.getXXService().findByName(serviceName);
if (xService == null) {
throw errorUtil.createRESTException("No Service found with name: " + serviceName, MessageEnums.ERROR_CREATING_OBJECT);
}
XXServiceDef xServiceDef = daoManager.getXXServiceDef().getById(xService.getType());
if (xServiceDef == null) {
throw errorUtil.createRESTException("No Service-Def found with ID: " + xService.getType(), MessageEnums.ERROR_CREATING_OBJECT);
}
Map<String, RangerPolicy.RangerPolicyResource> resElements = serviceResource.getResourceElements();
for (Map.Entry<String, RangerPolicyResource> resElement : resElements.entrySet()) {
XXResourceDef xResDef = daoManager.getXXResourceDef().findByNameAndServiceDefId(resElement.getKey(), xServiceDef.getId());
if (xResDef == null) {
LOG.error("TagDBStore.createResource: ResourceType is not valid [" + resElement.getKey() + "]");
throw errorUtil.createRESTException("Resource Type is not valid [" + resElement.getKey() + "]", MessageEnums.DATA_NOT_FOUND);
}
RangerPolicyResource policyRes = resElement.getValue();
XXServiceResourceElement resourceElement = new XXServiceResourceElement();
resourceElement.setIsExcludes(policyRes.getIsExcludes());
resourceElement.setIsRecursive(policyRes.getIsRecursive());
resourceElement.setResDefId(xResDef.getId());
resourceElement.setResourceId(resourceId);
resourceElement = rangerAuditFields.populateAuditFieldsForCreate(resourceElement);
resourceElement = daoManager.getXXServiceResourceElement().create(resourceElement);
int sortOrder = 1;
for (String resVal : policyRes.getValues()) {
XXServiceResourceElementValue resourceElementValue = new XXServiceResourceElementValue();
resourceElementValue.setResElementId(resourceElement.getId());
resourceElementValue.setValue(resVal);
resourceElementValue.setSortOrder(sortOrder);
resourceElementValue = rangerAuditFields.populateAuditFieldsForCreate(resourceElementValue);
resourceElementValue = daoManager.getXXServiceResourceElementValue().create(resourceElementValue);
sortOrder++;
}
}
}
use of org.apache.ranger.entity.XXResourceDef in project ranger by apache.
the class TestRangerServiceDefServiceBase method test5populateRangerResourceDefToXX.
@Test
public void test5populateRangerResourceDefToXX() {
RangerResourceDef rangerResourceDefObj = new RangerResourceDef();
rangerResourceDefObj.setDescription("HDFS Repository");
rangerResourceDefObj.setExcludesSupported(false);
rangerResourceDefObj.setLabel("HDFS Repository");
rangerResourceDefObj.setName("HDFs");
XXResourceDef resourceDefObj = new XXResourceDef();
resourceDefObj.setAddedByUserId(Id);
resourceDefObj.setCreateTime(new Date());
resourceDefObj.setDefid(Id);
resourceDefObj.setDescription("HDFS Repository");
resourceDefObj.setId(Id);
XXServiceDef serviceDefObj = new XXServiceDef();
serviceDefObj.setAddedByUserId(Id);
serviceDefObj.setCreateTime(new Date());
serviceDefObj.setDescription("HDFS Repository");
serviceDefObj.setGuid("1427365526516_835_0");
serviceDefObj.setId(Id);
Mockito.when((XXResourceDef) rangerAuditFields.populateAuditFields(resourceDefObj, serviceDefObj)).thenReturn(resourceDefObj);
XXResourceDef dbResourceDef = rangerServiceDefService.populateRangerResourceDefToXX(rangerResourceDefObj, resourceDefObj, serviceDefObj, 1);
Assert.assertNotNull(dbResourceDef);
Assert.assertEquals(dbResourceDef, resourceDefObj);
Assert.assertEquals(dbResourceDef.getId(), resourceDefObj.getId());
Assert.assertEquals(dbResourceDef.getLabel(), resourceDefObj.getLabel());
Assert.assertEquals(dbResourceDef.getName(), resourceDefObj.getName());
Assert.assertEquals(dbResourceDef.getDescription(), resourceDefObj.getDescription());
}
use of org.apache.ranger.entity.XXResourceDef in project ranger by apache.
the class ServiceDBStore method createNewResourcesForPolicy.
private void createNewResourcesForPolicy(RangerPolicy policy, XXPolicy xPolicy, Map<String, RangerPolicyResource> resources) throws Exception {
for (Entry<String, RangerPolicyResource> resource : resources.entrySet()) {
RangerPolicyResource policyRes = resource.getValue();
XXResourceDef xResDef = daoMgr.getXXResourceDef().findByNameAndPolicyId(resource.getKey(), policy.getId());
if (xResDef == null) {
throw new Exception(resource.getKey() + ": is not a valid resource-type. policy='" + policy.getName() + "' service='" + policy.getService() + "'");
}
XXPolicyResource xPolRes = new XXPolicyResource();
xPolRes = rangerAuditFields.populateAuditFields(xPolRes, xPolicy);
xPolRes.setIsExcludes(policyRes.getIsExcludes());
xPolRes.setIsRecursive(policyRes.getIsRecursive());
xPolRes.setPolicyId(policy.getId());
xPolRes.setResDefId(xResDef.getId());
xPolRes = daoMgr.getXXPolicyResource().create(xPolRes);
List<String> values = policyRes.getValues();
if (CollectionUtils.isNotEmpty(values)) {
Set<String> uniqueValues = new LinkedHashSet<String>(values);
int i = 0;
if (CollectionUtils.isNotEmpty(uniqueValues)) {
for (String uniqValue : uniqueValues) {
if (!StringUtils.isEmpty(uniqValue)) {
XXPolicyResourceMap xPolResMap = new XXPolicyResourceMap();
xPolResMap = (XXPolicyResourceMap) rangerAuditFields.populateAuditFields(xPolResMap, xPolRes);
xPolResMap.setResourceId(xPolRes.getId());
xPolResMap.setValue(uniqValue);
xPolResMap.setOrder(i);
xPolResMap = daoMgr.getXXPolicyResourceMap().create(xPolResMap);
i++;
}
}
}
}
}
}
Aggregations