use of org.apache.ranger.entity.XXPolicyResource in project ranger by apache.
the class ServiceDBStore method deleteExistingPolicyResources.
private Boolean deleteExistingPolicyResources(RangerPolicy policy) {
if (policy == null) {
return false;
}
List<XXPolicyResource> resources = daoMgr.getXXPolicyResource().findByPolicyId(policy.getId());
XXPolicyResourceDao resDao = daoMgr.getXXPolicyResource();
for (XXPolicyResource resource : resources) {
List<XXPolicyResourceMap> resMapList = daoMgr.getXXPolicyResourceMap().findByPolicyResId(resource.getId());
XXPolicyResourceMapDao resMapDao = daoMgr.getXXPolicyResourceMap();
for (XXPolicyResourceMap resMap : resMapList) {
resMapDao.remove(resMap);
}
resDao.remove(resource);
}
return true;
}
use of org.apache.ranger.entity.XXPolicyResource in project ranger by apache.
the class ServiceDBStore method deleteExistingPolicyResourcesNative.
private Boolean deleteExistingPolicyResourcesNative(RangerPolicy policy) {
if (policy == null) {
return false;
}
List<XXPolicyResource> resources = daoMgr.getXXPolicyResource().findByPolicyId(policy.getId());
for (XXPolicyResource resource : resources) {
daoMgr.getXXPolicyResourceMap().deletePolicyIDReference("resource_id", resource.getId());
daoMgr.getXXPolicyResource().deletePolicyIDReference("id", resource.getId());
}
return true;
}
use of org.apache.ranger.entity.XXPolicyResource in project ranger by apache.
the class PatchForAtlasResourceAndAccessTypeUpdate_J10016 method updatePolicyForRelationshipType.
private void updatePolicyForRelationshipType() {
logger.info("===> updatePolicyForRelationshipType ");
XXPortalUser xxPortalUser = daoMgr.getXXPortalUser().findByLoginId(LOGIN_ID_ADMIN);
Long currentUserId = xxPortalUser.getId();
XXServiceDef xXServiceDefObj = daoMgr.getXXServiceDef().findByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME);
if (xXServiceDefObj == null) {
logger.debug("xXServiceDefObj not found with name : " + EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME);
return;
}
Long xServiceDefId = xXServiceDefObj.getId();
XXResourceDef xxResourceDef = daoMgr.getXXResourceDef().findByNameAndServiceDefId(RESOURCE_DEF_NAME, xServiceDefId);
List<XXPolicyResource> policyResources = daoMgr.getXXPolicyResource().findByResDefId(xxResourceDef.getId());
for (XXPolicyResource xxPolicyResource : policyResources) {
XXPolicy xxPolicy = daoMgr.getXXPolicy().getById(xxPolicyResource.getPolicyid());
List<XXPolicyItem> xxPolicyItems = daoMgr.getXXPolicyItem().findByPolicyId(xxPolicy.getId());
for (XXPolicyItem xxPolicyItem : xxPolicyItems) {
XXGroup xxGroup = daoMgr.getXXGroup().findByGroupName(GROUP_PUBLIC);
if (xxGroup == null) {
logger.error("Group name 'public' not found in database");
return;
}
Long publicGroupId = xxGroup.getId();
XXPolicyItemGroupPerm xxPolicyItemGroupPerm = new XXPolicyItemGroupPerm();
xxPolicyItemGroupPerm.setPolicyItemId(xxPolicyItem.getId());
xxPolicyItemGroupPerm.setGroupId(publicGroupId);
xxPolicyItemGroupPerm.setOrder(0);
xxPolicyItemGroupPerm.setAddedByUserId(currentUserId);
xxPolicyItemGroupPerm.setUpdatedByUserId(currentUserId);
daoMgr.getXXPolicyItemGroupPerm().create(xxPolicyItemGroupPerm);
}
}
logger.info("<=== updatePolicyForRelationshipType ");
}
use of org.apache.ranger.entity.XXPolicyResource 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++;
}
}
}
}
}
}
use of org.apache.ranger.entity.XXPolicyResource in project ranger by apache.
the class PatchForNifiResourceUpdateExclude_J10011 method updateNifiServiceDef.
private void updateNifiServiceDef() {
RangerServiceDef ret = null;
RangerServiceDef dbNifiServiceDef = null;
try {
dbNifiServiceDef = svcDBStore.getServiceDefByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_NIFI_NAME);
if (dbNifiServiceDef != null) {
List<RangerResourceDef> rRDefList = null;
rRDefList = dbNifiServiceDef.getResources();
if (CollectionUtils.isNotEmpty(rRDefList)) {
for (RangerResourceDef rRDef : rRDefList) {
if (rRDef.getExcludesSupported()) {
rRDef.setExcludesSupported(false);
}
XXResourceDef sdf = daoMgr.getXXResourceDef().findByNameAndServiceDefId(rRDef.getName(), dbNifiServiceDef.getId());
long ResourceDefId = sdf.getId();
List<XXPolicyResource> RangerPolicyResourceList = daoMgr.getXXPolicyResource().findByResDefId(ResourceDefId);
if (CollectionUtils.isNotEmpty(RangerPolicyResourceList)) {
for (XXPolicyResource RangerPolicyResource : RangerPolicyResourceList) {
if (RangerPolicyResource.getIsexcludes()) {
RangerPolicy rPolicy = svcDBStore.getPolicy(RangerPolicyResource.getPolicyid());
rPolicy.setIsEnabled(false);
svcStore.updatePolicy(rPolicy);
}
}
}
}
}
RangerServiceDefValidator validator = validatorFactory.getServiceDefValidator(svcStore);
validator.validate(dbNifiServiceDef, Action.UPDATE);
ret = svcStore.updateServiceDef(dbNifiServiceDef);
}
if (ret == null) {
logger.error("Error while updating " + EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_NIFI_NAME + "service-def");
}
} catch (Exception e) {
logger.error("Error while updating " + EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_NIFI_NAME + "service-def", e);
}
}
Aggregations