use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class RangerServiceDefService method mapEntityToViewBean.
@Override
protected RangerServiceDef mapEntityToViewBean(RangerServiceDef vObj, XXServiceDef xObj) {
RangerServiceDef ret = super.mapEntityToViewBean(vObj, xObj);
Map<String, String> serviceDefOptions = ret.getOptions();
if (serviceDefOptions.get(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES) == null) {
boolean enableDenyAndExceptionsInPoliciesHiddenOption = RangerConfiguration.getInstance().getBoolean("ranger.servicedef.enableDenyAndExceptionsInPolicies", true);
if (enableDenyAndExceptionsInPoliciesHiddenOption || StringUtils.equalsIgnoreCase(ret.getName(), EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_TAG_NAME)) {
serviceDefOptions.put(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES, "true");
} else {
serviceDefOptions.put(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES, "false");
}
ret.setOptions(serviceDefOptions);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class MetricUtil method getAuditsCount.
private VXMetricServiceCount getAuditsCount(int accessResult, Date startDate, Date endDate) throws Exception {
long totalCountOfAudits = 0;
SearchFilter filter = new SearchFilter();
filter.setStartIndex(0);
Map<String, Long> servicesRepoType = new HashMap<String, Long>();
VXMetricServiceCount vXMetricServiceCount = new VXMetricServiceCount();
PList<RangerServiceDef> paginatedSvcDefs = svcStore.getPaginatedServiceDefs(filter);
Iterable<RangerServiceDef> repoTypeGet = paginatedSvcDefs.getList();
for (Object repo : repoTypeGet) {
RangerServiceDef rangerServiceDefObj = (RangerServiceDef) repo;
long id = rangerServiceDefObj.getId();
String serviceRepoName = rangerServiceDefObj.getName();
SearchCriteria searchCriteriaWithType = new SearchCriteria();
searchCriteriaWithType.getParamList().put("repoType", id);
searchCriteriaWithType.getParamList().put("accessResult", accessResult);
searchCriteriaWithType.addParam("startDate", startDate);
searchCriteriaWithType.addParam("endDate", endDate);
VXAccessAuditList vXAccessAuditListwithType = assetMgr.getAccessLogs(searchCriteriaWithType);
long toltalCountOfRepo = vXAccessAuditListwithType.getTotalCount();
if (toltalCountOfRepo != 0) {
servicesRepoType.put(serviceRepoName, toltalCountOfRepo);
totalCountOfAudits += toltalCountOfRepo;
}
}
vXMetricServiceCount.setServiceBasedCountList(servicesRepoType);
vXMetricServiceCount.setTotalCount(totalCountOfAudits);
return vXMetricServiceCount;
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class PublicAPIsv2 method deleteServiceDefByName.
@DELETE
@Path("/api/servicedef/name/{name}")
@PreAuthorize("hasRole('ROLE_SYS_ADMIN')")
public void deleteServiceDefByName(@PathParam("name") String name, @Context HttpServletRequest request) {
RangerServiceDef serviceDef = serviceREST.getServiceDefByName(name);
serviceREST.deleteServiceDef(serviceDef.getId(), request);
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class ServiceREST method getServiceDefByName.
@GET
@Path("/definitions/name/{name}")
@Produces({ "application/json", "application/xml" })
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_SERVICE_DEF_BY_NAME + "\")")
public RangerServiceDef getServiceDefByName(@PathParam("name") String name) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceREST.getServiceDefByName(serviceDefName=" + name + ")");
}
RangerServiceDef ret = null;
RangerPerfTracer perf = null;
try {
if (RangerPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = RangerPerfTracer.getPerfTracer(PERF_LOG, "ServiceREST.getServiceDefByName(" + name + ")");
}
XXServiceDef xServiceDef = daoManager.getXXServiceDef().findByName(name);
if (xServiceDef != null) {
if (!bizUtil.hasAccess(xServiceDef, null)) {
throw restErrorUtil.createRESTException("User is not allowed to access service-def: " + xServiceDef.getName(), MessageEnums.OPER_NO_PERMISSION);
}
}
ret = svcStore.getServiceDefByName(name);
} catch (WebApplicationException excp) {
throw excp;
} catch (Throwable excp) {
LOG.error("getServiceDefByName(" + name + ") failed", excp);
throw restErrorUtil.createRESTException(excp.getMessage());
} finally {
RangerPerfTracer.log(perf);
}
if (ret == null) {
throw restErrorUtil.createRESTException(HttpServletResponse.SC_NOT_FOUND, "Not found", true);
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== ServiceREST.getServiceDefByName(" + name + "): " + ret);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerServiceDef 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;
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;
}
Aggregations