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;
}
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());
}
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());
}
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);
}
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());
}
Aggregations