@HiveWebsocketAuth @PreAuthorize("isAuthenticated() and hasPermission(null, 'GET_DEVICE')") public void processDeviceList(JsonObject request, WebSocketSession session) throws HiveException { HivePrincipal principal = (HivePrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); ListDeviceRequest listDeviceRequest = ListDeviceRequest.createListDeviceRequest(request, principal); String sortField = Optional.ofNullable(listDeviceRequest.getSortField()).map(String::toLowerCase).orElse(null); if (sortField != null && !NAME.equalsIgnoreCase(sortField) && !STATUS.equalsIgnoreCase(sortField) && !NETWORK.equalsIgnoreCase(sortField)) { logger.error("Unable to proceed device list request. Invalid sortField."); throw new HiveException(Messages.INVALID_REQUEST_PARAMETERS, BAD_REQUEST.getStatusCode()); } WebSocketResponse response = new WebSocketResponse(); if (!principal.areAllNetworksAvailable() && (principal.getNetworkIds() == null || principal.getNetworkIds().isEmpty()) || !principal.areAllDeviceTypesAvailable() && (principal.getDeviceTypeIds() == null || principal.getDeviceTypeIds().isEmpty())) { logger.warn("Unable to get list for empty devices"); response.addValue(DEVICES, Collections.<DeviceVO>emptyList(), DEVICES_LISTED); webSocketClientHandler.sendMessage(request, response, session); } else { deviceService.list(listDeviceRequest) .thenAccept(devices -> { logger.debug("Device list request proceed successfully"); response.addValue(DEVICES, devices, DEVICES_LISTED); webSocketClientHandler.sendMessage(request, response, session); }); } }