Search in sources :

Example 6 with VXAuditMap

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

the class TestXUserREST method test56updateXAuditMap.

@Test
public void test56updateXAuditMap() {
    VXAuditMap testvXAuditMap = createVXAuditMapObj();
    testvXAuditMap.setResourceId(id);
    Mockito.when(xUserMgr.updateXAuditMap(testvXAuditMap)).thenReturn(testvXAuditMap);
    VXResource testVxResource = createVXResource();
    Mockito.when(xResourceService.readResource(testvXAuditMap.getResourceId())).thenReturn(testVxResource);
    VXAuditMap retvXAuditMap = xUserRest.updateXAuditMap(testvXAuditMap);
    assertEquals(testvXAuditMap.getId(), retvXAuditMap.getId());
    assertEquals(testvXAuditMap.getClass(), retvXAuditMap.getClass());
    assertNotNull(retvXAuditMap);
    Mockito.verify(xUserMgr).updateXAuditMap(testvXAuditMap);
    Mockito.verify(xResourceService).readResource(testvXAuditMap.getResourceId());
}
Also used : VXResource(org.apache.ranger.view.VXResource) VXAuditMap(org.apache.ranger.view.VXAuditMap) Test(org.junit.Test)

Example 7 with VXAuditMap

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

the class TestXUserREST method test50getXAuditMapVXAuditMapNull.

@Test
public void test50getXAuditMapVXAuditMapNull() {
    VXAuditMap testvXAuditMap = createVXAuditMapObj();
    Mockito.when(xUserMgr.getXAuditMap(testvXAuditMap.getResourceId())).thenReturn(testvXAuditMap);
    Mockito.when(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any())).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    VXAuditMap retVXAuditMap = xUserRest.getXAuditMap(testvXAuditMap.getResourceId());
    assertEquals(testvXAuditMap.getId(), retVXAuditMap.getId());
    assertEquals(testvXAuditMap.getClass(), retVXAuditMap.getClass());
    assertNotNull(retVXAuditMap);
    Mockito.verify(xUserMgr).getXAuditMap(testvXAuditMap.getResourceId());
    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 8 with VXAuditMap

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

the class TestXUserREST method test54createXAuditMapVxResourceNull.

@Test
public void test54createXAuditMapVxResourceNull() {
    VXAuditMap testvXAuditMap = createVXAuditMapObj();
    testvXAuditMap.setResourceId(null);
    Mockito.when(xResourceService.readResource(testvXAuditMap.getResourceId())).thenReturn(null);
    Mockito.when(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any())).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    VXAuditMap retvXAuditMap = xUserRest.createXAuditMap(testvXAuditMap);
    assertEquals(testvXAuditMap.getId(), retvXAuditMap.getId());
    assertEquals(testvXAuditMap.getClass(), retvXAuditMap.getClass());
    assertNotNull(retvXAuditMap);
    Mockito.verify(xUserMgr).createXAuditMap(testvXAuditMap);
    Mockito.verify(xResourceService).readResource(testvXAuditMap.getResourceId());
    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 9 with VXAuditMap

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

the class XAuditMapServiceBase method searchXAuditMaps.

/**
 * @param searchCriteria
 * @return
 */
public VXAuditMapList searchXAuditMaps(SearchCriteria searchCriteria) {
    VXAuditMapList returnList = new VXAuditMapList();
    List<VXAuditMap> xAuditMapList = new ArrayList<VXAuditMap>();
    List<T> resultList = searchResources(searchCriteria, searchFields, sortFields, returnList);
    // Iterate over the result list and create the return list
    for (T gjXAuditMap : resultList) {
        VXAuditMap vXAuditMap = populateViewBean(gjXAuditMap);
        xAuditMapList.add(vXAuditMap);
    }
    returnList.setVXAuditMaps(xAuditMapList);
    return returnList;
}
Also used : ArrayList(java.util.ArrayList) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) VXAuditMap(org.apache.ranger.view.VXAuditMap)

Example 10 with VXAuditMap

use of org.apache.ranger.view.VXAuditMap 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

VXAuditMap (org.apache.ranger.view.VXAuditMap)16 Test (org.junit.Test)10 VXResource (org.apache.ranger.view.VXResource)6 ArrayList (java.util.ArrayList)5 WebApplicationException (javax.ws.rs.WebApplicationException)3 MessageEnums (org.apache.ranger.common.MessageEnums)3 VXAuditMapList (org.apache.ranger.view.VXAuditMapList)3 VXPermMap (org.apache.ranger.view.VXPermMap)3 SearchCriteria (org.apache.ranger.common.SearchCriteria)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 SortField (org.apache.ranger.common.SortField)1 XXAsset (org.apache.ranger.entity.XXAsset)1 XXAuditMap (org.apache.ranger.entity.XXAuditMap)1 XXResource (org.apache.ranger.entity.XXResource)1 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)1 VXPermMapList (org.apache.ranger.view.VXPermMapList)1