use of org.apache.ranger.view.VXResource in project ranger by apache.
the class TestRangerBizUtil method testHasPermission_emptyResourceName.
@Test
public void testHasPermission_emptyResourceName() {
VXResource vXResource = new VXResource();
vXResource.setAssetId(12345L);
XXPortalUser portalUser = new XXPortalUser();
portalUser.setId(id);
portalUser.setLoginId("12121");
RangerContextHolder.getSecurityContext().getUserSession().setXXPortalUser(portalUser);
XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
XXUser xxUser = new XXUser();
XXAsset xxAsset = new XXAsset();
List<XXResource> lst = new ArrayList<XXResource>();
XXResourceDao xxResourceDao = Mockito.mock(XXResourceDao.class);
XXAssetDao xxAssetDao = Mockito.mock(XXAssetDao.class);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.getById(Mockito.anyLong())).thenReturn(portalUser);
Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
Mockito.when(xxUserDao.findByUserName(Mockito.anyString())).thenReturn(xxUser);
Mockito.when(daoManager.getXXResource()).thenReturn(xxResourceDao);
Mockito.when(xxResourceDao.findByAssetIdAndResourceStatus(Mockito.anyLong(), Mockito.anyInt())).thenReturn(lst);
Mockito.when(daoManager.getXXAsset()).thenReturn(xxAssetDao);
Mockito.when(xxAssetDao.getById(Mockito.anyLong())).thenReturn(xxAsset);
VXResponse resp = rangerBizUtil.hasPermission(vXResource, AppConstants.XA_PERM_TYPE_UNKNOWN);
Mockito.verify(daoManager).getXXPortalUser();
Mockito.verify(userDao).getById(Mockito.anyLong());
Mockito.verify(daoManager).getXXUser();
Mockito.verify(xxUserDao).findByUserName(Mockito.anyString());
Assert.assertNotNull(resp);
Assert.assertEquals(VXResponse.STATUS_ERROR, resp.getStatusCode());
Assert.assertEquals("Permission Denied !", resp.getMsgDesc());
}
use of org.apache.ranger.view.VXResource in project ranger by apache.
the class XPolicyService method mapToVXPolicyList.
public VXPolicyList mapToVXPolicyList(VXResourceList vXResourceList) {
List<VXPolicy> policyList = new ArrayList<VXPolicy>();
for (VXResource vXAsset : vXResourceList.getVXResources()) {
VXPolicy vXRepo = mapXAToPublicObject(vXAsset);
policyList.add(vXRepo);
}
VXPolicyList vXPolicyList = new VXPolicyList(policyList);
return vXPolicyList;
}
use of org.apache.ranger.view.VXResource in project ranger by apache.
the class XPolicyService method getResourceType.
public int getResourceType(VXDataObject vObj) {
int resourceType = AppConstants.RESOURCE_PATH;
if (vObj == null) {
return resourceType;
}
VXPolicy vXPolicy = null;
VXResource vXResource = null;
if (vObj instanceof VXPolicy) {
vXPolicy = (VXPolicy) vObj;
} else if (vObj instanceof VXResource) {
vXResource = (VXResource) vObj;
} else {
return resourceType;
}
String databases = null;
String tables = null;
String columns = null;
String udfs = null;
String columnFamilies = null;
String topologies = null;
String services = null;
if (vXPolicy != null) {
databases = vXPolicy.getDatabases();
tables = vXPolicy.getTables();
columns = vXPolicy.getColumns();
udfs = vXPolicy.getUdfs();
columnFamilies = vXPolicy.getColumnFamilies();
topologies = vXPolicy.getTopologies();
services = vXPolicy.getServices();
} else if (vXResource != null) {
databases = vXResource.getDatabases();
tables = vXResource.getTables();
columns = vXResource.getColumns();
udfs = vXResource.getUdfs();
columnFamilies = vXResource.getColumnFamilies();
topologies = vXResource.getTopologies();
services = vXResource.getServices();
}
if (!stringUtil.isEmpty(databases)) {
resourceType = AppConstants.RESOURCE_DB;
if (!stringUtil.isEmptyOrWildcardAsterisk(tables)) {
resourceType = AppConstants.RESOURCE_TABLE;
}
if (!stringUtil.isEmptyOrWildcardAsterisk(columns)) {
resourceType = AppConstants.RESOURCE_COLUMN;
}
if (!stringUtil.isEmpty(udfs)) {
resourceType = AppConstants.RESOURCE_UDF;
}
} else if (!stringUtil.isEmpty(tables)) {
resourceType = AppConstants.RESOURCE_TABLE;
if (!stringUtil.isEmptyOrWildcardAsterisk(columnFamilies)) {
resourceType = AppConstants.RESOURCE_COL_FAM;
}
if (!stringUtil.isEmptyOrWildcardAsterisk(columns)) {
resourceType = AppConstants.RESOURCE_COLUMN;
}
} else if (!stringUtil.isEmpty(topologies)) {
resourceType = AppConstants.RESOURCE_TOPOLOGY;
if (!stringUtil.isEmptyOrWildcardAsterisk(services)) {
resourceType = AppConstants.RESOURCE_SERVICE_NAME;
}
}
return resourceType;
}
use of org.apache.ranger.view.VXResource in project ranger by apache.
the class XResourceService method populatePageList.
private void populatePageList(List<XXResource> resourceList, int startIndex, int pageSize, VXResourceList vxResourceList) {
List<VXResource> onePageList = new ArrayList<VXResource>();
for (int i = startIndex; i < pageSize + startIndex && i < resourceList.size(); i++) {
VXResource vXResource = populateViewBean(resourceList.get(i));
onePageList.add(vXResource);
}
vxResourceList.setVXResources(onePageList);
vxResourceList.setStartIndex(startIndex);
vxResourceList.setPageSize(pageSize);
vxResourceList.setResultSize(onePageList.size());
vxResourceList.setTotalCount(resourceList.size());
}
use of org.apache.ranger.view.VXResource in project ranger by apache.
the class ServiceUtil method toVXResource.
public VXResource toVXResource(RangerPolicy policy, RangerService service) {
if (policy == null || service == null || toAssetType(service.getType()) == null) {
return null;
}
VXResource ret = new VXResource();
rangerObjectToDataObject(policy, ret);
ret.setAssetName(policy.getService());
ret.setAssetId(service.getId());
ret.setAssetType(toAssetType(service.getType()));
ret.setPolicyName(policy.getName());
ret.setDescription(policy.getDescription());
ret.setGuid(policy.getGuid());
ret.setResourceStatus(policy.getIsEnabled() ? RangerCommonEnums.STATUS_ENABLED : RangerCommonEnums.STATUS_DISABLED);
List<VXAuditMap> auditList = null;
if (policy.getIsAuditEnabled()) {
VXAuditMap auditMap = new VXAuditMap();
auditMap.setResourceId(policy.getId());
auditMap.setAuditType(AppConstants.XA_AUDIT_TYPE_ALL);
auditList = new ArrayList<VXAuditMap>();
auditList.add(auditMap);
}
ret.setAuditList(auditList);
for (Map.Entry<String, RangerPolicy.RangerPolicyResource> e : policy.getResources().entrySet()) {
RangerPolicy.RangerPolicyResource res = e.getValue();
String resType = e.getKey();
String resString = getResourceString(res.getValues());
if ("path".equalsIgnoreCase(resType)) {
ret.setName(resString);
ret.setIsRecursive(Boolean.TRUE.equals(res.getIsRecursive()) ? RangerCommonEnums.BOOL_TRUE : RangerCommonEnums.BOOL_FALSE);
} else if ("table".equalsIgnoreCase(resType)) {
ret.setTables(resString);
ret.setTableType(Boolean.TRUE.equals(res.getIsExcludes()) ? RangerCommonEnums.POLICY_EXCLUSION : RangerCommonEnums.POLICY_INCLUSION);
} else if ("column-family".equalsIgnoreCase(resType)) {
ret.setColumnFamilies(resString);
} else if ("column".equalsIgnoreCase(resType)) {
ret.setColumns(resString);
ret.setColumnType(Boolean.TRUE.equals(res.getIsExcludes()) ? RangerCommonEnums.POLICY_EXCLUSION : RangerCommonEnums.POLICY_INCLUSION);
} else if ("database".equalsIgnoreCase(resType)) {
ret.setDatabases(resString);
} else if ("udf".equalsIgnoreCase(resType)) {
ret.setUdfs(resString);
} else if ("topology".equalsIgnoreCase(resType)) {
ret.setTopologies(resString);
} else if ("service".equalsIgnoreCase(resType)) {
ret.setServices(resString);
}
}
updateResourceName(ret);
List<VXPermMap> permMapList = getVXPermMapList(policy);
ret.setPermMapList(permMapList);
return ret;
}
Aggregations