Search in sources :

Example 1 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);
        } else if (resType.equalsIgnoreCase("hiveservice")) {
            ret.setHiveServices(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)

Example 2 with VXAuditMap

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

the class TestXUserREST method test55createXAuditMapNull.

@Test
public void test55createXAuditMapNull() {
    VXAuditMap testvXAuditMap = createVXAuditMapObj();
    testvXAuditMap.setResourceId(null);
    VXAuditMap retvXAuditMap = xUserRest.createXAuditMap(null);
    assertNull(retvXAuditMap);
    Mockito.verify(xUserMgr).createXAuditMap(null);
}
Also used : VXAuditMap(org.apache.ranger.view.VXAuditMap) Test(org.junit.Test)

Example 3 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 4 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 5 with VXAuditMap

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

the class TestXUserREST method test58updateXAuditMapVXResourceNull.

@Test
public void test58updateXAuditMapVXResourceNull() {
    VXAuditMap vXAuditMap = null;
    VXAuditMap retvXAuditMap = xUserRest.updateXAuditMap(vXAuditMap);
    assertNull(retvXAuditMap);
}
Also used : VXAuditMap(org.apache.ranger.view.VXAuditMap) 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