Search in sources :

Example 11 with VXResource

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());
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXUser(org.apache.ranger.entity.XXUser) XXAssetDao(org.apache.ranger.db.XXAssetDao) XXResource(org.apache.ranger.entity.XXResource) XXUserDao(org.apache.ranger.db.XXUserDao) VXResource(org.apache.ranger.view.VXResource) XXAsset(org.apache.ranger.entity.XXAsset) ArrayList(java.util.ArrayList) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) XXResourceDao(org.apache.ranger.db.XXResourceDao) Test(org.junit.Test)

Example 12 with VXResource

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

Example 13 with VXResource

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

Example 14 with VXResource

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

Example 15 with VXResource

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;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXPermMap(org.apache.ranger.view.VXPermMap) VXResource(org.apache.ranger.view.VXResource) VXAuditMap(org.apache.ranger.view.VXAuditMap) VXAuditMap(org.apache.ranger.view.VXAuditMap) VXPermMap(org.apache.ranger.view.VXPermMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

VXResource (org.apache.ranger.view.VXResource)28 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)9 VXResponse (org.apache.ranger.view.VXResponse)7 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)6 VXAuditMap (org.apache.ranger.view.VXAuditMap)6 VXPermMap (org.apache.ranger.view.VXPermMap)6 RangerService (org.apache.ranger.plugin.model.RangerService)5 VXResourceList (org.apache.ranger.view.VXResourceList)5 XXResource (org.apache.ranger.entity.XXResource)3 List (java.util.List)2 UserSessionBase (org.apache.ranger.common.UserSessionBase)2 XXAsset (org.apache.ranger.entity.XXAsset)2 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)2 VXPolicy (org.apache.ranger.view.VXPolicy)2 VXPolicyList (org.apache.ranger.view.VXPolicyList)2 File (java.io.File)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1