User user = userWebAPI.getLoggedInUser(ctx.getHttpServletRequest());
boolean respectFrontendRoles = userWebAPI.isLoggedToFrontend(ctx.getHttpServletRequest());
HostAPI hostAPI = APILocator.getHostAPI();
List<Host> hosts = hostAPI.findAll(user, respectFrontendRoles);
List<Map<String, Object>> hostsToReturn = new ArrayList<Map<String,Object>>(hosts.size());
Collections.sort(hosts, new HostNameComparator());
for (Host h: hosts) {
if(UtilMethods.isSet(requiredPermissions)){
if(permissionAPI.doesUserHavePermissions(h,requiredPermissions, user)){
hostsToReturn.add(hostMap(h));
}