Search in sources :

Example 11 with VXPermMap

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

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

the class XResourceService method populatePermList.

private void populatePermList(VXResource vXResource) {
    List<XXPermMap> xPermMapList = daoManager.getXXPermMap().findByResourceId(vXResource.getId());
    List<VXPermMap> vXPermMapList = new ArrayList<VXPermMap>();
    for (XXPermMap xPermMap : xPermMapList) {
        vXPermMapList.add(xPermMapService.populateViewBean(xPermMap));
    }
    vXResource.setPermMapList(vXPermMapList);
}
Also used : VXPermMap(org.apache.ranger.view.VXPermMap) ArrayList(java.util.ArrayList) XXPermMap(org.apache.ranger.entity.XXPermMap)

Example 13 with VXPermMap

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

the class TestXUserREST method test46updateXPermMap.

@Test
public void test46updateXPermMap() {
    VXPermMap permMap = testcreateXPermMap();
    Mockito.when(xResourceService.readResource(permMap.getResourceId())).thenReturn(null);
    Mockito.when(restErrorUtil.createRESTException(Mockito.anyString())).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    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());
    Mockito.verify(restErrorUtil).createRESTException(Mockito.anyString());
}
Also used : VXPermMap(org.apache.ranger.view.VXPermMap) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 14 with VXPermMap

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

the class TestXUserREST method test45updateXPermMap.

@Test
public void test45updateXPermMap() {
    Mockito.when(xUserMgr.updateXPermMap(null)).thenReturn(null);
    VXPermMap retVxGroup = xUserRest.updateXPermMap(null);
    assertNull(retVxGroup);
    Mockito.verify(xUserMgr).updateXPermMap(null);
}
Also used : VXPermMap(org.apache.ranger.view.VXPermMap) Test(org.junit.Test)

Example 15 with VXPermMap

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

the class TestXUserREST method test41createXPermMap.

@Test
public void test41createXPermMap() {
    VXPermMap permMap = testcreateXPermMap();
    permMap.setResourceId(null);
    Mockito.when(xResourceService.readResource(permMap.getResourceId())).thenReturn(null);
    Mockito.when(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any())).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    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());
    Mockito.verify(restErrorUtil).createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any());
}
Also used : VXPermMap(org.apache.ranger.view.VXPermMap) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Aggregations

VXPermMap (org.apache.ranger.view.VXPermMap)25 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)10 HashMap (java.util.HashMap)7 List (java.util.List)6 VXResource (org.apache.ranger.view.VXResource)6 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)5 VXPermMapList (org.apache.ranger.view.VXPermMapList)5 VXPermObj (org.apache.ranger.view.VXPermObj)5 VXPolicyList (org.apache.ranger.view.VXPolicyList)5 Date (java.util.Date)4 SearchCriteria (org.apache.ranger.common.SearchCriteria)4 VXAuditMap (org.apache.ranger.view.VXAuditMap)4 LinkedHashMap (java.util.LinkedHashMap)3 Random (java.util.Random)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 RangerPolicyItemAccess (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess)3 VXAuditMapList (org.apache.ranger.view.VXAuditMapList)3 VXResourceList (org.apache.ranger.view.VXResourceList)3 Map (java.util.Map)2