use of org.apache.ranger.view.VXPolicy 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.VXPolicy in project ranger by apache.
the class XPolicyService method mapXAToPublicObject.
public VXPolicy mapXAToPublicObject(VXResource vXResource) {
VXPolicy vXPolicy = new VXPolicy();
vXPolicy = super.mapBaseAttributesToPublicObject(vXResource, vXPolicy);
vXPolicy.setPolicyName(StringUtils.trim(vXResource.getPolicyName()));
vXPolicy.setResourceName(vXResource.getName());
vXPolicy.setDescription(vXResource.getDescription());
vXPolicy.setRepositoryName(vXResource.getAssetName());
vXPolicy.setRepositoryType(AppConstants.getLabelFor_AssetType(vXResource.getAssetType()));
List<VXPermObj> permObjList = mapPermMapToPermObj(vXResource.getPermMapList());
if (!stringUtil.isEmpty(permObjList)) {
vXPolicy.setPermMapList(permObjList);
}
vXPolicy.setTables(vXResource.getTables());
vXPolicy.setColumnFamilies(vXResource.getColumnFamilies());
vXPolicy.setColumns(vXResource.getColumns());
vXPolicy.setDatabases(vXResource.getDatabases());
vXPolicy.setUdfs(vXResource.getUdfs());
vXPolicy.setTopologies(vXResource.getTopologies());
vXPolicy.setServices(vXResource.getServices());
boolean enable = true;
if (vXResource.getResourceStatus() == AppConstants.STATUS_DISABLED || vXResource.getResourceStatus() == AppConstants.STATUS_DELETED) {
enable = false;
}
vXPolicy.setIsEnabled(enable);
boolean auditEnable = true;
if (stringUtil.isEmpty(vXResource.getAuditList())) {
auditEnable = false;
}
vXPolicy.setIsAuditEnabled(auditEnable);
vXPolicy.setVersion(version);
/*
* TODO : These parameters are specific for some components. Need to
* take care while adding new component
*/
if (vXResource.getAssetType() == AppConstants.ASSET_HIVE) {
vXPolicy.setTableType(AppConstants.getLabelFor_PolicyType(vXResource.getTableType()));
vXPolicy.setColumnType(AppConstants.getLabelFor_PolicyType(vXResource.getColumnType()));
}
if (vXResource.getAssetType() == AppConstants.ASSET_HDFS) {
vXPolicy.setIsRecursive(AppConstants.getBooleanFor_BooleanValue(vXResource.getIsRecursive()));
} else {
vXPolicy.setIsRecursive(null);
}
return vXPolicy;
}
use of org.apache.ranger.view.VXPolicy in project ranger by apache.
the class ServiceUtil method rangerPolicyListToPublic.
public VXPolicyList rangerPolicyListToPublic(List<RangerPolicy> rangerPolicyList, SearchFilter filter) {
RangerService service = null;
List<VXPolicy> vXPolicyList = new ArrayList<VXPolicy>();
VXPolicyList vXPolicyListObj = new VXPolicyList(new ArrayList<VXPolicy>());
if (CollectionUtils.isNotEmpty(rangerPolicyList)) {
int totalCount = rangerPolicyList.size();
int startIndex = filter.getStartIndex();
int pageSize = filter.getMaxRows();
int toIndex = Math.min(startIndex + pageSize, totalCount);
String sortType = filter.getSortType();
String sortBy = filter.getSortBy();
for (int i = startIndex; i < toIndex; i++) {
RangerPolicy policy = rangerPolicyList.get(i);
try {
service = svcStore.getServiceByName(policy.getService());
} catch (Exception excp) {
throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(), true);
}
if (service == null) {
throw restErrorUtil.createRESTException(HttpServletResponse.SC_NOT_FOUND, RangerServiceNotFoundException.buildExceptionMsg(policy.getService()), true);
}
VXPolicy vXPolicy = toVXPolicy(policy, service);
if (vXPolicy != null) {
vXPolicyList.add(vXPolicy);
}
}
vXPolicyListObj = new VXPolicyList(vXPolicyList);
vXPolicyListObj.setPageSize(pageSize);
vXPolicyListObj.setResultSize(vXPolicyList.size());
vXPolicyListObj.setStartIndex(startIndex);
vXPolicyListObj.setTotalCount(totalCount);
vXPolicyListObj.setSortBy(sortBy);
vXPolicyListObj.setSortType(sortType);
}
return vXPolicyListObj;
}
use of org.apache.ranger.view.VXPolicy in project ranger by apache.
the class TestAssetREST method testRevokePermission.
@Test
public void testRevokePermission() {
RangerPolicy policy = rangerPolicy(Id);
RangerService service = rangerService(Id);
VXPolicy vXPolicy = vXPolicy(policy, service);
GrantRevokeRequest grantRequestObj = new GrantRevokeRequest();
grantRequestObj.setAccessTypes(null);
grantRequestObj.setDelegateAdmin(true);
grantRequestObj.setEnableAudit(true);
grantRequestObj.setGrantor("read");
grantRequestObj.setIsRecursive(true);
RESTResponse response = Mockito.mock(RESTResponse.class);
Mockito.when(serviceUtil.toGrantRevokeRequest(vXPolicy)).thenReturn(grantRequestObj);
try {
Mockito.when(serviceREST.revokeAccess(vXPolicy.getRepositoryName(), grantRequestObj, request)).thenReturn(response);
} catch (Exception e) {
fail("test failed due to: " + e.getMessage());
}
VXPolicy expectedVXPolicy = assetREST.revokePermission(request, vXPolicy);
Assert.assertEquals(vXPolicy, expectedVXPolicy);
Mockito.verify(serviceUtil).toGrantRevokeRequest(vXPolicy);
try {
Mockito.verify(serviceREST).revokeAccess(vXPolicy.getRepositoryName(), grantRequestObj, request);
} catch (Exception e) {
fail("test failed due to: " + e.getMessage());
}
}
use of org.apache.ranger.view.VXPolicy in project ranger by apache.
the class TestAssetREST method testGrantPermission.
@Test
public void testGrantPermission() {
RangerPolicy policy = rangerPolicy(Id);
RangerService service = rangerService(Id);
VXPolicy vXPolicy = vXPolicy(policy, service);
GrantRevokeRequest grantRequestObj = new GrantRevokeRequest();
grantRequestObj.setAccessTypes(null);
grantRequestObj.setDelegateAdmin(true);
grantRequestObj.setEnableAudit(true);
grantRequestObj.setGrantor("read");
grantRequestObj.setIsRecursive(true);
RESTResponse response = Mockito.mock(RESTResponse.class);
Mockito.when(serviceUtil.toGrantRevokeRequest(vXPolicy)).thenReturn(grantRequestObj);
try {
Mockito.when(serviceREST.grantAccess(vXPolicy.getRepositoryName(), grantRequestObj, request)).thenReturn(response);
} catch (Exception e) {
fail("test failed due to: " + e.getMessage());
}
VXPolicy expectedVXPolicy = assetREST.grantPermission(request, vXPolicy);
Assert.assertEquals(vXPolicy, expectedVXPolicy);
Mockito.verify(serviceUtil).toGrantRevokeRequest(vXPolicy);
try {
Mockito.verify(serviceREST).grantAccess(vXPolicy.getRepositoryName(), grantRequestObj, request);
} catch (Exception e) {
fail("test failed due to: " + e.getMessage());
}
}
Aggregations