use of org.apache.ranger.plugin.model.validation.RangerServiceDefValidator in project ranger by apache.
the class ServiceREST method deleteServiceDef.
@DELETE
@Path("/definitions/{id}")
@Produces({ "application/json", "application/xml" })
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.DELETE_SERVICE_DEF + "\")")
public void deleteServiceDef(@PathParam("id") Long id, @Context HttpServletRequest request) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceREST.deleteServiceDef(" + id + ")");
}
RangerPerfTracer perf = null;
try {
if (RangerPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = RangerPerfTracer.getPerfTracer(PERF_LOG, "ServiceREST.deleteServiceDef(serviceDefId=" + id + ")");
}
RangerServiceDefValidator validator = validatorFactory.getServiceDefValidator(svcStore);
validator.validate(id, Action.DELETE);
bizUtil.hasAdminPermissions("Service-Def");
XXServiceDef xServiceDef = daoManager.getXXServiceDef().getById(id);
if (xServiceDef != null) {
bizUtil.hasKMSPermissions("Service-Def", xServiceDef.getImplclassname());
String forceDeleteStr = request.getParameter("forceDelete");
boolean forceDelete = false;
if (!StringUtils.isEmpty(forceDeleteStr) && "true".equalsIgnoreCase(forceDeleteStr)) {
forceDelete = true;
}
svcStore.deleteServiceDef(id, forceDelete);
} else {
LOG.error("Cannot retrieve service-definition:[" + id + "] for deletion");
throw new Exception("deleteServiceDef(" + id + ") failed");
}
} catch (WebApplicationException excp) {
throw excp;
} catch (Throwable excp) {
LOG.error("deleteServiceDef(" + id + ") failed", excp);
throw restErrorUtil.createRESTException(excp.getMessage());
} finally {
RangerPerfTracer.log(perf);
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== ServiceREST.deleteServiceDef(" + id + ")");
}
}
use of org.apache.ranger.plugin.model.validation.RangerServiceDefValidator in project ranger by apache.
the class ServiceREST method createServiceDef.
@POST
@Path("/definitions")
@Produces({ "application/json", "application/xml" })
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.CREATE_SERVICE_DEF + "\")")
public RangerServiceDef createServiceDef(RangerServiceDef serviceDef) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceREST.createServiceDef(" + serviceDef + ")");
}
RangerServiceDef ret = null;
RangerPerfTracer perf = null;
/**
* If display name is blank (EMPTY String or NULL), use name.
*/
if (StringUtils.isBlank(serviceDef.getDisplayName())) {
serviceDef.setDisplayName(serviceDef.getName());
}
try {
if (RangerPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = RangerPerfTracer.getPerfTracer(PERF_LOG, "ServiceREST.createServiceDef(serviceDefName=" + serviceDef.getName() + ")");
}
RangerServiceDefValidator validator = validatorFactory.getServiceDefValidator(svcStore);
validator.validate(serviceDef, Action.CREATE);
bizUtil.hasAdminPermissions("Service-Def");
bizUtil.hasKMSPermissions("Service-Def", serviceDef.getImplClass());
bizUtil.blockAuditorRoleUser();
ret = svcStore.createServiceDef(serviceDef);
} catch (WebApplicationException excp) {
throw excp;
} catch (Throwable excp) {
LOG.error("createServiceDef(" + serviceDef + ") failed", excp);
throw restErrorUtil.createRESTException(excp.getMessage());
} finally {
RangerPerfTracer.log(perf);
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== ServiceREST.createServiceDef(" + serviceDef + "): " + ret);
}
return ret;
}
use of org.apache.ranger.plugin.model.validation.RangerServiceDefValidator 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);
}
}
use of org.apache.ranger.plugin.model.validation.RangerServiceDefValidator in project ranger by apache.
the class PatchAtlasForClassificationResource_J10047 method addResourceClassificationsInServiceDef.
private void addResourceClassificationsInServiceDef() throws Exception {
RangerServiceDef ret = null;
RangerServiceDef embeddedAtlasServiceDef = null;
XXServiceDef xXServiceDefObj = null;
RangerServiceDef dbAtlasServiceDef = null;
embeddedAtlasServiceDef = EmbeddedServiceDefsUtil.instance().getEmbeddedServiceDef(EMBEDDED_SERVICEDEF_ATLAS_NAME);
if (embeddedAtlasServiceDef != null) {
xXServiceDefObj = daoMgr.getXXServiceDef().findByName(EMBEDDED_SERVICEDEF_ATLAS_NAME);
if (xXServiceDefObj == null) {
logger.info(" service-def for " + EMBEDDED_SERVICEDEF_ATLAS_NAME + " not found. No patching is needed");
return;
}
dbAtlasServiceDef = svcDBStore.getServiceDefByName(EMBEDDED_SERVICEDEF_ATLAS_NAME);
updateResourceInServiceDef(embeddedAtlasServiceDef, dbAtlasServiceDef);
updateTypeResourceWithIgnoreCase(dbAtlasServiceDef.getResources());
removeEntityResourceAccessTypeRestrictions(dbAtlasServiceDef.getResources());
RangerServiceDefValidator validator = validatorFactory.getServiceDefValidator(svcStore);
validator.validate(dbAtlasServiceDef, RangerValidator.Action.UPDATE);
ret = svcStore.updateServiceDef(dbAtlasServiceDef);
if (ret == null) {
logger.error("Error while updating " + EMBEDDED_SERVICEDEF_ATLAS_NAME + " service-def");
throw new RuntimeException("Error while updating " + EMBEDDED_SERVICEDEF_ATLAS_NAME + " service-def");
}
}
}
use of org.apache.ranger.plugin.model.validation.RangerServiceDefValidator in project ranger by apache.
the class PatchForTagServiceDefUpdate_J10008 method updateTagServiceDef.
private void updateTagServiceDef() {
RangerServiceDef embeddedTagServiceDef = null;
RangerServiceDef dbTagServiceDef = null;
List<RangerServiceDef.RangerPolicyConditionDef> embeddedTagPolicyConditionDefs = null;
XXServiceDef xXServiceDefObj = null;
try {
embeddedTagServiceDef = EmbeddedServiceDefsUtil.instance().getEmbeddedServiceDef(SERVICEDBSTORE_SERVICEDEFBYNAME_TAG_NAME);
if (embeddedTagServiceDef != null) {
embeddedTagPolicyConditionDefs = embeddedTagServiceDef.getPolicyConditions();
if (embeddedTagPolicyConditionDefs == null) {
logger.error("Policy Conditions are empyt in tag service def json");
return;
}
if (checkScriptPolicyCondPresent(embeddedTagPolicyConditionDefs) == false) {
logger.error(SCRIPT_POLICY_CONDITION_NAME + "policy condition not found!!");
return;
}
xXServiceDefObj = daoMgr.getXXServiceDef().findByName(SERVICEDBSTORE_SERVICEDEFBYNAME_TAG_NAME);
if (xXServiceDefObj == null) {
logger.error("Service def for " + SERVICEDBSTORE_SERVICEDEFBYNAME_TAG_NAME + " is not found!!");
return;
}
Map<String, String> serviceDefOptionsPreUpdate = null;
String jsonStrPreUpdate = null;
jsonStrPreUpdate = xXServiceDefObj.getDefOptions();
if (!StringUtils.isEmpty(jsonStrPreUpdate)) {
serviceDefOptionsPreUpdate = jsonUtil.jsonToMap(jsonStrPreUpdate);
}
xXServiceDefObj = null;
dbTagServiceDef = svcDBStore.getServiceDefByName(SERVICEDBSTORE_SERVICEDEFBYNAME_TAG_NAME);
if (dbTagServiceDef != null) {
dbTagServiceDef.setPolicyConditions(embeddedTagPolicyConditionDefs);
RangerServiceDefValidator validator = validatorFactory.getServiceDefValidator(svcStore);
validator.validate(dbTagServiceDef, Action.UPDATE);
svcStore.updateServiceDef(dbTagServiceDef);
xXServiceDefObj = daoMgr.getXXServiceDef().findByName(SERVICEDBSTORE_SERVICEDEFBYNAME_TAG_NAME);
if (xXServiceDefObj != null) {
String jsonStrPostUpdate = xXServiceDefObj.getDefOptions();
Map<String, String> serviceDefOptionsPostUpdate = null;
if (!StringUtils.isEmpty(jsonStrPostUpdate)) {
serviceDefOptionsPostUpdate = jsonUtil.jsonToMap(jsonStrPostUpdate);
}
if (serviceDefOptionsPostUpdate != null && serviceDefOptionsPostUpdate.containsKey(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES)) {
if (serviceDefOptionsPreUpdate == null || !serviceDefOptionsPreUpdate.containsKey(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES)) {
String preUpdateValue = serviceDefOptionsPreUpdate == null ? null : serviceDefOptionsPreUpdate.get(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES);
if (preUpdateValue == null) {
serviceDefOptionsPostUpdate.remove(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES);
} else {
serviceDefOptionsPostUpdate.put(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES, preUpdateValue);
}
xXServiceDefObj.setDefOptions(mapToJsonString(serviceDefOptionsPostUpdate));
daoMgr.getXXServiceDef().update(xXServiceDefObj);
}
}
}
}
}
} catch (Exception e) {
logger.error("Error while updating " + SERVICEDBSTORE_SERVICEDEFBYNAME_TAG_NAME + "service-def", e);
}
}
Aggregations