Tabnine Logo
BaseRegistrationService.assertRegistration
Code IndexAdd Tabnine to your IDE (free)

How to use
assertRegistration
method
in
org.eclipse.hono.service.registration.BaseRegistrationService

Best Java code snippets using org.eclipse.hono.service.registration.BaseRegistrationService.assertRegistration (Showing top 11 results out of 315)

origin: eclipse/hono

@Override
public final void assertRegistration(
    final String tenantId,
    final String deviceId,
    final Handler<AsyncResult<RegistrationResult>> resultHandler) {
  assertRegistration(tenantId, deviceId, NoopSpan.INSTANCE, resultHandler);
}
origin: eclipse/hono

@Override
public final void assertRegistration(
    final String tenantId,
    final String deviceId,
    final String gatewayId,
    final Handler<AsyncResult<RegistrationResult>> resultHandler) {
  assertRegistration(tenantId, deviceId, gatewayId, NoopSpan.INSTANCE, resultHandler);
}
origin: eclipse/hono

private Future<EventBusMessage> processAssertRequest(final EventBusMessage request) {
  final String tenantId = request.getTenant();
  final String deviceId = request.getDeviceId();
  final String gatewayId = request.getGatewayId();
  final SpanContext spanContext = request.getSpanContext();
  final Span span = newChildSpan(SPAN_NAME_ASSERT_DEVICE_REGISTRATION, spanContext, tenantId, deviceId, gatewayId);
  final Future<EventBusMessage> resultFuture;
  if (tenantId == null || deviceId == null) {
    TracingHelper.logError(span, "missing tenant and/or device");
    resultFuture = Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
  } else {
    final Future<RegistrationResult> result = Future.future();
    if (gatewayId == null) {
      log.debug("asserting registration of device [{}] with tenant [{}]", deviceId, tenantId);
      assertRegistration(tenantId, deviceId, span, result.completer());
    } else {
      log.debug("asserting registration of device [{}] with tenant [{}] for gateway [{}]",
          deviceId, tenantId, gatewayId);
      assertRegistration(tenantId, deviceId, gatewayId, span, result.completer());
    }
    resultFuture = result.map(res -> {
      return request.getResponse(res.getStatus())
          .setDeviceId(deviceId)
          .setJsonPayload(res.getPayload())
          .setCacheDirective(res.getCacheDirective());
    });
  }
  return finishSpanOnFutureCompletion(span, resultFuture);
}
origin: org.eclipse.hono/hono-service-base

private Future<EventBusMessage> processAssertRequest(final EventBusMessage request) {
  final String tenantId = request.getTenant();
  final String deviceId = request.getDeviceId();
  final String gatewayId = request.getGatewayId();
  if (tenantId == null || deviceId == null) {
    return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
  } else if (gatewayId == null) {
    log.debug("asserting registration of device [{}] with tenant [{}]", deviceId, tenantId);
    final Future<RegistrationResult> result = Future.future();
    assertRegistration(tenantId, deviceId, result.completer());
    return result.map(res -> {
      return request.getResponse(res.getStatus())
          .setDeviceId(deviceId)
          .setJsonPayload(res.getPayload())
          .setCacheDirective(res.getCacheDirective());
    });
  } else {
    log.debug("asserting registration of device [{}] with tenant [{}] for gateway [{}]",
        deviceId, tenantId, gatewayId);
    final Future<RegistrationResult> result = Future.future();
    assertRegistration(tenantId, deviceId, gatewayId, result.completer());
    return result.map(res -> {
      return request.getResponse(res.getStatus())
          .setDeviceId(deviceId)
          .setJsonPayload(res.getPayload())
          .setCacheDirective(res.getCacheDirective());
    });
  }
}
origin: eclipse/hono

/**
 * Verifies that a device's status can be asserted by an existing gateway.
 * 
 * @param ctx The vertx unit test context.
 */
@Test
public void testAssertDeviceRegistrationSucceedsForExistingGateway(final TestContext ctx) {
  // GIVEN a registry that contains an enabled device that is configured to
  // be connected to an enabled gateway
  final BaseRegistrationService<ServiceConfigProperties> registrationService = newRegistrationService();
  registrationService.setRegistrationAssertionFactory(RegistrationAssertionHelperImpl.forSigning(vertx, props));
  // WHEN trying to assert the device's registration status for a gateway
  registrationService.assertRegistration(Constants.DEFAULT_TENANT, "4711", "gw-1", ctx.asyncAssertSuccess(result -> {
    // THEN the response contains a 200 status
    ctx.assertEquals(HttpURLConnection.HTTP_OK, result.getStatus());
    final JsonObject payload = result.getPayload();
    ctx.assertNotNull(payload);
    // and contains a JWT token
    ctx.assertNotNull(payload.getString(RegistrationConstants.FIELD_ASSERTION));
  }));
}
origin: eclipse/hono

/**
 * Verifies that an enabled device's status can be asserted successfully.
 * 
 * @param ctx The vertx unit test context.
 */
@Test
public void testAssertDeviceRegistrationReturnsToken(final TestContext ctx) {
  // GIVEN a registry that contains an enabled device with a default content type set
  final BaseRegistrationService<ServiceConfigProperties> registrationService = newRegistrationService();
  registrationService.setRegistrationAssertionFactory(RegistrationAssertionHelperImpl.forSigning(vertx, props));
  // WHEN trying to assert the device's registration status
  registrationService.assertRegistration(Constants.DEFAULT_TENANT, "4711", ctx.asyncAssertSuccess(result -> {
    ctx.assertEquals(result.getStatus(), HttpURLConnection.HTTP_OK);
    final JsonObject payload = result.getPayload();
    ctx.assertNotNull(payload);
    // THEN the response contains a JWT token asserting the device's registration status
    final String compactJws = payload.getString(RegistrationConstants.FIELD_ASSERTION);
    ctx.assertNotNull(compactJws);
    // and contains the registered default content type
    final JsonObject defaults = payload.getJsonObject(RegistrationConstants.FIELD_DEFAULTS);
    ctx.assertNotNull(defaults);
    ctx.assertEquals("application/default", defaults.getString(MessageHelper.SYS_PROPERTY_CONTENT_TYPE));
  }));
}
origin: eclipse/hono

/**
 * Verifies that a disabled device's status cannot be asserted.
 * 
 * @param ctx The vertx unit test context.
 */
@Test
public void testAssertDeviceRegistrationFailsForDisabledDevice(final TestContext ctx) {
  // GIVEN a registry that contains a disabled device
  final BaseRegistrationService<ServiceConfigProperties> registrationService = newRegistrationService();
  registrationService.setRegistrationAssertionFactory(RegistrationAssertionHelperImpl.forSigning(vertx, props));
  // WHEN trying to assert the device's registration status
  registrationService.assertRegistration(Constants.DEFAULT_TENANT, "4712", ctx.asyncAssertSuccess(result -> {
    // THEN the response does not contain a JWT token
    ctx.assertEquals(result.getStatus(), HttpURLConnection.HTTP_NOT_FOUND);
    ctx.assertNull(result.getPayload());
  }));
}
origin: eclipse/hono

/**
 * Verifies that a non existing device's status cannot be asserted.
 * 
 * @param ctx The vertx unit test context.
 */
@Test
public void testAssertDeviceRegistrationFailsForNonExistingDevice(final TestContext ctx) {
  // GIVEN a registry that does not contain any devices
  final BaseRegistrationService<ServiceConfigProperties> registrationService = newRegistrationService();
  registrationService.setRegistrationAssertionFactory(RegistrationAssertionHelperImpl.forSigning(vertx, props));
  // WHEN trying to assert a device's registration status
  registrationService.assertRegistration(Constants.DEFAULT_TENANT, "non-existent", ctx.asyncAssertSuccess(result -> {
    // THEN the response does not contain a JWT token
    ctx.assertEquals(result.getStatus(), HttpURLConnection.HTTP_NOT_FOUND);
    ctx.assertNull(result.getPayload());
  }));
}
origin: eclipse/hono

/**
 * Verifies that a device's status cannot be asserted by a non-existing gateway.
 * 
 * @param ctx The vertx unit test context.
 */
@Test
public void testAssertDeviceRegistrationFailsForNonExistingGateway(final TestContext ctx) {
  // GIVEN a registry that contains an enabled device but no gateway
  final BaseRegistrationService<ServiceConfigProperties> registrationService = newRegistrationService();
  registrationService.setRegistrationAssertionFactory(RegistrationAssertionHelperImpl.forSigning(vertx, props));
  // WHEN trying to assert the device's registration status for a gateway
  registrationService.assertRegistration(Constants.DEFAULT_TENANT, "4711", "non-existent-gw", ctx.asyncAssertSuccess(result -> {
    // THEN the response contains a 403 status
    ctx.assertEquals(result.getStatus(), HttpURLConnection.HTTP_FORBIDDEN);
    // and does not contain a JWT token
    ctx.assertNull(result.getPayload());
  }));
}
origin: eclipse/hono

/**
 * Verifies that a device's status cannot be asserted by a gateway that does not
 * match the device's configured gateway.
 * 
 * @param ctx The vertx unit test context.
 */
@Test
public void testAssertDeviceRegistrationFailsForWrongGateway(final TestContext ctx) {
  // GIVEN a registry that contains an enabled device and two gateways:
  // 1. the gateway that the device is configured for.
  // 2. another gateway
  final BaseRegistrationService<ServiceConfigProperties> registrationService = newRegistrationService();
  registrationService.setRegistrationAssertionFactory(RegistrationAssertionHelperImpl.forSigning(vertx, props));
  // WHEN trying to assert the device's registration status for the wrong gateway
  registrationService.assertRegistration(Constants.DEFAULT_TENANT, "4711", "gw-2", ctx.asyncAssertSuccess(result -> {
    // THEN the response contains a 403 status
    ctx.assertEquals(result.getStatus(), HttpURLConnection.HTTP_FORBIDDEN);
    // and does not contain a JWT token
    ctx.assertNull(result.getPayload());
  }));
}
origin: eclipse/hono

/**
 * Verifies that a device's status cannot be asserted by a disabled gateway.
 * 
 * @param ctx The vertx unit test context.
 */
@Test
public void testAssertDeviceRegistrationFailsForDisabledGateway(final TestContext ctx) {
  // GIVEN a registry that contains an enabled device
  // and a gateway that the device is configured for but
  // which is disabled
  final BaseRegistrationService<ServiceConfigProperties> registrationService = newRegistrationService();
  registrationService.setRegistrationAssertionFactory(RegistrationAssertionHelperImpl.forSigning(vertx, props));
  // WHEN trying to assert the device's registration status for a gateway
  registrationService.assertRegistration(Constants.DEFAULT_TENANT, "4713", "gw-3", ctx.asyncAssertSuccess(result -> {
    // THEN the response contains a 403 status
    ctx.assertEquals(result.getStatus(), HttpURLConnection.HTTP_FORBIDDEN);
    // and does not contain a JWT token
    ctx.assertNull(result.getPayload());
  }));
}
org.eclipse.hono.service.registrationBaseRegistrationServiceassertRegistration

Javadoc

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 #getDevice(String,String,Handler) method to work.

Popular methods of BaseRegistrationService

  • doStart
    Asserts that the assertionFactory property is set. The given future is succeeded if the property is
  • finishSpanOnFutureCompletion
  • getAssertionPayload
    Creates a registration assertion token for a device and wraps it in a JSON object. The returned JSON
  • getDevice
    Gets device registration data by device ID. This method is invoked by #assertRegistration(String,Str
  • getResultPayload
    Wraps a given device ID and registration data into a JSON structure suitable to be returned to clien
  • handleUnimplementedOperation
    Handles an unimplemented operation by failing the given handler with a ClientErrorException having a
  • isDeviceEnabled
  • isGatewayAuthorized
    Checks if a gateway is authorized to act on behalf of a device. This default implementation checks i
  • newChildSpan
    Creates a new OpenTracing span for tracing the execution of a registration service operation. The re
  • processAssertRequest
  • processCustomRegistrationMessage
    Processes a request for a non-standard operation. Subclasses should override this method in order to
  • processRequest
    Processes a device registration API request received via the vert.x event bus. This method validate
  • processCustomRegistrationMessage,
  • processRequest,
  • setRegistrationAssertionFactory

Popular in Java

  • Updating database using SQL prepared statement
  • setRequestProperty (URLConnection)
  • getSystemService (Context)
  • setScale (BigDecimal)
  • NumberFormat (java.text)
    The abstract base class for all number formats. This class provides the interface for formatting and
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now