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

The following examples show how to use org.apache.ranger.plugin.model.RangerPolicy#setId() . 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: PublicAPIsv2.java    From ranger with Apache License 2.0 6 votes vote down vote up
@PUT
@Path("/api/service/{servicename}/policy/{policyname}")
@Produces({ "application/json", "application/xml" })
public RangerPolicy updatePolicyByName(RangerPolicy policy,
                                               @PathParam("servicename") String serviceName,
                                               @PathParam("policyname") String policyName,
                                               @Context HttpServletRequest request) {
	if (policy.getService() == null || !policy.getService().equals(serviceName)) {
		throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST , "service name mismatch", true);
	}
	RangerPolicy oldPolicy = getPolicyByName(serviceName, policyName, request);

	// ignore policy.id - if specified. Retrieve using the given serviceName+policyName and use id from the retrieved object
	policy.setId(oldPolicy.getId());
	if(StringUtils.isEmpty(policy.getGuid())) {
		policy.setGuid(oldPolicy.getGuid());
	}
	if(StringUtils.isEmpty(policy.getName())) {
		policy.setName(StringUtils.trim(oldPolicy.getName()));
	}

	return serviceREST.updatePolicy(policy);
}
 
Example 2
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 3
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;
}
 
Example 4
Source File: TestServiceDBStore.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<String> policyLabels = 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.setPolicyLabels(policyLabels);

	return policy;
}
 
Example 5
Source File: TestXUserMgr.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<String> policyLabels = 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(userId);
	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.setPolicyLabels(policyLabels);
	return policy;
}
 
Example 6
Source File: TestPublicAPIsv2.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);
	policyResource.put("resource", rangerPolicyResource);
	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.setService("HDFS_1");

	return policy;
}
 
Example 7
Source File: TestPublicAPIsv2.java    From ranger with Apache License 2.0 5 votes vote down vote up
private RangerPolicy rangerPolicy1() {
	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("2");
	rangerPolicyResource.setValues(users);
	policyResource.put("resource", rangerPolicyResource);
	RangerPolicy policy = new RangerPolicy();
	policy.setId(Id2);
	policy.setCreateTime(new Date());
	policy.setDescription("policy");
	policy.setGuid("policyguid");
	policy.setIsEnabled(true);
	policy.setName("HDFS_1-1-20150316062454");
	policy.setUpdatedBy("Admin");
	policy.setUpdateTime(new Date());
	policy.setService("HDFS_1-1-20150316062454");
	policy.setIsAuditEnabled(true);
	policy.setPolicyItems(policyItems);
	policy.setResources(policyResource);
	policy.setService("HDFS_2");

	return policy;
}
 
Example 8
Source File: TestServiceUtil.java    From ranger with Apache License 2.0 5 votes vote down vote up
@Test
public void testToVXResourceForServiceNull(){
        RangerPolicy policy = new RangerPolicy();
        policy.setId(1L);
        policy.setName("hive Policy");
        policy.setService("hive");
        policy.setDescription("hive policy description");

        RangerService rangerService = null;

        VXResource vXResource = serviceUtil.toVXResource(policy, rangerService);

        Assert.assertNull(vXResource);

}
 
Example 9
Source File: TestServiceUtil.java    From ranger with Apache License 2.0 4 votes vote down vote up
@Test
public void testToRangerPolicyForResourceTypeColumn(){

        RangerPolicy expectedRangerPolicy = new RangerPolicy();
        expectedRangerPolicy.setId(1L);
        expectedRangerPolicy.setName("hive Policy");
        expectedRangerPolicy.setService("hive");
        expectedRangerPolicy.setDescription("hive policy description");

        Map<String, RangerPolicyResource> expectedMap = new HashMap<String, RangerPolicyResource>();
        List<String> valuesList = new ArrayList<String>();
        valuesList.add("column");


        VXAuditMap vXAuditMap = new VXAuditMap();
        vXAuditMap.setId(1L);
        vXAuditMap.setOwner("rangerAdmin");
        List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>();
        vXAuditMapList.add(vXAuditMap);

        RangerPolicyResource rangerPolicyResource = new RangerPolicyResource();
        rangerPolicyResource.setIsExcludes(true);
        rangerPolicyResource.setIsRecursive(false);
        rangerPolicyResource.setValue("column");
        rangerPolicyResource.setValues(valuesList);

        expectedMap.put("column", rangerPolicyResource);

        expectedRangerPolicy.setResources(expectedMap);

        RangerService rangerService = new RangerService();
        rangerService.setName("hive");


        VXResource resource = new VXResource();
        resource.setId(1L);
        resource.setColumns("column");
        resource.setUpdateDate(new Date());
        resource.setCreateDate(new Date());
        resource.setOwner("rangerAdmin");
        resource.setUpdatedBy("rangerAdmin");
        resource.setPolicyName("hive Policy");
        resource.setDescription("hive policy description");
        resource.setResourceStatus(RangerCommonEnums.STATUS_ENABLED);
        resource.setIsRecursive(1);
        resource.setTableType(1);
        resource.setColumnType(1);

        RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(resource, rangerService);

        Assert.assertNotNull(actualRangerPolicy);
        Assert.assertEquals(expectedRangerPolicy.getId(), actualRangerPolicy.getId());
        Assert.assertEquals(expectedRangerPolicy.getName(), actualRangerPolicy.getName());
        Assert.assertEquals(expectedRangerPolicy.getService(), actualRangerPolicy.getService());
        Assert.assertEquals(expectedRangerPolicy.getDescription(), actualRangerPolicy.getDescription());
        Assert.assertEquals(expectedRangerPolicy.getResources(), actualRangerPolicy.getResources());

}
 
Example 10
Source File: TestServiceUtil.java    From ranger with Apache License 2.0 4 votes vote down vote up
@Test
public void testToRangerPolicyForPermGroup(){

        RangerPolicyItemCondition rpic = new RangerPolicyItemCondition();
        List<String> valuesList = new ArrayList<String>();
        valuesList.add("10.129.25.56");
        rpic.setType("ipaddress");
        rpic.setValues(valuesList);

        List<String> usersList = new ArrayList<String>();
        usersList.add("rangerAdmin");

        List<String> groupList = new ArrayList<String>();

        List<RangerPolicyItemCondition> listRPIC = new ArrayList<RangerPolicy.RangerPolicyItemCondition>();
        listRPIC.add(rpic);

        RangerPolicyItemAccess rpia = new RangerPolicyItemAccess();
        rpia.setIsAllowed(true);
        rpia.setType("drop");

        List<RangerPolicyItemAccess> listRPIA = new ArrayList<RangerPolicy.RangerPolicyItemAccess>();
        listRPIA.add(rpia);

        RangerPolicyItem rangerPolicyItem = new RangerPolicyItem();
        rangerPolicyItem.setConditions(listRPIC);
        rangerPolicyItem.setAccesses(listRPIA);
        rangerPolicyItem.setDelegateAdmin(false);
        rangerPolicyItem.setUsers(usersList);
        rangerPolicyItem.setGroups(groupList);

        List<RangerPolicyItem> listRangerPolicyItem = new ArrayList<RangerPolicy.RangerPolicyItem>();
        listRangerPolicyItem.add(rangerPolicyItem);

        RangerPolicy expectedRangerPolicy = new RangerPolicy();
        expectedRangerPolicy.setId(1L);
        expectedRangerPolicy.setName("hive Policy");
        expectedRangerPolicy.setService("hive");
        expectedRangerPolicy.setDescription("hive policy description");
        expectedRangerPolicy.setPolicyItems(listRangerPolicyItem);

        VXPermMap vXPermMap = new VXPermMap();
        vXPermMap.setId(5L);
        vXPermMap.setGroupName("myGroup");
        vXPermMap.setPermGroup("permGroup");
        vXPermMap.setUserName("rangerAdmin");
        vXPermMap.setPermType(12);
        vXPermMap.setPermFor(AppConstants.XA_PERM_FOR_USER);
        vXPermMap.setIpAddress("10.129.25.56");

        List<VXPermMap> vXPermMapList = new ArrayList<VXPermMap>();
        vXPermMapList.add(vXPermMap);


        VXAuditMap vXAuditMap = new VXAuditMap();
        vXAuditMap.setId(1L);
        vXAuditMap.setOwner("rangerAdmin");
        List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>();
        vXAuditMapList.add(vXAuditMap);

        RangerService rangerService = new RangerService();
        rangerService.setName("hive");
        rangerService.setType("hive");


        VXResource resource = new VXResource();
        resource.setId(1L);
        resource.setUpdateDate(new Date());
        resource.setCreateDate(new Date());
        resource.setOwner("rangerAdmin");
        resource.setUpdatedBy("rangerAdmin");
        resource.setPolicyName("hive Policy");
        resource.setDescription("hive policy description");
        resource.setResourceStatus(RangerCommonEnums.STATUS_ENABLED);
        resource.setIsRecursive(1);
        resource.setTableType(1);
        resource.setColumnType(1);
        resource.setPermMapList(vXPermMapList);

        RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(resource, rangerService);

        Assert.assertNotNull(actualRangerPolicy);
        Assert.assertEquals(expectedRangerPolicy.getId(), actualRangerPolicy.getId());
        Assert.assertEquals(expectedRangerPolicy.getName(), actualRangerPolicy.getName());
        Assert.assertEquals(expectedRangerPolicy.getService(), actualRangerPolicy.getService());
        Assert.assertEquals(expectedRangerPolicy.getDescription(), actualRangerPolicy.getDescription());
        Assert.assertEquals(expectedRangerPolicy.getPolicyItems(), actualRangerPolicy.getPolicyItems());

}
 
Example 11
Source File: TestServiceUtil.java    From ranger with Apache License 2.0 4 votes vote down vote up
@Test
public void testToRangerPolicyForResourceTypeColumnFamily(){

        RangerPolicy expectedRangerPolicy = new RangerPolicy();
        expectedRangerPolicy.setId(1L);
        expectedRangerPolicy.setName("hive Policy");
        expectedRangerPolicy.setService("hive");
        expectedRangerPolicy.setDescription("hive policy description");

        Map<String, RangerPolicyResource> expectedMap = new HashMap<String, RangerPolicyResource>();
        List<String> valuesList = new ArrayList<String>();
        valuesList.add("columnFamilies");


        VXAuditMap vXAuditMap = new VXAuditMap();
        vXAuditMap.setId(1L);
        vXAuditMap.setOwner("rangerAdmin");
        List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>();
        vXAuditMapList.add(vXAuditMap);

        RangerPolicyResource rangerPolicyResource = new RangerPolicyResource();
        rangerPolicyResource.setIsExcludes(false);
        rangerPolicyResource.setIsRecursive(false);
        rangerPolicyResource.setValue("columnFamilies");
        rangerPolicyResource.setValues(valuesList);

        expectedMap.put("column-family", rangerPolicyResource);

        expectedRangerPolicy.setResources(expectedMap);

        RangerService rangerService = new RangerService();
        rangerService.setName("hive");


        VXResource resource = new VXResource();
        resource.setId(1L);
        resource.setColumnFamilies("columnFamilies");
        resource.setUpdateDate(new Date());
        resource.setCreateDate(new Date());
        resource.setOwner("rangerAdmin");
        resource.setUpdatedBy("rangerAdmin");
        resource.setPolicyName("hive Policy");
        resource.setDescription("hive policy description");
        resource.setResourceStatus(RangerCommonEnums.STATUS_ENABLED);
        resource.setIsRecursive(1);
        resource.setTableType(1);
        resource.setColumnType(1);

        RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(resource, rangerService);

        Assert.assertNotNull(actualRangerPolicy);
        Assert.assertEquals(expectedRangerPolicy.getId(), actualRangerPolicy.getId());
        Assert.assertEquals(expectedRangerPolicy.getName(), actualRangerPolicy.getName());
        Assert.assertEquals(expectedRangerPolicy.getService(), actualRangerPolicy.getService());
        Assert.assertEquals(expectedRangerPolicy.getDescription(), actualRangerPolicy.getDescription());
        Assert.assertEquals(expectedRangerPolicy.getResources(), actualRangerPolicy.getResources());

}
 
Example 12
Source File: TestServiceUtil.java    From ranger with Apache License 2.0 4 votes vote down vote up
@Test
public void testToRangerPolicyForResourceTypeTable(){

        RangerPolicy expectedRangerPolicy = new RangerPolicy();
        expectedRangerPolicy.setId(1L);
        expectedRangerPolicy.setName("hive Policy");
        expectedRangerPolicy.setService("hive");
        expectedRangerPolicy.setDescription("hive policy description");

        Map<String, RangerPolicyResource> expectedMap = new HashMap<String, RangerPolicyResource>();
        List<String> valuesList = new ArrayList<String>();
        valuesList.add("xa_service");


        VXAuditMap vXAuditMap = new VXAuditMap();
        vXAuditMap.setId(1L);
        vXAuditMap.setOwner("rangerAdmin");
        List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>();
        vXAuditMapList.add(vXAuditMap);

        RangerPolicyResource rangerPolicyResource = new RangerPolicyResource();
        rangerPolicyResource.setIsExcludes(true);
        rangerPolicyResource.setIsRecursive(false);
        rangerPolicyResource.setValue("xa_service");
        rangerPolicyResource.setValues(valuesList);

        expectedMap.put("table", rangerPolicyResource);

        expectedRangerPolicy.setResources(expectedMap);

        RangerService rangerService = new RangerService();
        rangerService.setName("hive");


        VXResource resource = new VXResource();
        resource.setId(1L);
        resource.setTables("xa_service");
        resource.setUpdateDate(new Date());
        resource.setCreateDate(new Date());
        resource.setOwner("rangerAdmin");
        resource.setUpdatedBy("rangerAdmin");
        resource.setPolicyName("hive Policy");
        resource.setDescription("hive policy description");
        resource.setResourceStatus(RangerCommonEnums.STATUS_ENABLED);
        resource.setIsRecursive(1);
        resource.setTableType(1);
        resource.setColumnType(1);

        RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(resource, rangerService);

        Assert.assertNotNull(actualRangerPolicy);
        Assert.assertEquals(expectedRangerPolicy.getId(), actualRangerPolicy.getId());
        Assert.assertEquals(expectedRangerPolicy.getName(), actualRangerPolicy.getName());
        Assert.assertEquals(expectedRangerPolicy.getService(), actualRangerPolicy.getService());
        Assert.assertEquals(expectedRangerPolicy.getDescription(), actualRangerPolicy.getDescription());
        Assert.assertEquals(expectedRangerPolicy.getResources(), actualRangerPolicy.getResources());


}
 
Example 13
Source File: TestServiceUtil.java    From ranger with Apache License 2.0 4 votes vote down vote up
@Test
public void testToRangerPolicyForResourceTypePath(){
        RangerPolicy expectedRangerPolicy = new RangerPolicy();
        expectedRangerPolicy.setId(1L);
        expectedRangerPolicy.setName("hive Policy");
        expectedRangerPolicy.setService("hive");
        expectedRangerPolicy.setDescription("hive policy description");

        Map<String, RangerPolicyResource> expectedMap = new HashMap<String, RangerPolicyResource>();
        List<String> valuesList = new ArrayList<String>();
        valuesList.add("resource");


        VXAuditMap vXAuditMap = new VXAuditMap();
        vXAuditMap.setId(1L);
        vXAuditMap.setOwner("rangerAdmin");
        List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>();
        vXAuditMapList.add(vXAuditMap);

        RangerPolicyResource rangerPolicyResource = new RangerPolicyResource();
        rangerPolicyResource.setIsExcludes(false);
        rangerPolicyResource.setIsRecursive(true);
        rangerPolicyResource.setValue("/localhost/files");
        rangerPolicyResource.setValues(valuesList);

        expectedMap.put("path", rangerPolicyResource);

        expectedRangerPolicy.setResources(expectedMap);

        RangerService rangerService = new RangerService();
        rangerService.setName("hive");


        VXResource resource = new VXResource();
        resource.setId(1L);
        resource.setName("resource");
        resource.setUpdateDate(new Date());
        resource.setCreateDate(new Date());
        resource.setOwner("rangerAdmin");
        resource.setUpdatedBy("rangerAdmin");
        resource.setPolicyName("hive Policy");
        resource.setDescription("hive policy description");
        resource.setResourceStatus(RangerCommonEnums.STATUS_ENABLED);
        resource.setIsRecursive(1);
        resource.setTableType(1);
        resource.setColumnType(1);

        RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(resource, rangerService);

        Assert.assertNotNull(actualRangerPolicy);
        Assert.assertEquals(expectedRangerPolicy.getId(), actualRangerPolicy.getId());
        Assert.assertEquals(expectedRangerPolicy.getName(), actualRangerPolicy.getName());
        Assert.assertEquals(expectedRangerPolicy.getService(), actualRangerPolicy.getService());
        Assert.assertEquals(expectedRangerPolicy.getDescription(), actualRangerPolicy.getDescription());
        Assert.assertEquals(expectedRangerPolicy.getResources(), actualRangerPolicy.getResources());

}
 
Example 14
Source File: TestServiceUtil.java    From ranger with Apache License 2.0 4 votes vote down vote up
@Test
public void testToVXResourceForTablesColumnFamiliesAndColumn(){
        GUIDUtil guid = new GUIDUtil();
        String guidString = guid.genGUID();
        List<VXAuditMap> auditList = new ArrayList<VXAuditMap>();

        VXAuditMap vxAuditMap = new VXAuditMap();
        vxAuditMap.setResourceId(1L);
        vxAuditMap.setAuditType(AppConstants.XA_AUDIT_TYPE_ALL);
        auditList.add(vxAuditMap);

        VXResource expectedVXResource = new VXResource();
        expectedVXResource.setName("/myTable/myColumnFamilies/myColumn");
        expectedVXResource.setTables("myTable");
        expectedVXResource.setColumnFamilies("myColumnFamilies");
        expectedVXResource.setColumns("myColumn");
        expectedVXResource.setGuid(guidString);
        expectedVXResource.setPolicyName("hbase Policy");
        expectedVXResource.setDescription("hbase policy description");
        expectedVXResource.setResourceType(1);
        expectedVXResource.setAssetName("hbase");
        expectedVXResource.setAssetType(2);
        expectedVXResource.setResourceStatus(1);
        expectedVXResource.setTableType(1);
        expectedVXResource.setColumnType(1);
        expectedVXResource.setAuditList(auditList);

        Map<String, RangerPolicyResource> rangerPolicyResourceMap = new HashMap<String, RangerPolicyResource>();
        List<String> valuesListForTable = new ArrayList<String>();
        valuesListForTable.add("myTable");

        List<String> valuesListForColumn = new ArrayList<String>();
        valuesListForColumn.add("myColumn");

        List<String> valuesListForColumnFamilies = new ArrayList<String>();
        valuesListForColumnFamilies.add("myColumnFamilies");

        RangerPolicy policy = new RangerPolicy();
        policy.setId(1L);
        policy.setName("hbase Policy");
        policy.setService("hbase");
        policy.setDescription("hbase policy description");
        policy.setIsEnabled(true);
        policy.setGuid(guidString);
        policy.setIsAuditEnabled(true);

        RangerService rangerService = new RangerService();
        rangerService.setName("hbase");
        rangerService.setType("hbase");

        RangerPolicyResource rangerPolicyResourceForTable = new RangerPolicyResource();
        rangerPolicyResourceForTable.setIsExcludes(true);
        rangerPolicyResourceForTable.setIsRecursive(true);
        rangerPolicyResourceForTable.setValue("table");
        rangerPolicyResourceForTable.setValues(valuesListForTable);

        rangerPolicyResourceMap.put("table", rangerPolicyResourceForTable);

        RangerPolicyResource rangerPolicyResourceForColumn = new RangerPolicyResource();
        rangerPolicyResourceForColumn.setIsExcludes(true);
        rangerPolicyResourceForColumn.setIsRecursive(true);
        rangerPolicyResourceForColumn.setValue("table");
        rangerPolicyResourceForColumn.setValues(valuesListForColumn);

        rangerPolicyResourceMap.put("column", rangerPolicyResourceForColumn);

        RangerPolicyResource rangerPolicyResourceForColumnFamilies = new RangerPolicyResource();
        rangerPolicyResourceForColumnFamilies.setIsExcludes(true);
        rangerPolicyResourceForColumnFamilies.setIsRecursive(true);
        rangerPolicyResourceForColumnFamilies.setValue("table");
        rangerPolicyResourceForColumnFamilies.setValues(valuesListForColumnFamilies);

        rangerPolicyResourceMap.put("column-family", rangerPolicyResourceForColumnFamilies);


        policy.setResources(rangerPolicyResourceMap);

        VXResource actualVXResource = serviceUtil.toVXResource(policy, rangerService);


        Assert.assertNotNull(actualVXResource);
        Assert.assertEquals(expectedVXResource.getName(), actualVXResource.getName());
        Assert.assertEquals(expectedVXResource.getGuid(), actualVXResource.getGuid());
        Assert.assertEquals(expectedVXResource.getPolicyName(), actualVXResource.getPolicyName());
        Assert.assertEquals(expectedVXResource.getResourceType(), actualVXResource.getResourceType());
        Assert.assertEquals(expectedVXResource.getDescription(), actualVXResource.getDescription());
        Assert.assertEquals(expectedVXResource.getAssetName(), actualVXResource.getAssetName());
        Assert.assertEquals(expectedVXResource.getAssetType(), actualVXResource.getAssetType());
        Assert.assertEquals(expectedVXResource.getResourceStatus(), actualVXResource.getResourceStatus());
        Assert.assertEquals(expectedVXResource.getTableType(), actualVXResource.getTableType());
        Assert.assertEquals(expectedVXResource.getColumnType(), actualVXResource.getColumnType());
        Assert.assertEquals(expectedVXResource.getTables(), actualVXResource.getTables());
        Assert.assertEquals(expectedVXResource.getColumns(), actualVXResource.getColumns());
        Assert.assertEquals(expectedVXResource.getColumnFamilies(), actualVXResource.getColumnFamilies());
        Assert.assertEquals(expectedVXResource.getAuditList().get(0).getResourceId(), actualVXResource.getAuditList().get(0).getResourceId());
        Assert.assertEquals(expectedVXResource.getAuditList().get(0).getAuditType(), actualVXResource.getAuditList().get(0).getAuditType());


}
 
Example 15
Source File: TestServiceUtil.java    From ranger with Apache License 2.0 4 votes vote down vote up
@Test
public void testToRangerPolicyForResourceTypeTopology(){

        RangerPolicy expectedRangerPolicy = new RangerPolicy();
        expectedRangerPolicy.setId(1L);
        expectedRangerPolicy.setName("hive Policy");
        expectedRangerPolicy.setService("hive");
        expectedRangerPolicy.setDescription("hive policy description");

        Map<String, RangerPolicyResource> expectedMap = new HashMap<String, RangerPolicyResource>();
        List<String> valuesList = new ArrayList<String>();
        valuesList.add("topology");


        VXAuditMap vXAuditMap = new VXAuditMap();
        vXAuditMap.setId(1L);
        vXAuditMap.setOwner("rangerAdmin");
        List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>();
        vXAuditMapList.add(vXAuditMap);

        RangerPolicyResource rangerPolicyResource = new RangerPolicyResource();
        rangerPolicyResource.setIsExcludes(false);
        rangerPolicyResource.setIsRecursive(false);
        rangerPolicyResource.setValue("topology");
        rangerPolicyResource.setValues(valuesList);

        expectedMap.put("topology", rangerPolicyResource);

        expectedRangerPolicy.setResources(expectedMap);

        RangerService rangerService = new RangerService();
        rangerService.setName("hive");


        VXResource resource = new VXResource();
        resource.setId(1L);
        resource.setTopologies("topology");
        resource.setUpdateDate(new Date());
        resource.setCreateDate(new Date());
        resource.setOwner("rangerAdmin");
        resource.setUpdatedBy("rangerAdmin");
        resource.setPolicyName("hive Policy");
        resource.setDescription("hive policy description");
        resource.setResourceStatus(RangerCommonEnums.STATUS_ENABLED);
        resource.setIsRecursive(1);
        resource.setTableType(1);
        resource.setColumnType(1);

        RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(resource, rangerService);

        Assert.assertNotNull(actualRangerPolicy);
        Assert.assertEquals(expectedRangerPolicy.getId(), actualRangerPolicy.getId());
        Assert.assertEquals(expectedRangerPolicy.getName(), actualRangerPolicy.getName());
        Assert.assertEquals(expectedRangerPolicy.getService(), actualRangerPolicy.getService());
        Assert.assertEquals(expectedRangerPolicy.getDescription(), actualRangerPolicy.getDescription());
        Assert.assertEquals(expectedRangerPolicy.getResources(), actualRangerPolicy.getResources());

}
 
Example 16
Source File: TestServiceUtil.java    From ranger with Apache License 2.0 4 votes vote down vote up
@Test
public void testToRangerPolicyForResourceTypeHiveService(){

        RangerPolicy expectedRangerPolicy = new RangerPolicy();
        expectedRangerPolicy.setId(1L);
        expectedRangerPolicy.setName("hive Policy");
        expectedRangerPolicy.setService("hive");
        expectedRangerPolicy.setDescription("hive policy description");

        Map<String, RangerPolicyResource> expectedMap = new HashMap<String, RangerPolicyResource>();
        List<String> valuesList = new ArrayList<String>();
        valuesList.add("hiveservice");


        VXAuditMap vXAuditMap = new VXAuditMap();
        vXAuditMap.setId(1L);
        vXAuditMap.setOwner("rangerAdmin");
        List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>();
        vXAuditMapList.add(vXAuditMap);

        RangerPolicyResource rangerPolicyResource = new RangerPolicyResource();
        rangerPolicyResource.setIsExcludes(false);
        rangerPolicyResource.setIsRecursive(false);
        rangerPolicyResource.setValue("hiveservice");
        rangerPolicyResource.setValues(valuesList);

        expectedMap.put("service", rangerPolicyResource);

        expectedRangerPolicy.setResources(expectedMap);

        RangerService rangerService = new RangerService();
        rangerService.setName("hive");


        VXResource resource = new VXResource();
        resource.setId(1L);
        resource.setServices("hiveservice");
        resource.setUpdateDate(new Date());
        resource.setCreateDate(new Date());
        resource.setOwner("rangerAdmin");
        resource.setUpdatedBy("rangerAdmin");
        resource.setPolicyName("hive Policy");
        resource.setDescription("hive policy description");
        resource.setResourceStatus(RangerCommonEnums.STATUS_ENABLED);
        resource.setIsRecursive(1);
        resource.setTableType(1);
        resource.setColumnType(1);

        RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(resource, rangerService);

        Assert.assertNotNull(actualRangerPolicy);
        Assert.assertEquals(expectedRangerPolicy.getId(), actualRangerPolicy.getId());
        Assert.assertEquals(expectedRangerPolicy.getName(), actualRangerPolicy.getName());
        Assert.assertEquals(expectedRangerPolicy.getService(), actualRangerPolicy.getService());
        Assert.assertEquals(expectedRangerPolicy.getDescription(), actualRangerPolicy.getDescription());
        Assert.assertEquals(expectedRangerPolicy.getResources(), actualRangerPolicy.getResources());

}
 
Example 17
Source File: TestServiceUtil.java    From ranger with Apache License 2.0 4 votes vote down vote up
@Test
public void testToRangerPolicy(){
        Date date = new Date();

        List<String> userList = new ArrayList<String>();
        userList.add("rangerAdmin");

        List<String> groupList = new ArrayList<String>();
        groupList.add("rangerGroup");

        List<String> permObjList = new ArrayList<String>();
        permObjList.add("Admin");

        Map<String, RangerPolicyResource> resourceMap = new HashMap<String, RangerPolicyResource>();
        List<String> valuesList = new ArrayList<String>();
        valuesList.add("resource");

        RangerPolicyResource rangerPolicyResource = new RangerPolicyResource();
        rangerPolicyResource.setIsExcludes(false);
        rangerPolicyResource.setIsRecursive(true);
        rangerPolicyResource.setValues(valuesList);

        resourceMap.put("path", rangerPolicyResource);

        List<RangerPolicyItem> rangerPolicyItemList = new ArrayList<RangerPolicy.RangerPolicyItem>();
        RangerPolicyItem rangerPolicyItem = new RangerPolicyItem();
        rangerPolicyItem.setUsers(userList);
        rangerPolicyItem.setGroups(groupList);

        List<RangerPolicyItemCondition> rangerPolicyItemConditionList = new ArrayList<RangerPolicy.RangerPolicyItemCondition>();
        RangerPolicyItemCondition rangerPolicyItemCondition = new RangerPolicyItemCondition();
        rangerPolicyItemCondition.setType("ipaddress");
        List<String> conditionValueList = new ArrayList<String>();
        conditionValueList.add("10.129.35.86");
        rangerPolicyItemCondition.setValues(conditionValueList);
        rangerPolicyItemConditionList.add(rangerPolicyItemCondition);
        rangerPolicyItem.setConditions(rangerPolicyItemConditionList);
        rangerPolicyItem.setDelegateAdmin(true);

        rangerPolicyItemList.add(rangerPolicyItem);

        RangerPolicy expectedRangerPolicy = new RangerPolicy();
        expectedRangerPolicy.setId(1L);
        expectedRangerPolicy.setName("hdfs");
        expectedRangerPolicy.setCreatedBy("rangerAdmin");
        expectedRangerPolicy.setCreateTime(date);
        expectedRangerPolicy.setDescription("hdfs policy description");
        expectedRangerPolicy.setIsAuditEnabled(true);
        expectedRangerPolicy.setResources(resourceMap);
        expectedRangerPolicy.setPolicyItems(rangerPolicyItemList);

        VXPolicy vXPolicy = new VXPolicy();
        vXPolicy.setId(1L);
        vXPolicy.setCreateDate(date);
        vXPolicy.setUpdateDate(date);
        vXPolicy.setOwner("rangerAdmin");
        vXPolicy.setUpdatedBy("rangerAdmin");
        vXPolicy.setPolicyName("hdfs");
        vXPolicy.setDescription("hdfs policy description");
        vXPolicy.setIsEnabled(true);
        vXPolicy.setIsAuditEnabled(true);
        vXPolicy.setIsRecursive(true);
        vXPolicy.setResourceName("resource");

        RangerService service = new RangerService();
        service.setId(1L);
        service.setName("hdfsService");
        service.setType("hdfs");

        List<VXPermObj> vXPermObjList = new ArrayList<VXPermObj>();
        VXPermObj vXPermObj = new VXPermObj();
        vXPermObj.setUserList(userList);
        vXPermObj.setGroupList(groupList);
        vXPermObj.setPermList(permObjList);

        vXPermObj.setIpAddress("10.129.35.86");

        vXPermObjList.add(vXPermObj);

        vXPolicy.setPermMapList(vXPermObjList);

        RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(vXPolicy, service);

        Assert.assertNotNull(actualRangerPolicy);
        Assert.assertEquals(expectedRangerPolicy.getId(), actualRangerPolicy.getId());
        Assert.assertEquals(expectedRangerPolicy.getName(), actualRangerPolicy.getName());
        Assert.assertEquals(expectedRangerPolicy.getDescription(), actualRangerPolicy.getDescription());
        Assert.assertEquals(expectedRangerPolicy.getCreatedBy(), actualRangerPolicy.getCreatedBy());
        Assert.assertTrue(actualRangerPolicy.getIsAuditEnabled());
        Assert.assertEquals(expectedRangerPolicy.getResources(), actualRangerPolicy.getResources());
        Assert.assertEquals(expectedRangerPolicy.getPolicyItems(), actualRangerPolicy.getPolicyItems());
}
 
Example 18
Source File: PatchMigration_J10002.java    From ranger with Apache License 2.0 4 votes vote down vote up
private RangerPolicy mapXResourceToPolicy(RangerPolicy policy, XXResource xRes, RangerService service) {
	String serviceName = service.getName();
	String serviceType = service.getType();
	String name = xRes.getPolicyName();
	String description = xRes.getDescription();
	Boolean isAuditEnabled = true;
	Boolean isEnabled = true;
	Map<String, RangerPolicyResource> resources = new HashMap<String, RangerPolicyResource>();
	List<RangerPolicyItem> policyItems = new ArrayList<RangerPolicyItem>();

	XXServiceDef svcDef = daoMgr.getXXServiceDef().findByName(serviceType);
	
	if(svcDef == null) {
		logger.error(serviceType + ": service-def not found. Skipping policy '" + name + "'");

		return null;
	}

	List<XXAuditMap> auditMapList = daoMgr.getXXAuditMap().findByResourceId(xRes.getId());
	if (stringUtil.isEmpty(auditMapList)) {
		isAuditEnabled = false;
	}
	if (xRes.getResourceStatus() == AppConstants.STATUS_DISABLED) {
		isEnabled = false;
	}

	Boolean isPathRecursive  = xRes.getIsRecursive() == RangerCommonEnums.BOOL_TRUE;
	Boolean isTableExcludes  = xRes.getTableType() == RangerCommonEnums.POLICY_EXCLUSION;
	Boolean isColumnExcludes = xRes.getColumnType() == RangerCommonEnums.POLICY_EXCLUSION;

	if (StringUtils.equalsIgnoreCase(serviceType, "hdfs")) {
		toRangerResourceList(xRes.getName(), "path", Boolean.FALSE, isPathRecursive, resources);
	} else if (StringUtils.equalsIgnoreCase(serviceType, "hbase")) {
		toRangerResourceList(xRes.getTables(), "table", isTableExcludes, Boolean.FALSE, resources);
		toRangerResourceList(xRes.getColumnFamilies(), "column-family", Boolean.FALSE, Boolean.FALSE, resources);
		toRangerResourceList(xRes.getColumns(), "column", isColumnExcludes, Boolean.FALSE, resources);
	} else if (StringUtils.equalsIgnoreCase(serviceType, "hive")) {
		toRangerResourceList(xRes.getDatabases(), "database", Boolean.FALSE, Boolean.FALSE, resources);
		toRangerResourceList(xRes.getTables(), "table", isTableExcludes, Boolean.FALSE, resources);
		toRangerResourceList(xRes.getColumns(), "column", isColumnExcludes, Boolean.FALSE, resources);
		toRangerResourceList(xRes.getUdfs(), "udf", Boolean.FALSE, Boolean.FALSE, resources);
	} else if (StringUtils.equalsIgnoreCase(serviceType, "knox")) {
		toRangerResourceList(xRes.getTopologies(), "topology", Boolean.FALSE, Boolean.FALSE, resources);
		toRangerResourceList(xRes.getServices(), "service", Boolean.FALSE, Boolean.FALSE, resources);
	} else if (StringUtils.equalsIgnoreCase(serviceType, "storm")) {
		toRangerResourceList(xRes.getTopologies(), "topology", Boolean.FALSE, Boolean.FALSE, resources);
	}

	policyItems = getPolicyItemListForRes(xRes, svcDef);

	policy.setService(serviceName);
	policy.setName(name);
	policy.setDescription(description);
	policy.setIsAuditEnabled(isAuditEnabled);
	policy.setIsEnabled(isEnabled);
	policy.setResources(resources);
	policy.setPolicyItems(policyItems);

	policy.setCreateTime(xRes.getCreateTime());
	policy.setUpdateTime(xRes.getUpdateTime());

	XXPortalUser createdByUser = daoMgr.getXXPortalUser().getById(xRes.getAddedByUserId());
	XXPortalUser updByUser = daoMgr.getXXPortalUser().getById(xRes.getUpdatedByUserId());

	if (createdByUser != null) {
		policy.setCreatedBy(createdByUser.getLoginId());
	}
	if (updByUser != null) {
		policy.setUpdatedBy(updByUser.getLoginId());
	}

	policy.setId(xRes.getId());

	return policy;
}
 
Example 19
Source File: PatchForKafkaServiceDefUpdate_J10025.java    From ranger with Apache License 2.0 4 votes vote down vote up
private RangerPolicy getRangerPolicy(String newResource, XXPortalUser xxPortalUser, XXService xxService) {
	RangerPolicy policy = new RangerPolicy();

	List<RangerPolicy.RangerPolicyItemAccess> accesses = getPolicyItemAccesses();
	List<String> users = new ArrayList<>(DEFAULT_POLICY_USERS);
	List<String> groups = new ArrayList<>();
	List<RangerPolicy.RangerPolicyItemCondition> conditions = new ArrayList<>();
	List<RangerPolicy.RangerPolicyItem> policyItems = new ArrayList<>();
	RangerPolicy.RangerPolicyItem rangerPolicyItem = new RangerPolicy.RangerPolicyItem();
	rangerPolicyItem.setAccesses(accesses);
	rangerPolicyItem.setConditions(conditions);
	rangerPolicyItem.setGroups(groups);
	rangerPolicyItem.setUsers(users);
	rangerPolicyItem.setDelegateAdmin(false);

	policyItems.add(rangerPolicyItem);

	Map<String, RangerPolicy.RangerPolicyResource> policyResource = new HashMap<>();
	RangerPolicy.RangerPolicyResource rangerPolicyResource = new RangerPolicy.RangerPolicyResource();
	rangerPolicyResource.setIsExcludes(false);
	rangerPolicyResource.setIsRecursive(false);
	rangerPolicyResource.setValue("*");
	String policyResourceName = KAFKA_RESOURCE_CLUSTER;
	if ("all - delegationtoken".equals(newResource)) {
		policyResourceName = KAFKA_RESOURCE_DELEGATIONTOKEN;
	}
	policyResource.put(policyResourceName, rangerPolicyResource);
	policy.setCreateTime(new Date());
	policy.setDescription(newResource);
	policy.setIsEnabled(true);
	policy.setName(newResource);
	policy.setCreatedBy(xxPortalUser.getLoginId());
	policy.setUpdatedBy(xxPortalUser.getLoginId());
	policy.setUpdateTime(new Date());
	policy.setService(xxService.getName());
	policy.setIsAuditEnabled(true);
	policy.setPolicyItems(policyItems);
	policy.setResources(policyResource);
	policy.setPolicyType(0);
	policy.setId(0L);
	policy.setGuid("");
	policy.setPolicyLabels(new ArrayList<>());
	policy.setVersion(1L);
	RangerPolicyResourceSignature resourceSignature = new RangerPolicyResourceSignature(policy);
	policy.setResourceSignature(resourceSignature.getSignature());
	return policy;
}
 
Example 20
Source File: PatchForKafkaServiceDefUpdate_J10033.java    From ranger with Apache License 2.0 4 votes vote down vote up
private RangerPolicy getRangerPolicy(String newResource, XXPortalUser xxPortalUser, XXService xxService) {
	RangerPolicy policy = new RangerPolicy();

	List<RangerPolicy.RangerPolicyItemAccess> accesses = getPolicyItemAccesses();
	List<String> users = new ArrayList<>(DEFAULT_POLICY_USERS);
	List<String> groups = new ArrayList<>(DEFAULT_POLICY_GROUP);
	List<RangerPolicy.RangerPolicyItemCondition> conditions = new ArrayList<>();
	List<RangerPolicy.RangerPolicyItem> policyItems = new ArrayList<>();
	RangerPolicy.RangerPolicyItem rangerPolicyItem = new RangerPolicy.RangerPolicyItem();
	rangerPolicyItem.setAccesses(accesses);
	rangerPolicyItem.setConditions(conditions);
	rangerPolicyItem.setGroups(groups);
	rangerPolicyItem.setUsers(users);
	rangerPolicyItem.setDelegateAdmin(false);

	policyItems.add(rangerPolicyItem);

	Map<String, RangerPolicy.RangerPolicyResource> policyResource = new HashMap<>();
	RangerPolicy.RangerPolicyResource rangerPolicyResource = new RangerPolicy.RangerPolicyResource();
	rangerPolicyResource.setIsExcludes(false);
	rangerPolicyResource.setIsRecursive(false);
	rangerPolicyResource.setValue("*");
	String policyResourceName = CONSUMERGROUP_RESOURCE_NAME;
	policyResource.put(policyResourceName, rangerPolicyResource);
	policy.setCreateTime(new Date());
	policy.setDescription(newResource);
	policy.setIsEnabled(true);
	policy.setName(newResource);
	policy.setCreatedBy(xxPortalUser.getLoginId());
	policy.setUpdatedBy(xxPortalUser.getLoginId());
	policy.setUpdateTime(new Date());
	policy.setService(xxService.getName());
	policy.setIsAuditEnabled(true);
	policy.setPolicyItems(policyItems);
	policy.setResources(policyResource);
	policy.setPolicyType(0);
	policy.setId(0L);
	policy.setGuid("");
	policy.setPolicyLabels(new ArrayList<>());
	policy.setVersion(1L);
	RangerPolicyResourceSignature resourceSignature = new RangerPolicyResourceSignature(policy);
	policy.setResourceSignature(resourceSignature.getSignature());
	return policy;
}