/** * @return true, if user is admin */ public boolean isAdmin() { return UserRole.ADMIN.equals(role); }
/** * @return true, if user is admin */ @ApiModelProperty(hidden = true) public boolean isAdmin() { return UserRole.ADMIN.equals(role); }
@Transactional(propagation = Propagation.SUPPORTS) public List<DeviceVO> getAllowedExistingDevices(Set<String> deviceIds, HivePrincipal principal) { List<DeviceVO> devices = findByIdWithPermissionsCheck(deviceIds, principal); Set<String> allowedIds = devices.stream() .map(DeviceVO::getDeviceId) .collect(Collectors.toSet()); Set<String> unresolvedIds = Sets.difference(deviceIds, allowedIds); if (unresolvedIds.isEmpty()) { return devices; } if (UserRole.ADMIN.equals(principal.getUser().getRole())) { throw new HiveException(String.format(Messages.DEVICES_NOT_FOUND, unresolvedIds), SC_NOT_FOUND); } else { throw new HiveException(Messages.ACCESS_DENIED, SC_FORBIDDEN); } }
@Transactional(propagation = Propagation.SUPPORTS) public DeviceVO findByIdWithPermissionsCheckIfExists(String deviceId, HivePrincipal principal) { if (deviceId.isEmpty()) { logger.error("Device ID is empty"); throw new HiveException(String.format(Messages.DEVICE_ID_REQUIRED, deviceId), BAD_REQUEST.getStatusCode()); } DeviceVO deviceVO = findByIdWithPermissionsCheck(deviceId, principal); if (deviceVO == null) { logger.error("Device with ID {} not found", deviceId); if (UserRole.CLIENT.equals(principal.getUser().getRole())) { throw new HiveException(ACCESS_DENIED, SC_FORBIDDEN); } throw new HiveException(String.format(Messages.DEVICE_NOT_FOUND, deviceId), NOT_FOUND.getStatusCode()); } return deviceVO; }
).filter(Objects::nonNull).collect(Collectors.toSet()); if (actualNetworks.size() != networks.size()) { if (UserRole.CLIENT.equals(principal.getUser().getRole())) { throw new HiveException(ACCESS_DENIED, SC_FORBIDDEN); .map(deviceTypeService::getWithDevices).filter(Objects::nonNull).collect(Collectors.toSet()); if (actualDeviceTypes.size() != deviceTypes.size()) { if (UserRole.CLIENT.equals(principal.getUser().getRole())) { throw new HiveException(ACCESS_DENIED, SC_FORBIDDEN);
final boolean isClient = UserRole.CLIENT.equals(curUser.getRole()); if (isClient) { if (userToUpdate.getLogin().isPresent() ||