Search in sources :

Example 21 with VXResource

use of org.apache.ranger.view.VXResource 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 22 with VXResource

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

the class TestXUserREST method test44updateXPermMap.

@Test
public void test44updateXPermMap() {
    VXPermMap permMap = testcreateXPermMap();
    VXResource testVxResource = new VXResource();
    Mockito.when(xResourceService.readResource(id)).thenReturn(testVxResource);
    Mockito.when(xUserMgr.updateXPermMap(permMap)).thenReturn(permMap);
    VXPermMap retVxGroup = xUserRest.updateXPermMap(permMap);
    assertEquals(permMap.getId(), retVxGroup.getId());
    assertEquals(permMap.getClass(), retVxGroup.getClass());
    assertNotNull(retVxGroup);
    Mockito.verify(xUserMgr).updateXPermMap(permMap);
    Mockito.verify(xResourceService).readResource(permMap.getResourceId());
}
Also used : VXPermMap(org.apache.ranger.view.VXPermMap) VXResource(org.apache.ranger.view.VXResource) Test(org.junit.Test)

Example 23 with VXResource

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

the class TestXUserREST method test43createXPermMapNullVXResource.

@Test
public void test43createXPermMapNullVXResource() {
    VXPermMap permMap = testcreateXPermMap();
    permMap.setResourceId(null);
    Mockito.when(xUserMgr.createXPermMap(permMap)).thenReturn(permMap);
    VXResource testVxResource = new VXResource();
    Mockito.when(xResourceService.readResource(permMap.getResourceId())).thenReturn(testVxResource);
    VXPermMap retVxGroup = xUserRest.createXPermMap(permMap);
    assertEquals(permMap.getId(), retVxGroup.getId());
    assertEquals(permMap.getClass(), retVxGroup.getClass());
    assertNotNull(retVxGroup);
    Mockito.verify(xUserMgr).createXPermMap(permMap);
    Mockito.verify(xResourceService).readResource(permMap.getResourceId());
}
Also used : VXPermMap(org.apache.ranger.view.VXPermMap) VXResource(org.apache.ranger.view.VXResource) Test(org.junit.Test)

Example 24 with VXResource

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

the class TestXUserREST method test39getXPermMapNotNull.

@Test
public void test39getXPermMapNotNull() throws Exception {
    VXPermMap permMap = testcreateXPermMap();
    Mockito.when(xUserMgr.getXPermMap(id)).thenReturn(permMap);
    VXResource testVxResource = new VXResource();
    Mockito.when(xResourceService.readResource(id)).thenReturn(testVxResource);
    VXPermMap retVxGroup = xUserRest.getXPermMap(id);
    assertEquals(permMap.getId(), retVxGroup.getId());
    assertEquals(permMap.getClass(), retVxGroup.getClass());
    assertNotNull(retVxGroup);
    Mockito.verify(xUserMgr).getXPermMap(id);
    Mockito.verify(xResourceService).readResource(id);
}
Also used : VXPermMap(org.apache.ranger.view.VXPermMap) VXResource(org.apache.ranger.view.VXResource) Test(org.junit.Test)

Example 25 with VXResource

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

the class TestRangerBizUtil method testHasPermission_When_NoResource.

@Test
public void testHasPermission_When_NoResource() {
    VXResource vXResource = null;
    VXResponse resp = rangerBizUtil.hasPermission(vXResource, AppConstants.XA_PERM_TYPE_UNKNOWN);
    Assert.assertNotNull(resp);
    Assert.assertEquals(VXResponse.STATUS_ERROR, resp.getStatusCode());
    Assert.assertEquals("Please provide valid policy.", resp.getMsgDesc());
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) VXResource(org.apache.ranger.view.VXResource) Test(org.junit.Test)

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