Java Code Examples for org.apache.ranger.plugin.model.RangerPolicy#setZoneName()

The following examples show how to use org.apache.ranger.plugin.model.RangerPolicy#setZoneName() . 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: PatchForAtlasToAddEntityLabelAndBusinessMetadata_J10034.java    From ranger with Apache License 2.0 6 votes vote down vote up
private RangerPolicy getRangerPolicyObject(String serviceName, String policyName) {
    RangerPolicy rangerPolicy = new RangerPolicy();
    RangerPolicyResourceSignature resourceSignature = new RangerPolicyResourceSignature(rangerPolicy);

    rangerPolicy.setName(policyName);
    rangerPolicy.setDescription("Policy for " + policyName);
    rangerPolicy.setService(serviceName);
    rangerPolicy.setPolicyPriority(RangerPolicy.POLICY_PRIORITY_NORMAL);
    rangerPolicy.setIsAuditEnabled(Boolean.TRUE);
    rangerPolicy.setIsEnabled(Boolean.TRUE);
    rangerPolicy.setPolicyType(RangerPolicy.POLICY_TYPE_ACCESS);
    rangerPolicy.setGuid(guidUtil.genGUID());
    rangerPolicy.setResourceSignature(resourceSignature.getSignature());
    rangerPolicy.setZoneName("");
    rangerPolicy.setUpdatedBy(LOGIN_ID_ADMIN);
    return rangerPolicy;
}
 
Example 2
Source File: ServiceREST.java    From ranger with Apache License 2.0 5 votes vote down vote up
private void deleteExactMatchPolicyForResource(List<RangerPolicy> policies, String user, String zoneName) throws Exception {
	if (CollectionUtils.isNotEmpty(policies)) {
		long totalDeletedPolicies = 0;
		for (RangerPolicy rangerPolicy : policies) {
			RangerPolicy existingPolicy = null ;
			try {
				if(zoneName!=null) {
					rangerPolicy.setZoneName(zoneName);
				}
				existingPolicy = getExactMatchPolicyForResource(rangerPolicy, StringUtils.isNotBlank(user) ? user :"admin");
			} catch (Exception e) {
				existingPolicy=null;
			}
			if (existingPolicy != null) {
				svcStore.deletePolicy(existingPolicy, null);
				totalDeletedPolicies = totalDeletedPolicies + 1;
				if (totalDeletedPolicies % RangerBizUtil.policyBatchSize == 0) {
					bizUtil.bulkModeOnlyFlushAndClear();
				}
				if (LOG.isDebugEnabled()) {
					LOG.debug("Policy " + rangerPolicy.getName() + " deleted successfully.");
				}
			}
		}
		bizUtil.bulkModeOnlyFlushAndClear();
	}
}
 
Example 3
Source File: RangerPolicyRetriever.java    From ranger with Apache License 2.0 5 votes vote down vote up
RangerPolicy getNextPolicy() {
	RangerPolicy ret = null;

	if (service != null && iterPolicy != null && iterPolicy.hasNext()) {
		XXPolicy xPolicy = iterPolicy.next();

		if (xPolicy != null) {
			String policyText = xPolicy.getPolicyText();

			ret = JsonUtils.jsonToObject(policyText, RangerPolicy.class);

			if (ret != null) {
				ret.setId(xPolicy.getId());
				ret.setGuid(xPolicy.getGuid());
				ret.setCreatedBy(lookupCache.getUserScreenName(xPolicy.getAddedByUserId()));
				ret.setUpdatedBy(lookupCache.getUserScreenName(xPolicy.getUpdatedByUserId()));
				ret.setCreateTime(xPolicy.getCreateTime());
				ret.setUpdateTime(xPolicy.getUpdateTime());
				ret.setVersion(xPolicy.getVersion());
				ret.setPolicyType(xPolicy.getPolicyType() == null ? RangerPolicy.POLICY_TYPE_ACCESS : xPolicy.getPolicyType());
				ret.setService(service.getName());
				ret.setServiceType(serviceDef.getName());
				ret.setZoneName(lookupCache.getSecurityZoneName(xPolicy.getZoneId()));
				updatePolicyReferenceFields(ret);
				getPolicyLabels(ret);
			}
		}
	}

	return ret;
}
 
Example 4
Source File: TestRangerPolicyServiceBase.java    From ranger with Apache License 2.0 5 votes vote down vote up
private RangerPolicy rangerPolicy() {
	List<RangerPolicyItemAccess> accesses = new ArrayList<RangerPolicyItemAccess>();
	List<String> users = new ArrayList<String>();
	List<String> groups = new ArrayList<String>();
	List<RangerPolicyItemCondition> conditions = new ArrayList<RangerPolicyItemCondition>();
	List<RangerPolicyItem> policyItems = new ArrayList<RangerPolicyItem>();
	RangerPolicyItem rangerPolicyItem = new RangerPolicyItem();
	rangerPolicyItem.setAccesses(accesses);
	rangerPolicyItem.setConditions(conditions);
	rangerPolicyItem.setGroups(groups);
	rangerPolicyItem.setUsers(users);
	rangerPolicyItem.setDelegateAdmin(false);

	policyItems.add(rangerPolicyItem);

	Map<String, RangerPolicyResource> policyResource = new HashMap<String, RangerPolicyResource>();
	RangerPolicyResource rangerPolicyResource = new RangerPolicyResource();
	rangerPolicyResource.setIsExcludes(true);
	rangerPolicyResource.setIsRecursive(true);
	rangerPolicyResource.setValue("1");
	rangerPolicyResource.setValues(users);
	RangerPolicy policy = new RangerPolicy();
	policy.setId(Id);
	policy.setCreateTime(new Date());
	policy.setDescription("policy");
	policy.setGuid("policyguid");
	policy.setIsEnabled(true);
	policy.setName("HDFS_1-1-20150316062453");
	policy.setUpdatedBy("Admin");
	policy.setUpdateTime(new Date());
	policy.setService("HDFS_1-1-20150316062453");
	policy.setIsAuditEnabled(true);
	policy.setPolicyItems(policyItems);
	policy.setResources(policyResource);
	policy.setZoneName("");

	return policy;
}