Search in sources :

Example 11 with XXResourceDef

use of org.apache.ranger.entity.XXResourceDef in project ranger by apache.

the class PatchForAtlasServiceDefUpdate_J10013 method checkIfHasOlderServiceDef.

/*
	 * This method shall check whether atlas service def resources and access types
	 * are matching with older service def resources and access types or not.
	 * returns true if all resources and access types matches with older service def
	 * resources and access types.
	 */
private boolean checkIfHasOlderServiceDef(XXServiceDef serviceDef) {
    boolean result = true;
    Set<String> atlasResources = new HashSet<>(Arrays.asList("entity", "type", "operation", "taxonomy", "term"));
    XXResourceDefDao resourceDefDao = daoMgr.getXXResourceDef();
    List<XXResourceDef> xxResourceDefs = resourceDefDao.findByServiceDefId(serviceDef.getId());
    for (XXResourceDef xxResourceDef : xxResourceDefs) {
        if (!atlasResources.contains(xxResourceDef.getName())) {
            result = false;
            break;
        }
    }
    if (result) {
        Set<String> atlasAccessTypes = new HashSet<>(Arrays.asList("read", "create", "update", "delete", "all"));
        XXAccessTypeDefDao accessTypeDefDao = daoMgr.getXXAccessTypeDef();
        List<XXAccessTypeDef> xxAccessTypeDefs = accessTypeDefDao.findByServiceDefId(serviceDef.getId());
        for (XXAccessTypeDef xxAccessTypeDef : xxAccessTypeDefs) {
            if (!atlasAccessTypes.contains(xxAccessTypeDef.getName())) {
                result = false;
                break;
            }
        }
    }
    return result;
}
Also used : XXResourceDefDao(org.apache.ranger.db.XXResourceDefDao) XXAccessTypeDef(org.apache.ranger.entity.XXAccessTypeDef) XXAccessTypeDefDao(org.apache.ranger.db.XXAccessTypeDefDao) XXResourceDef(org.apache.ranger.entity.XXResourceDef) HashSet(java.util.HashSet)

Example 12 with XXResourceDef

use of org.apache.ranger.entity.XXResourceDef 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

XXResourceDef (org.apache.ranger.entity.XXResourceDef)12 RangerResourceDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef)5 XXResourceDefDao (org.apache.ranger.db.XXResourceDefDao)4 XXAccessTypeDef (org.apache.ranger.entity.XXAccessTypeDef)4 XXPolicyResource (org.apache.ranger.entity.XXPolicyResource)4 XXAccessTypeDefDao (org.apache.ranger.db.XXAccessTypeDefDao)3 XXContextEnricherDefDao (org.apache.ranger.db.XXContextEnricherDefDao)3 XXDataMaskTypeDefDao (org.apache.ranger.db.XXDataMaskTypeDefDao)3 XXEnumDefDao (org.apache.ranger.db.XXEnumDefDao)3 XXPolicyConditionDefDao (org.apache.ranger.db.XXPolicyConditionDefDao)3 XXServiceConfigDefDao (org.apache.ranger.db.XXServiceConfigDefDao)3 XXContextEnricherDef (org.apache.ranger.entity.XXContextEnricherDef)3 XXDataMaskTypeDef (org.apache.ranger.entity.XXDataMaskTypeDef)3 XXEnumDef (org.apache.ranger.entity.XXEnumDef)3 XXEnumElementDef (org.apache.ranger.entity.XXEnumElementDef)3 XXPolicyConditionDef (org.apache.ranger.entity.XXPolicyConditionDef)3 XXServiceConfigDef (org.apache.ranger.entity.XXServiceConfigDef)3 RangerPolicyResource (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)3 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)3 VXString (org.apache.ranger.view.VXString)3