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;
}
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);
}
}
Aggregations