Java Code Examples for org.apache.ranger.plugin.policyengine.RangerAccessRequest#getContext()

The following examples show how to use org.apache.ranger.plugin.policyengine.RangerAccessRequest#getContext() . 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: RangerSampleCountryProvider.java    From ranger with Apache License 2.0 6 votes vote down vote up
@Override
public void enrich(RangerAccessRequest request) {
	if(LOG.isDebugEnabled()) {
		LOG.debug("==> RangerSampleCountryProvider.enrich(" + request + ")");
	}
	
	if(request != null && userCountryMap != null) {
		Map<String, Object> context = request.getContext();
		String              country = userCountryMap.getProperty(request.getUser());

		if(context != null && !StringUtils.isEmpty(country)) {
			request.getContext().put(contextName, country);
		} else {
			if(LOG.isDebugEnabled()) {
				LOG.debug("RangerSampleCountryProvider.enrich(): skipping due to unavailable context or country. context=" + context + "; country=" + country);
			}
		}
	}

	if(LOG.isDebugEnabled()) {
		LOG.debug("<== RangerSampleCountryProvider.enrich(" + request + ")");
	}
}
 
Example 2
Source File: RangerSampleProjectProvider.java    From ranger with Apache License 2.0 6 votes vote down vote up
@Override
public void enrich(RangerAccessRequest request) {
	if(LOG.isDebugEnabled()) {
		LOG.debug("==> RangerSampleProjectProvider.enrich(" + request + ")");
	}
	
	if(request != null && userProjectMap != null && request.getUser() != null) {
		Map<String, Object> context = request.getContext();
		String              project = userProjectMap.getProperty(request.getUser());

		if(context != null && !StringUtils.isEmpty(project)) {
			request.getContext().put(contextName, project);
		} else {
			if(LOG.isDebugEnabled()) {
				LOG.debug("RangerSampleProjectProvider.enrich(): skipping due to unavailable context or project. context=" + context + "; project=" + project);
			}
		}
	}

	if(LOG.isDebugEnabled()) {
		LOG.debug("<== RangerSampleProjectProvider.enrich(" + request + ")");
	}
}
 
Example 3
Source File: RangerPolicyConditionSampleSimpleMatcher.java    From ranger with Apache License 2.0 6 votes vote down vote up
String extractValue(final RangerAccessRequest request, String key) {
	if(LOG.isDebugEnabled()) {
		LOG.debug("==> RangerPolicyConditionSampleSimpleMatcher.extractValue(" + request+ ")");
	}

	String value = null;
	if (request == null) {
		LOG.debug("isMatched: Unexpected: null request.  Returning null!");
	} else if (request.getContext() == null) {
		LOG.debug("isMatched: Context map of request is null.  Ok. Returning null!");
	} else if (CollectionUtils.isEmpty(request.getContext().entrySet())) {
		LOG.debug("isMatched: Missing context on request.  Ok. Condition isn't applicable.  Returning null!");
	} else if (!request.getContext().containsKey(key)) {
		if (LOG.isDebugEnabled()) {
			LOG.debug("isMatched: Unexpected: Context did not have data for condition[" + key + "]. Returning null!");
		}
	} else {
		value = (String)request.getContext().get(key);
	}

	if(LOG.isDebugEnabled()) {
		LOG.debug("<== RangerPolicyConditionSampleSimpleMatcher.extractValue(" + request+ "): " + value);
	}
	return value;
}
 
Example 4
Source File: RangerSampleSimpleMatcher.java    From ranger with Apache License 2.0 6 votes vote down vote up
String extractValue(final RangerAccessRequest request, String key) {
	if(LOG.isDebugEnabled()) {
		LOG.debug("==> RangerSampleSimpleMatcher.extractValue(" + request+ ")");
	}

	String value = null;
	if (request == null) {
		LOG.debug("isMatched: Unexpected: null request.  Returning null!");
	} else if (request.getContext() == null) {
		LOG.debug("isMatched: Context map of request is null.  Ok. Returning null!");
	} else if (CollectionUtils.isEmpty(request.getContext().entrySet())) {
		LOG.debug("isMatched: Missing context on request.  Ok. Condition isn't applicable.  Returning null!");
	} else if (!request.getContext().containsKey(key)) {
		if (LOG.isDebugEnabled()) {
			LOG.debug("isMatched: Unexpected: Context did not have data for condition[" + key + "]. Returning null!");
		}
	} else {
		value = (String)request.getContext().get(key);
	}

	if(LOG.isDebugEnabled()) {
		LOG.debug("<== RangerSampleSimpleMatcher.extractValue(" + request+ "): " + value);
	}
	return value;
}
 
Example 5
Source File: RangerSimpleMatcher.java    From ranger with Apache License 2.0 6 votes vote down vote up
String extractValue(final RangerAccessRequest request, String key) {
	if(LOG.isDebugEnabled()) {
		LOG.debug("==> RangerSimpleMatcher.extractValue(" + request+ ")");
	}

	String value = null;
	if (request == null) {
		LOG.debug("isMatched: Unexpected: null request.  Returning null!");
	} else if (request.getContext() == null) {
		LOG.debug("isMatched: Context map of request is null.  Ok. Returning null!");
	} else if (CollectionUtils.isEmpty(request.getContext().entrySet())) {
		LOG.debug("isMatched: Missing context on request.  Ok. Condition isn't applicable.  Returning null!");
	} else if (!request.getContext().containsKey(key)) {
		if (LOG.isDebugEnabled()) {
			LOG.debug("isMatched: Unexpected: Context did not have data for condition[" + key + "]. Returning null!");
		}
	} else {
		value = (String)request.getContext().get(key);
	}

	if(LOG.isDebugEnabled()) {
		LOG.debug("<== RangerSimpleMatcher.extractValue(" + request+ "): " + value);
	}
	return value;
}
 
Example 6
Source File: RangerAbstractGeolocationProvider.java    From ranger with Apache License 2.0 4 votes vote down vote up
@Override
public void enrich(RangerAccessRequest request) {
	if (LOG.isDebugEnabled()) {
		LOG.debug("==> RangerAbstractGeolocationProvider.enrich(" + request + ")");
	}

	RangerGeolocationData geolocation = null;

	String clientIPAddress = request.getClientIPAddress();

	if (LOG.isDebugEnabled()) {
		LOG.debug("RangerAbstractGeolocationProvider.enrich() - clientIPAddress=" + clientIPAddress);
	}

	if (StringUtils.isNotBlank(clientIPAddress) && store != null) {
		geolocation = store.getGeoLocation(clientIPAddress);

		if (geolocation != null) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("RangerAbstractGeolocationProvider.enrich() - Country=" + geolocation);
			}
			Map<String, Object> context = request.getContext();

			String[] geoAttrValues = geolocation.getLocationData();

			RangerGeolocationDatabase database = store.getGeoDatabase();
			String[] attributeNames = database.getMetadata().getLocationDataItemNames();

			for (int i = 0; i < geoAttrValues.length && i < attributeNames.length; i++) {
				String contextName = KEY_CONTEXT_GEOLOCATION_PREFIX + geoMetaPrefix + attributeNames[i];
				context.put(contextName, geoAttrValues[i]);
			}
		} else {
			if (LOG.isDebugEnabled()) {
				LOG.debug("RangerAbstractGeolocationProvider.enrich() - clientIPAddress '" + clientIPAddress + "' not found.");
			}
		}
	} else {
		if (LOG.isDebugEnabled()) {
			LOG.debug("RangerAbstractGeolocationProvider.enrich() - clientIPAddress is null or blank, cannot get geolocation");
		}
	}
	if (LOG.isDebugEnabled()) {
		LOG.debug("<== RangerAbstractGeolocationProvider.enrich(" + request + ")");
	}
}