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

The following examples show how to use org.apache.ranger.plugin.model.RangerPolicy#setService() . 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: RangerServiceHive.java    From ranger with Apache License 2.0 5 votes vote down vote up
private RangerPolicy createDefaultDBPolicy() {
	RangerPolicy defaultDBPolicy = new RangerPolicy();

	defaultDBPolicy.setName(DEFAULT_DB_POLICYNAME);
	defaultDBPolicy.setService(serviceName);
	defaultDBPolicy.setResources(createDefaultDBPolicyResource());
	defaultDBPolicy.setPolicyItems(createDefaultDBPolicyItem());

	return defaultDBPolicy;
}
 
Example 2
Source File: RangerServiceHive.java    From ranger with Apache License 2.0 5 votes vote down vote up
private RangerPolicy createInformationSchemaPolicy() {
	RangerPolicy informationSchemaPolicy = new RangerPolicy();

	informationSchemaPolicy.setName(INFORMATION_SCHEMA_DB_POLICYNAME);
	informationSchemaPolicy.setService(serviceName);
	informationSchemaPolicy.setResources(createInformationSchemaPolicyResource());
	informationSchemaPolicy.setPolicyItems(createInformationSchemaPolicyItem());

	return informationSchemaPolicy;
}
 
Example 3
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 4
Source File: RangerServiceAtlas.java    From ranger with Apache License 2.0 5 votes vote down vote up
private RangerPolicy getSearchFeaturePolicy() {
	RangerPolicy searchFeaturePolicy = new RangerPolicy();

	searchFeaturePolicy.setName(SEARCH_FEATURE_POLICY_NAME);
	searchFeaturePolicy.setService(serviceName);
	searchFeaturePolicy.setResources(getSearchFeaturePolicyResource());
	searchFeaturePolicy.setPolicyItems(getSearchFeaturePolicyItem());

	return searchFeaturePolicy;
}
 
Example 5
Source File: TestAssetREST.java    From ranger with Apache License 2.0 5 votes vote down vote up
private RangerPolicy rangerPolicy(Long id) {
	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 6
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 7
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 8
Source File: TestRangerPolicyService.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.setPolicyType(0);

	return policy;
}
 
Example 9
Source File: TestServiceREST.java    From ranger with Apache License 2.0 5 votes vote down vote up
@Test
public void test30getPolicyFromEventTime() throws Exception {
	HttpServletRequest request = Mockito.mock(HttpServletRequest.class);

	String strdt = new Date().toString();
	String userName="Admin";
	Set<String> userGroupsList = new HashSet<String>();
	userGroupsList.add("group1");
	userGroupsList.add("group2");
	Mockito.when(request.getParameter("eventTime")).thenReturn(strdt);
	Mockito.when(request.getParameter("policyId")).thenReturn("1");
	Mockito.when(request.getParameter("versionNo")).thenReturn("1");
	RangerPolicy policy=new RangerPolicy();
	Map<String, RangerPolicyResource> resources=new HashMap<String, RangerPolicy.RangerPolicyResource>();
	policy.setService("services");
	policy.setResources(resources);
	Mockito.when(svcStore.getPolicyFromEventTime(strdt, 1l)).thenReturn(policy);
	Mockito.when(bizUtil.isAdmin()).thenReturn(false);
	Mockito.when(bizUtil.getCurrentUserLoginId()).thenReturn(userName);

	Mockito.when(restErrorUtil.createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean()))
			.thenThrow(new WebApplicationException());
	thrown.expect(WebApplicationException.class);

	RangerPolicy dbRangerPolicy = serviceREST
			.getPolicyFromEventTime(request);
	Assert.assertNull(dbRangerPolicy);
	Mockito.verify(request).getParameter("eventTime");
	Mockito.verify(request).getParameter("policyId");
	Mockito.verify(request).getParameter("versionNo");
}
 
Example 10
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 11
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 12
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 13
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 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 testToRangerPolicyForResourceTypeService(){

        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("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(false);
        rangerPolicyResource.setIsRecursive(false);
        rangerPolicyResource.setValue("service");
        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("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 16
Source File: TestServiceUtil.java    From ranger with Apache License 2.0 4 votes vote down vote up
@Test
public void testToVXResourceForTablesColumnsAndDatabase(){
        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("/myDatabase/myTable/myColumn");
        expectedVXResource.setTables("myTable");
        expectedVXResource.setDatabases("myDatabase");
        expectedVXResource.setColumns("myColumn");
        expectedVXResource.setGuid(guidString);
        expectedVXResource.setPolicyName("hive Policy");
        expectedVXResource.setDescription("hive policy description");
        expectedVXResource.setResourceType(1);
        expectedVXResource.setAssetName("hive");
        expectedVXResource.setAssetType(3);
        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> valuesListForDatabase = new ArrayList<String>();
        valuesListForDatabase.add("myDatabase");

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

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

        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("column");
        rangerPolicyResourceForColumn.setValues(valuesListForColumn);

        rangerPolicyResourceMap.put("column", rangerPolicyResourceForColumn);

        RangerPolicyResource rangerPolicyResourceForDatabase = new RangerPolicyResource();
        rangerPolicyResourceForDatabase.setIsExcludes(true);
        rangerPolicyResourceForDatabase.setIsRecursive(true);
        rangerPolicyResourceForDatabase.setValue("database");
        rangerPolicyResourceForDatabase.setValues(valuesListForDatabase);

        rangerPolicyResourceMap.put("database", rangerPolicyResourceForDatabase);


        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.getDatabases(), actualVXResource.getDatabases());
        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 17
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 18
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 19
Source File: TestServiceUtil.java    From ranger with Apache License 2.0 4 votes vote down vote up
@Test
public void testToVXResourceForPath(){
        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("resource");
        expectedVXResource.setGuid(guidString);
        expectedVXResource.setPolicyName("hdfs Policy");
        expectedVXResource.setDescription("hdfs policy description");
        expectedVXResource.setResourceType(1);
        expectedVXResource.setAssetName("hdfs");
        expectedVXResource.setAssetType(1);
        expectedVXResource.setAuditList(auditList);

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

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

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

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

        rangerPolicyResourceMap.put("path", rangerPolicyResource);


        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.getAuditList().get(0).getResourceId(), actualVXResource.getAuditList().get(0).getResourceId());
        Assert.assertEquals(expectedVXResource.getAuditList().get(0).getAuditType(), actualVXResource.getAuditList().get(0).getAuditType());


}
 
Example 20
Source File: TestServiceUtil.java    From ranger with Apache License 2.0 4 votes vote down vote up
@Test
public void testToVXResourceForTopologyAndService(){
        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("/myTopology/myService");
        expectedVXResource.setTopologies("myTopology");
        expectedVXResource.setServices("myService");
        expectedVXResource.setGuid(guidString);
        expectedVXResource.setPolicyName("knox Policy");
        expectedVXResource.setDescription("knox policy description");
        expectedVXResource.setResourceType(1);
        expectedVXResource.setAssetName("knox");
        expectedVXResource.setAssetType(5);
        expectedVXResource.setResourceStatus(1);
        expectedVXResource.setAuditList(auditList);

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

        List<String> valuesListForService = new ArrayList<String>();
        valuesListForService.add("myService");

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

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

        RangerPolicyResource rangerPolicyResourceForTopology = new RangerPolicyResource();
        rangerPolicyResourceForTopology.setValue("topology");
        rangerPolicyResourceForTopology.setValues(valuesListForTopology);

        rangerPolicyResourceMap.put("topology", rangerPolicyResourceForTopology);

        RangerPolicyResource rangerPolicyResourceForService = new RangerPolicyResource();
        rangerPolicyResourceForService.setValue("service");
        rangerPolicyResourceForService.setValues(valuesListForService);

        rangerPolicyResourceMap.put("service", rangerPolicyResourceForService);

        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.getTopologies(), actualVXResource.getTopologies());
        Assert.assertEquals(expectedVXResource.getServices(), actualVXResource.getServices());
        Assert.assertEquals(expectedVXResource.getAuditList().get(0).getResourceId(), actualVXResource.getAuditList().get(0).getResourceId());
        Assert.assertEquals(expectedVXResource.getAuditList().get(0).getAuditType(), actualVXResource.getAuditList().get(0).getAuditType());


}