/** * Creates a registration assertion token for a device and wraps it in a JSON object. * <p> * The returned JSON object may also contain <em>default</em> values registered for the * device under key {@link RegistrationConstants#FIELD_DEFAULTS}. * * @param tenantId The tenant the device belongs to. * @param deviceId The device to create the assertion token for. * @param registrationInfo The device's registration information. * @return The payload. */ protected final JsonObject getAssertionPayload(final String tenantId, final String deviceId, final JsonObject registrationInfo) { final JsonObject result = new JsonObject() .put(RegistrationConstants.FIELD_PAYLOAD_DEVICE_ID, deviceId) .put(RegistrationConstants.FIELD_ASSERTION, assertionFactory.getAssertion(tenantId, deviceId)); final JsonObject defaults = registrationInfo.getJsonObject(RegistrationConstants.FIELD_DEFAULTS); if (defaults != null) { result.put(RegistrationConstants.FIELD_DEFAULTS, defaults); } return result; }
/** * Verifies that signatures created using an RSA private key can be validated using the corresponding public key. */ @Test public void testForSigningWorksWithRsaSignatures() { final SignatureSupportingConfigProperties props = new SignatureSupportingConfigProperties(); props.setKeyPath("target/certs/hono-messaging-key.pem"); props.setCertPath("target/certs/hono-messaging-cert.pem"); final RegistrationAssertionHelper factory = RegistrationAssertionHelperImpl.forSigning(vertx, props); final String assertion = factory.getAssertion("tenant", "device"); assertNotNull(assertion); final RegistrationAssertionHelper validator = RegistrationAssertionHelperImpl.forValidating(vertx, props); assertTrue(validator.isValid(assertion, "tenant", "device")); }
HttpURLConnection.HTTP_OK, getAssertionPayload(tenantId, deviceId, result.getPayload().getJsonObject(RegistrationConstants.FIELD_DATA)), CacheDirective.maxAgeDirective(assertionFactory.getAssertionLifetime())); } else { TracingHelper.logError(span, "device not enabled");
/** * {@inheritDoc} * <p> * Subclasses may override this method in order to implement a more sophisticated approach for asserting registration status, e.g. * using cached information etc. * This method requires a functional {@link #getDevice(String, String, Handler) getDevice} method to work. */ @Override public void assertRegistration( final String tenantId, final String deviceId, final Handler<AsyncResult<RegistrationResult>> resultHandler) { Objects.requireNonNull(tenantId); Objects.requireNonNull(deviceId); Objects.requireNonNull(resultHandler); final Future<RegistrationResult> getResultTracker = Future.future(); getDevice(tenantId, deviceId, getResultTracker.completer()); getResultTracker.map(result -> { if (isDeviceEnabled(result)) { return RegistrationResult.from( HttpURLConnection.HTTP_OK, getAssertionPayload(tenantId, deviceId, result.getPayload().getJsonObject(RegistrationConstants.FIELD_DATA)), CacheDirective.maxAgeDirective(assertionFactory.getAssertionLifetime())); } else { return RegistrationResult.from(HttpURLConnection.HTTP_NOT_FOUND); } }).setHandler(resultHandler); }
/** * Creates a registration assertion token for a device and wraps it in a JSON object. * <p> * The returned JSON object may also contain <em>default</em> values registered for the * device under key {@link RegistrationConstants#FIELD_DEFAULTS}. * * @param tenantId The tenant the device belongs to. * @param deviceId The device to create the assertion token for. * @param registrationInfo The device's registration information. * @return The payload. */ protected final JsonObject getAssertionPayload(final String tenantId, final String deviceId, final JsonObject registrationInfo) { final JsonObject result = new JsonObject() .put(RegistrationConstants.FIELD_PAYLOAD_DEVICE_ID, deviceId) .put(RegistrationConstants.FIELD_ASSERTION, assertionFactory.getAssertion(tenantId, deviceId)); final JsonObject defaults = registrationInfo.getJsonObject(RegistrationConstants.FIELD_DEFAULTS); if (defaults != null) { result.put(RegistrationConstants.FIELD_DEFAULTS, defaults); } return result; }
HttpURLConnection.HTTP_OK, getAssertionPayload(tenantId, deviceId, deviceData), CacheDirective.maxAgeDirective(assertionFactory.getAssertionLifetime()))); } else { return Future.succeededFuture(RegistrationResult.from(HttpURLConnection.HTTP_FORBIDDEN));
HttpURLConnection.HTTP_OK, getAssertionPayload(tenantId, deviceId, deviceData), CacheDirective.maxAgeDirective(assertionFactory.getAssertionLifetime()))); } else { TracingHelper.logError(span, "gateway not authorized");