private Future<MessageSender> getOrCreateSender(final HonoClient messageSenderClient, final Device device) { return messageSenderSource.apply(messageSenderClient, device.getTenantId()); }
private Future<MessageSender> getOrCreateSender(final HonoClient messageSenderClient, final Device device) { return messageSenderSource.apply(messageSenderClient, device.getTenantId()); }
/** * Gets the device id in an address structure. * * @param device The device. * @return tenantId and deviceId as an address. * @throws NullPointerException if device is {@code null}. */ public static final String asAddress(final Device device) { return String.format("%s/%s", device.getTenantId(), device.getDeviceId()); } }
@Override public final String toString() { return String.format("device [%s: %s, %s: %s]", CredentialsConstants.FIELD_PAYLOAD_DEVICE_ID, getDeviceId(), CredentialsConstants.FIELD_PAYLOAD_TENANT_ID, getTenantId()); }
@Override public final String toString() { return String.format("device [%s: %s, %s: %s]", CredentialsConstants.FIELD_PAYLOAD_DEVICE_ID, getDeviceId(), CredentialsConstants.FIELD_PAYLOAD_TENANT_ID, getTenantId()); }
/** * Gets the device id in an address structure. * * @param device The device. * @return tenantId and deviceId as an address. * @throws NullPointerException if device is {@code null}. */ public static final String asAddress(final Device device) { return String.format("%s/%s", device.getTenantId(), device.getDeviceId()); } }
/** * Gets the tenant identifier for this context. * * @return The tenant identifier. */ String getTenantId() { return isDeviceAuthenticated() ? authenticatedDevice.getTenantId() : resource.getTenantId(); }
private Future<Device> createLinks(final Device authenticatedDevice, final Span currentSpan) { final Future<MessageSender> telemetrySender = getTelemetrySender(authenticatedDevice.getTenantId()); final Future<MessageSender> eventSender = getEventSender(authenticatedDevice.getTenantId()); return CompositeFuture .all(telemetrySender, eventSender) .compose(ok -> { currentSpan.log("opened downstream links"); LOG.debug( "providently opened downstream links [credit telemetry: {}, credit event: {}] for tenant [{}]", telemetrySender.result().getCredit(), eventSender.result().getCredit(), authenticatedDevice.getTenantId()); return Future.succeededFuture(authenticatedDevice); }); }
private Future<Device> createLinks(final Device authenticatedDevice, final Span currentSpan) { final Future<MessageSender> telemetrySender = getTelemetrySender(authenticatedDevice.getTenantId()); final Future<MessageSender> eventSender = getEventSender(authenticatedDevice.getTenantId()); return CompositeFuture .all(telemetrySender, eventSender) .compose(ok -> { currentSpan.log("opened downstream links"); LOG.debug( "providently opened downstream links [credit telemetry: {}, credit event: {}] for tenant [{}]", telemetrySender.result().getCredit(), eventSender.result().getCredit(), authenticatedDevice.getTenantId()); return Future.succeededFuture(authenticatedDevice); }); }
void handlePostTelemetry(final RoutingContext ctx) { if (Device.class.isInstance(ctx.user())) { final Device device = (Device) ctx.user(); uploadTelemetryMessage(ctx, device.getTenantId(), device.getDeviceId()); } else { handle401(ctx); } }
void handlePostEvent(final RoutingContext ctx) { if (Device.class.isInstance(ctx.user())) { final Device device = (Device) ctx.user(); uploadEventMessage(ctx, device.getTenantId(), device.getDeviceId()); } else { handle401(ctx); } }
void handlePostTelemetry(final RoutingContext ctx) { if (Device.class.isInstance(ctx.user())) { final Device device = (Device) ctx.user(); uploadTelemetryMessage(ctx, device.getTenantId(), device.getDeviceId()); } else { handle401(ctx); } }
void handlePostEvent(final RoutingContext ctx) { if (Device.class.isInstance(ctx.user())) { final Device device = (Device) ctx.user(); uploadEventMessage(ctx, device.getTenantId(), device.getDeviceId()); } else { handle401(ctx); } }
void assertTenant(final RoutingContext ctx) { if (Device.class.isInstance(ctx.user())) { final Device device = (Device) ctx.user(); if (device.getTenantId().equals(getTenantParam(ctx))) { ctx.next(); } else { ctx.fail(new ClientErrorException(HttpURLConnection.HTTP_FORBIDDEN, "not authorized to upload data for device from other tenant")); } } else { handle401(ctx); } } }
void assertTenant(final RoutingContext ctx) { if (Device.class.isInstance(ctx.user())) { final Device device = (Device) ctx.user(); if (device.getTenantId().equals(getTenantParam(ctx))) { ctx.next(); } else { ctx.fail(new ClientErrorException(HttpURLConnection.HTTP_FORBIDDEN, "not authorized to upload data for device from other tenant")); } } else { handle401(ctx); } } }
void handlePostCommandResponse(final RoutingContext ctx) { if (Device.class.isInstance(ctx.user())) { final Device device = (Device) ctx.user(); uploadCommandResponseMessage(ctx, device.getTenantId(), device.getDeviceId(), getCommandRequestIdParam(ctx), getCommandResponseStatusParam(ctx)); } else { handle401(ctx); } }
void handlePostCommandResponse(final RoutingContext ctx) { if (Device.class.isInstance(ctx.user())) { final Device device = (Device) ctx.user(); uploadCommandResponseMessage(ctx, device.getTenantId(), device.getDeviceId(), getCommandRequestIdParam(ctx), getCommandResponseStatusParam(ctx)); } else { handle401(ctx); } }
private Future<Device> registerHandlers(final MqttEndpoint endpoint, final Device authenticatedDevice) { endpoint.closeHandler(v -> close(endpoint, authenticatedDevice)); endpoint.publishHandler( message -> handlePublishedMessage(new MqttContext(message, endpoint, authenticatedDevice))); endpoint.subscribeHandler(subscribeMsg -> onSubscribe(endpoint, authenticatedDevice, subscribeMsg)); endpoint.unsubscribeHandler(unsubscribeMsg -> onUnsubscribe(endpoint, authenticatedDevice, unsubscribeMsg)); metrics.incrementConnections(authenticatedDevice.getTenantId()); return Future.succeededFuture(authenticatedDevice); }
private Span newSpan(final String operationName, final Device authenticatedDevice) { final Span span = tracer.buildSpan(operationName) .ignoreActiveSpan() .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER) .withTag(Tags.COMPONENT.getKey(), getTypeName()) .withTag(TracingHelper.TAG_AUTHENTICATED.getKey(), authenticatedDevice != null) .start(); if (authenticatedDevice != null) { span.setTag(MessageHelper.APP_PROPERTY_TENANT_ID, authenticatedDevice.getTenantId()); span.setTag(MessageHelper.APP_PROPERTY_DEVICE_ID, authenticatedDevice.getDeviceId()); } return span; }
private Span newSpan(final String operationName, final MqttEndpoint endpoint, final Device authenticatedDevice) { final Span span = tracer.buildSpan(operationName) .ignoreActiveSpan() .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER) .withTag(Tags.COMPONENT.getKey(), getTypeName()) .withTag(TracingHelper.TAG_CLIENT_ID.getKey(), endpoint.clientIdentifier()) .withTag(TracingHelper.TAG_AUTHENTICATED.getKey(), authenticatedDevice != null) .start(); if (authenticatedDevice != null) { span.setTag(MessageHelper.APP_PROPERTY_TENANT_ID, authenticatedDevice.getTenantId()); span.setTag(MessageHelper.APP_PROPERTY_DEVICE_ID, authenticatedDevice.getDeviceId()); } return span; }