use of org.apache.ranger.view.RangerSecurityZoneList in project ranger by apache.
the class TestSecurityZoneREST method testGetAllSecurityZone.
@Test(expected = WebApplicationException.class)
public void testGetAllSecurityZone() throws Exception {
RangerSecurityZone securityZone = createRangerSecurityZone();
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
SearchFilter filter = new SearchFilter();
when(searchUtil.getSearchFilter(request, securityZoneService.sortFields)).thenReturn(filter);
Long securityZoneId = 2L;
securityZone.setId(securityZoneId);
List<RangerSecurityZone> zonesList = new ArrayList<>();
zonesList.add(securityZone);
RangerSecurityZoneList rangerZoneList = new RangerSecurityZoneList();
rangerZoneList.setSecurityZoneList(zonesList);
when(securityZoneStore.getSecurityZones(filter)).thenReturn(zonesList);
when(rangerBizUtil.hasModuleAccess(Mockito.anyString())).thenReturn(true);
RangerSecurityZoneList returnedZonesList = securityZoneREST.getAllZones(request);
assertEquals(returnedZonesList.getResultSize(), rangerZoneList.getList().size());
verify(securityZoneStore, times(1)).getSecurityZones(filter);
// No access
when(rangerBizUtil.hasModuleAccess(Mockito.anyString())).thenReturn(false);
when(restErrorUtil.createRESTException(Mockito.anyString(), Mockito.any())).thenReturn(new WebApplicationException());
securityZoneREST.getAllZones(request);
verify(securityZoneStore, times(0)).getSecurityZones(filter);
}
use of org.apache.ranger.view.RangerSecurityZoneList in project ranger by apache.
the class SecurityZoneREST method getAllZones.
@GET
@Path("/zones")
public RangerSecurityZoneList getAllZones(@Context HttpServletRequest request) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> getAllZones()");
}
if (!bizUtil.hasModuleAccess(RangerConstants.MODULE_SECURITY_ZONE)) {
throw restErrorUtil.createRESTException(STR_USER_NOT_AUTHORIZED_TO_ACCESS_ZONE, MessageEnums.OPER_NO_PERMISSION);
}
RangerSecurityZoneList ret = new RangerSecurityZoneList();
SearchFilter filter = searchUtil.getSearchFilter(request, securityZoneService.sortFields);
try {
List<RangerSecurityZone> securityZones = securityZoneStore.getSecurityZones(filter);
ret.setSecurityZoneList(securityZones);
if (securityZones != null) {
ret.setTotalCount(securityZones.size());
ret.setSortBy(filter.getSortBy());
ret.setSortType(filter.getSortType());
ret.setResultSize(securityZones.size());
}
} catch (WebApplicationException excp) {
throw excp;
} catch (Throwable excp) {
LOG.error("getSecurityZones() failed", excp);
throw restErrorUtil.createRESTException(excp.getMessage());
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== getAllZones():" + ret);
}
return ret;
}
Aggregations