Search in sources :

Example 1 with XXPolicyResource

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;
}
Also used : XXPolicyResource(org.apache.ranger.entity.XXPolicyResource) XXPolicyResourceDao(org.apache.ranger.db.XXPolicyResourceDao) XXPolicyResourceMap(org.apache.ranger.entity.XXPolicyResourceMap) XXPolicyResourceMapDao(org.apache.ranger.db.XXPolicyResourceMapDao)

Example 2 with XXPolicyResource

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;
}
Also used : XXPolicyResource(org.apache.ranger.entity.XXPolicyResource)

Example 3 with XXPolicyResource

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 ");
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXPolicyItemGroupPerm(org.apache.ranger.entity.XXPolicyItemGroupPerm) XXPolicyItem(org.apache.ranger.entity.XXPolicyItem) XXGroup(org.apache.ranger.entity.XXGroup) XXPolicyResource(org.apache.ranger.entity.XXPolicyResource) XXPolicy(org.apache.ranger.entity.XXPolicy) XXResourceDef(org.apache.ranger.entity.XXResourceDef)

Example 4 with XXPolicyResource

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++;
                    }
                }
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) XXPolicyResource(org.apache.ranger.entity.XXPolicyResource) RangerPolicyResource(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource) XXPolicyResourceMap(org.apache.ranger.entity.XXPolicyResourceMap) VXString(org.apache.ranger.view.VXString) XXResourceDef(org.apache.ranger.entity.XXResourceDef) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) JSONException(org.codehaus.jettison.json.JSONException)

Example 5 with XXPolicyResource

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);
    }
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXPolicyResource(org.apache.ranger.entity.XXPolicyResource) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) XXResourceDef(org.apache.ranger.entity.XXResourceDef) RangerServiceDefValidator(org.apache.ranger.plugin.model.validation.RangerServiceDefValidator) RangerResourceDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef)

Aggregations

XXPolicyResource (org.apache.ranger.entity.XXPolicyResource)7 XXResourceDef (org.apache.ranger.entity.XXResourceDef)5 XXPolicyResourceMap (org.apache.ranger.entity.XXPolicyResourceMap)4 XXPolicy (org.apache.ranger.entity.XXPolicy)3 XXPolicyItem (org.apache.ranger.entity.XXPolicyItem)3 XXPortalUser (org.apache.ranger.entity.XXPortalUser)3 XXServiceDef (org.apache.ranger.entity.XXServiceDef)3 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)3 XXAccessTypeDef (org.apache.ranger.entity.XXAccessTypeDef)2 XXGroup (org.apache.ranger.entity.XXGroup)2 XXPolicyItemAccess (org.apache.ranger.entity.XXPolicyItemAccess)2 XXPolicyItemGroupPerm (org.apache.ranger.entity.XXPolicyItemGroupPerm)2 XXService (org.apache.ranger.entity.XXService)2 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 LinkedHashSet (java.util.LinkedHashSet)1 XXPolicyResourceDao (org.apache.ranger.db.XXPolicyResourceDao)1 XXPolicyResourceMapDao (org.apache.ranger.db.XXPolicyResourceMapDao)1 XXPolicyItemUserPerm (org.apache.ranger.entity.XXPolicyItemUserPerm)1 XXUser (org.apache.ranger.entity.XXUser)1