Search in sources :

Example 36 with VXAuditMap

use of org.apache.ranger.view.VXAuditMap in project ranger by apache.

the class XPolicyService method mapPublicToXAObject.

public VXResource mapPublicToXAObject(VXPolicy vXPolicy, int operationContext) {
    VXResource vXResource = new VXResource();
    vXResource = super.mapBaseAttributesToXAObject(vXPolicy, vXResource);
    vXResource.setName(vXPolicy.getResourceName());
    vXResource.setPolicyName(StringUtils.trim(vXPolicy.getPolicyName()));
    vXResource.setDescription(vXPolicy.getDescription());
    vXResource.setResourceType(getResourceType(vXPolicy));
    XXAsset xAsset = xaDaoMgr.getXXAsset().findByAssetName(vXPolicy.getRepositoryName());
    if (xAsset == null) {
        throw restErrorUtil.createRESTException("The repository for which " + "you're updating policy, doesn't exist.", MessageEnums.INVALID_INPUT_DATA);
    }
    vXResource.setAssetId(xAsset.getId());
    if (operationContext == AbstractBaseResourceService.OPERATION_UPDATE_CONTEXT) {
        XXResource xxResource = xaDaoMgr.getXXResource().getById(vXPolicy.getId());
        if (xxResource == null) {
            logger.error("No policy found with given Id : " + vXPolicy.getId());
            throw restErrorUtil.createRESTException("No Policy found with given Id : " + vXResource.getId(), MessageEnums.DATA_NOT_FOUND);
        }
        /*
			 * While updating public object we wont have createDate/updateDate,
			 * so create time, addedById, updatedById, etc. we ll have to take
			 * from existing object
			 */
        xxResource.setUpdateTime(DateUtil.getUTCDate());
        xResourceService.mapBaseAttributesToViewBean(xxResource, vXResource);
        SearchCriteria scAuditMap = new SearchCriteria();
        scAuditMap.addParam("resourceId", xxResource.getId());
        VXAuditMapList vXAuditMapList = xAuditMapService.searchXAuditMaps(scAuditMap);
        List<VXAuditMap> auditList = new ArrayList<VXAuditMap>();
        if (vXAuditMapList.getListSize() > 0 && vXPolicy.getIsAuditEnabled()) {
            auditList.addAll(vXAuditMapList.getVXAuditMaps());
        } else if (vXAuditMapList.getListSize() == 0 && vXPolicy.getIsAuditEnabled()) {
            VXAuditMap vXAuditMap = new VXAuditMap();
            vXAuditMap.setAuditType(AppConstants.XA_AUDIT_TYPE_ALL);
            auditList.add(vXAuditMap);
        }
        List<VXPermMap> permMapList = mapPermObjToPermList(vXPolicy.getPermMapList(), vXPolicy);
        vXResource.setAuditList(auditList);
        vXResource.setPermMapList(permMapList);
    } else if (operationContext == AbstractBaseResourceService.OPERATION_CREATE_CONTEXT) {
        if (vXPolicy.getIsAuditEnabled()) {
            VXAuditMap vXAuditMap = new VXAuditMap();
            vXAuditMap.setAuditType(AppConstants.XA_AUDIT_TYPE_ALL);
            List<VXAuditMap> auditList = new ArrayList<VXAuditMap>();
            auditList.add(vXAuditMap);
            vXResource.setAuditList(auditList);
        }
        if (!stringUtil.isEmpty(vXPolicy.getPermMapList())) {
            List<VXPermMap> permMapList = mapPermObjToPermList(vXPolicy.getPermMapList());
            vXResource.setPermMapList(permMapList);
        }
    }
    vXResource.setDatabases(vXPolicy.getDatabases());
    vXResource.setTables(vXPolicy.getTables());
    vXResource.setColumnFamilies(vXPolicy.getColumnFamilies());
    vXResource.setColumns(vXPolicy.getColumns());
    vXResource.setUdfs(vXPolicy.getUdfs());
    vXResource.setAssetName(vXPolicy.getRepositoryName());
    int assetType = AppConstants.getEnumFor_AssetType(vXPolicy.getRepositoryType());
    if (assetType == AppConstants.ASSET_UNKNOWN) {
        assetType = xAsset.getAssetType();
        vXPolicy.setRepositoryType(AppConstants.getLabelFor_AssetType(assetType));
    }
    vXResource.setAssetType(assetType);
    int resourceStatus = AppConstants.STATUS_ENABLED;
    if (!vXPolicy.getIsEnabled()) {
        resourceStatus = AppConstants.STATUS_DISABLED;
    }
    vXResource.setResourceStatus(resourceStatus);
    // Allowing to create policy without checking parent permission
    vXResource.setCheckParentPermission(AppConstants.BOOL_FALSE);
    vXResource.setTopologies(vXPolicy.getTopologies());
    vXResource.setServices(vXPolicy.getServices());
    /*
		 * TODO : These parameters are specific for some components. Need to
		 * take care while adding new component
		 */
    if (vXPolicy.getRepositoryType().equalsIgnoreCase(AppConstants.getLabelFor_AssetType(AppConstants.ASSET_HIVE))) {
        vXResource.setTableType(AppConstants.getEnumFor_PolicyType(vXPolicy.getTableType()));
        vXResource.setColumnType(AppConstants.getEnumFor_PolicyType(vXPolicy.getColumnType()));
    }
    if (vXPolicy.getRepositoryType().equalsIgnoreCase(AppConstants.getLabelFor_AssetType(AppConstants.ASSET_HDFS))) {
        vXResource.setIsRecursive(AppConstants.getEnumFor_BooleanValue(vXPolicy.getIsRecursive()));
    }
    return vXResource;
}
Also used : VXPermMap(org.apache.ranger.view.VXPermMap) XXResource(org.apache.ranger.entity.XXResource) VXResource(org.apache.ranger.view.VXResource) XXAsset(org.apache.ranger.entity.XXAsset) ArrayList(java.util.ArrayList) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) SearchCriteria(org.apache.ranger.common.SearchCriteria) VXAuditMap(org.apache.ranger.view.VXAuditMap) VXResourceList(org.apache.ranger.view.VXResourceList) ArrayList(java.util.ArrayList) VXPolicyList(org.apache.ranger.view.VXPolicyList) VXPermMapList(org.apache.ranger.view.VXPermMapList) List(java.util.List) VXAuditMapList(org.apache.ranger.view.VXAuditMapList)

Example 37 with VXAuditMap

use of org.apache.ranger.view.VXAuditMap in project ranger by apache.

the class XResourceService method populateAuditList.

private void populateAuditList(VXResource vXResource) {
    List<XXAuditMap> xAuditMapList = daoManager.getXXAuditMap().findByResourceId(vXResource.getId());
    List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>();
    for (XXAuditMap xAuditMap : xAuditMapList) {
        vXAuditMapList.add(xAuditMapService.populateViewBean(xAuditMap));
    }
    vXResource.setAuditList(vXAuditMapList);
}
Also used : ArrayList(java.util.ArrayList) VXAuditMap(org.apache.ranger.view.VXAuditMap) XXAuditMap(org.apache.ranger.entity.XXAuditMap)

Example 38 with VXAuditMap

use of org.apache.ranger.view.VXAuditMap in project ranger by apache.

the class XResourceService method createResource.

@Override
public VXResource createResource(VXResource vXResource) {
    VXResource resource = super.createResource(vXResource);
    List<VXAuditMap> newAuditMapList = new ArrayList<VXAuditMap>();
    List<VXAuditMap> vxAuditMapList = vXResource.getAuditList();
    if (vxAuditMapList != null) {
        for (VXAuditMap vxAuditMap : vxAuditMapList) {
            vxAuditMap.setResourceId(resource.getId());
            vxAuditMap = xAuditMapService.createResource(vxAuditMap);
            newAuditMapList.add(vxAuditMap);
        }
    }
    List<VXPermMap> newPermMapList = new ArrayList<VXPermMap>();
    List<VXPermMap> vxPermMapList = vXResource.getPermMapList();
    if (vxPermMapList != null) {
        for (VXPermMap permMap : vxPermMapList) {
            if (permMap.getUserId() == null && permMap.getGroupId() == null && vxAuditMapList == null) {
                if (vxAuditMapList == null) {
                    throw restErrorUtil.createRESTException("Please provide" + " valid group/user permissions for policy.", MessageEnums.INVALID_INPUT_DATA);
                }
            } else {
                permMap.setResourceId(resource.getId());
                permMap = xPermMapService.createResource(permMap);
                newPermMapList.add(permMap);
            }
        }
    }
    resource.setPermMapList(newPermMapList);
    resource.setAuditList(newAuditMapList);
    return resource;
}
Also used : VXPermMap(org.apache.ranger.view.VXPermMap) VXResource(org.apache.ranger.view.VXResource) ArrayList(java.util.ArrayList) VXAuditMap(org.apache.ranger.view.VXAuditMap)

Example 39 with VXAuditMap

use of org.apache.ranger.view.VXAuditMap in project ranger by apache.

the class TestXUserREST method test57updateXAuditMapNull.

@Test
public void test57updateXAuditMapNull() {
    VXAuditMap testvXAuditMap = createVXAuditMapObj();
    Mockito.when(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any())).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    VXAuditMap retvXAuditMap = xUserRest.updateXAuditMap(testvXAuditMap);
    assertNull(retvXAuditMap);
    Mockito.verify(xUserMgr).updateXAuditMap(testvXAuditMap);
    Mockito.verify(xResourceService).readResource(null);
    Mockito.verify(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any()));
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) MessageEnums(org.apache.ranger.common.MessageEnums) VXAuditMap(org.apache.ranger.view.VXAuditMap) Test(org.junit.Test)

Example 40 with VXAuditMap

use of org.apache.ranger.view.VXAuditMap in project ranger by apache.

the class TestXUserREST method test60searchXAuditMaps.

@SuppressWarnings("unchecked")
@Test
public void test60searchXAuditMaps() {
    VXAuditMap testvXAuditMap = createVXAuditMapObj();
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    SearchCriteria testSearchCriteria = createsearchCriteria();
    Mockito.when(searchUtil.extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any())).thenReturn(testSearchCriteria);
    List<VXAuditMap> testvXAuditMaps = new ArrayList<VXAuditMap>();
    testvXAuditMaps.add(testvXAuditMap);
    VXAuditMapList testVXAuditMapList = new VXAuditMapList();
    testVXAuditMapList.setVXAuditMaps(testvXAuditMaps);
    Mockito.when(xUserMgr.searchXAuditMaps(testSearchCriteria)).thenReturn(testVXAuditMapList);
    VXAuditMapList outputVXAuditMapList = xUserRest.searchXAuditMaps(request);
    Mockito.verify(xUserMgr).searchXAuditMaps(testSearchCriteria);
    Mockito.verify(searchUtil).extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any());
    assertNotNull(outputVXAuditMapList);
    assertEquals(outputVXAuditMapList.getClass(), testVXAuditMapList.getClass());
    assertEquals(outputVXAuditMapList.getResultSize(), testVXAuditMapList.getResultSize());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ArrayList(java.util.ArrayList) VXAuditMap(org.apache.ranger.view.VXAuditMap) SortField(org.apache.ranger.common.SortField) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) SearchCriteria(org.apache.ranger.common.SearchCriteria) Test(org.junit.Test)

Aggregations

VXAuditMap (org.apache.ranger.view.VXAuditMap)45 Test (org.junit.Test)37 ArrayList (java.util.ArrayList)31 VXResource (org.apache.ranger.view.VXResource)24 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)19 HashMap (java.util.HashMap)16 RangerService (org.apache.ranger.plugin.model.RangerService)16 RangerPolicyResource (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)15 VXPermMap (org.apache.ranger.view.VXPermMap)14 VXAuditMapList (org.apache.ranger.view.VXAuditMapList)13 Date (java.util.Date)12 WebApplicationException (javax.ws.rs.WebApplicationException)9 VXPermMapList (org.apache.ranger.view.VXPermMapList)9 XXPolicy (org.apache.ranger.entity.XXPolicy)8 XXUser (org.apache.ranger.entity.XXUser)6 XXUserDao (org.apache.ranger.db.XXUserDao)5 XXResource (org.apache.ranger.entity.XXResource)5 VXResponse (org.apache.ranger.view.VXResponse)5 VXUser (org.apache.ranger.view.VXUser)5 SearchCriteria (org.apache.ranger.common.SearchCriteria)4