Search in sources :

Example 6 with VXPolicy

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;
}
Also used : VXPolicy(org.apache.ranger.view.VXPolicy) VXResource(org.apache.ranger.view.VXResource)

Example 7 with VXPolicy

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;
}
Also used : VXPolicy(org.apache.ranger.view.VXPolicy) VXPermObj(org.apache.ranger.view.VXPermObj)

Example 8 with 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;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXPolicyList(org.apache.ranger.view.VXPolicyList) VXPolicy(org.apache.ranger.view.VXPolicy) ArrayList(java.util.ArrayList) RangerService(org.apache.ranger.plugin.model.RangerService) RangerServiceNotFoundException(org.apache.ranger.plugin.util.RangerServiceNotFoundException) InvalidNameException(javax.naming.InvalidNameException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 9 with VXPolicy

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());
    }
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RESTResponse(org.apache.ranger.admin.client.datatype.RESTResponse) VXPolicy(org.apache.ranger.view.VXPolicy) RangerService(org.apache.ranger.plugin.model.RangerService) GrantRevokeRequest(org.apache.ranger.plugin.util.GrantRevokeRequest) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 10 with VXPolicy

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());
    }
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RESTResponse(org.apache.ranger.admin.client.datatype.RESTResponse) VXPolicy(org.apache.ranger.view.VXPolicy) RangerService(org.apache.ranger.plugin.model.RangerService) GrantRevokeRequest(org.apache.ranger.plugin.util.GrantRevokeRequest) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Aggregations

VXPolicy (org.apache.ranger.view.VXPolicy)16 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)11 RangerService (org.apache.ranger.plugin.model.RangerService)10 Test (org.junit.Test)9 WebApplicationException (javax.ws.rs.WebApplicationException)5 ArrayList (java.util.ArrayList)4 GrantRevokeRequest (org.apache.ranger.plugin.util.GrantRevokeRequest)4 VXPolicyList (org.apache.ranger.view.VXPolicyList)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 RESTResponse (org.apache.ranger.admin.client.datatype.RESTResponse)2 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)2 VXPermObj (org.apache.ranger.view.VXPermObj)2 VXResource (org.apache.ranger.view.VXResource)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 InvalidNameException (javax.naming.InvalidNameException)1 XXPolicyDao (org.apache.ranger.db.XXPolicyDao)1 XXPolicy (org.apache.ranger.entity.XXPolicy)1 RangerServiceNotFoundException (org.apache.ranger.plugin.util.RangerServiceNotFoundException)1 VXAuditMap (org.apache.ranger.view.VXAuditMap)1