Java Code Examples for org.apache.ranger.plugin.model.RangerServiceDef#getId()

The following examples show how to use org.apache.ranger.plugin.model.RangerServiceDef#getId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetricUtil.java    From ranger with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 2
Source File: PublicAPIsv2.java    From ranger with Apache License 2.0 5 votes vote down vote up
@PUT
@Path("/api/servicedef/{id}")
@PreAuthorize("hasRole('ROLE_SYS_ADMIN')")
@Produces({ "application/json", "application/xml" })
public RangerServiceDef updateServiceDef(RangerServiceDef serviceDef, @PathParam("id") Long id) {
	// if serviceDef.id is specified, it should be same as param 'id'
	if(serviceDef.getId() == null) {
		serviceDef.setId(id);
	} else if(!serviceDef.getId().equals(id)) {
		throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST , "serviceDef id mismatch", true);
	}

	return serviceREST.updateServiceDef(serviceDef);
}
 
Example 3
Source File: EmbeddedServiceDefsUtil.java    From ranger with Apache License 2.0 5 votes vote down vote up
private RangerServiceDef getOrCreateServiceDef(ServiceStore store, String serviceDefName) {
	if(LOG.isDebugEnabled()) {
		LOG.debug("==> EmbeddedServiceDefsUtil.getOrCreateServiceDef(" + serviceDefName + ")");
	}

	RangerServiceDef ret = null;
	boolean createServiceDef = (CollectionUtils.isEmpty(supportedServiceDefs) || supportedServiceDefs.contains(serviceDefName));
	try {
		ret = store.getServiceDefByName(serviceDefName);
		if(ret == null && createEmbeddedServiceDefs && createServiceDef) {
			ret = ServiceDefUtil.normalize(loadEmbeddedServiceDef(serviceDefName));

			LOG.info("creating embedded service-def " + serviceDefName);
			if (ret.getId() != null) {
				store.setPopulateExistingBaseFields(true);
				try {
					ret = store.createServiceDef(ret);
				} finally {
					store.setPopulateExistingBaseFields(false);
				}
			} else {
				ret = store.createServiceDef(ret);
			}
			LOG.info("created embedded service-def " + serviceDefName);
		}
	} catch(Exception excp) {
		LOG.fatal("EmbeddedServiceDefsUtil.getOrCreateServiceDef(): failed to load/create serviceType " + serviceDefName, excp);
	}

	if(LOG.isDebugEnabled()) {
		LOG.debug("<== EmbeddedServiceDefsUtil.getOrCreateServiceDef(" + serviceDefName + "): " + ret);
	}

	return ret;
}
 
Example 4
Source File: RangerServiceDefValidator.java    From ranger with Apache License 2.0 4 votes vote down vote up
boolean isValid(final RangerServiceDef serviceDef, final Action action, final List<ValidationFailureDetails> failures) {
	if(LOG.isDebugEnabled()) {
		LOG.debug("==> RangerServiceDefValidator.isValid(" + serviceDef + ")");
	}
	
	if (!(action == Action.CREATE || action == Action.UPDATE)) {
		throw new IllegalArgumentException("isValid(RangerServiceDef, ...) is only supported for CREATE/UPDATE");
	}
	boolean valid = true;
	if (serviceDef == null) {
		ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_NULL_SERVICE_DEF_OBJECT;
		failures.add(new ValidationFailureDetailsBuilder()
			.field("service def")
			.isMissing()
			.errorCode(error.getErrorCode())
			.becauseOf(error.getMessage(action))
			.build());
		valid = false;
	} else {
		Long id = serviceDef.getId();
		valid = isValidServiceDefId(id, action, failures) && valid;
		valid = isValidServiceDefName(serviceDef.getName(), id, action, failures) && valid;
		valid = isValidServiceDefDisplayName(serviceDef.getDisplayName(), id, action, failures) && valid;
		valid = isValidAccessTypes(serviceDef.getId(), serviceDef.getAccessTypes(), failures, action) && valid;
		if (isValidResources(serviceDef, failures, action)) {
			// Semantic check of resource graph can only be done if resources are "syntactically" valid
			valid = isValidResourceGraph(serviceDef, failures) && valid;
		} else {
			valid = false;
		}
		List<RangerEnumDef> enumDefs = serviceDef.getEnums();
		if (isValidEnums(enumDefs, failures)) {
			// config def validation requires valid enums
			valid = isValidConfigs(serviceDef.getConfigs(), enumDefs, failures) && valid;
		} else {
			valid = false;
		}
		valid = isValidPolicyConditions(serviceDef.getId(), serviceDef.getPolicyConditions(), failures, action) && valid;
		valid = isValidDataMaskTypes(serviceDef.getId(), serviceDef.getDataMaskDef().getMaskTypes(), failures, action) && valid;
	}
	
	if(LOG.isDebugEnabled()) {
		LOG.debug("<== RangerServiceDefValidator.isValid(" + serviceDef + "): " + valid);
	}
	return valid;
}
 
Example 5
Source File: RangerBasePlugin.java    From ranger with Apache License 2.0 4 votes vote down vote up
public int getServiceDefId() {
	RangerServiceDef serviceDef = getServiceDef();

	return serviceDef != null && serviceDef.getId() != null ? serviceDef.getId().intValue() : -1;
}
 
Example 6
Source File: EmbeddedServiceDefsUtil.java    From ranger with Apache License 2.0 4 votes vote down vote up
private long getId(RangerServiceDef serviceDef) {
	return serviceDef == null || serviceDef.getId() == null ? -1 : serviceDef.getId().longValue();
}