Tabnine Logo
CompleteCredentialsService
Code IndexAdd Tabnine to your IDE (free)

How to use
CompleteCredentialsService
in
org.eclipse.hono.service.credentials

Best Java code snippets using org.eclipse.hono.service.credentials.CompleteCredentialsService (Showing top 11 results out of 315)

origin: eclipse/hono

/**
 * Gets all credentials registered for a device.
 * <p>
 * This default implementation simply returns the result of {@link #getAll(String, String, Handler)}.
 *
 * @param tenantId The tenant the device belongs to.
 * @param deviceId The device to get credentials for.
 * @param span The active OpenTracing span for this operation. It is not to be closed in this method!
 *            An implementation should log (error) events on this span and it may set tags and use this span as the
 *            parent for any spans created in this method.
 * @param resultHandler The handler to invoke with the result of the operation.
 *         The <em>status</em> will be
 *         <ul>
 *         <li><em>200 OK</em> if credentials of the given type and authentication identifier have been found. The
 *         <em>payload</em> will contain the credentials.</li>
 *         <li><em>404 Not Found</em> if no credentials matching the criteria exist.</li>
 *         </ul>
 * @throws NullPointerException if any of the parameters is {@code null}.
 */
default void getAll(final String tenantId, final String deviceId, final Span span,
    final Handler<AsyncResult<CredentialsResult<JsonObject>>> resultHandler) {
  getAll(tenantId, deviceId, resultHandler);
}
origin: eclipse/hono

/**
 * Verifies that service returns 404 if a client provides wrong client context.
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testGetCredentialsFailsForWrongClientContext(final TestContext ctx) {
  final JsonObject clientContext = new JsonObject()
      .put("client-id", "gateway-one");
  register(getCompleteCredentialsService(), "tenant", "device", "myId", "myType", clientContext, new JsonArray(), ctx);
  final JsonObject testContext = new JsonObject()
      .put("client-id", "gateway-two");
  final Async get = ctx.async();
  getCompleteCredentialsService().get("tenant", "myType", "myId", testContext, ctx.asyncAssertSuccess(s -> {
    assertThat(s.getStatus(), is(HttpURLConnection.HTTP_NOT_FOUND));
    get.complete();
  }));
  get.await(2000);
}
origin: eclipse/hono

  protected static void register(
      final CompleteCredentialsService svc,
      final String tenant,
      final String deviceId,
      final String authId,
      final String type,
      final JsonObject clientContext,
      final JsonArray secrets,
      final TestContext ctx) {

    final JsonObject data = new JsonObject()
        .put(CredentialsConstants.FIELD_PAYLOAD_DEVICE_ID, deviceId)
        .put(CredentialsConstants.FIELD_AUTH_ID, authId)
        .put(CredentialsConstants.FIELD_TYPE, type)
        .put(CredentialsConstants.FIELD_SECRETS, secrets);

    if (clientContext != null) {
      data.mergeIn(clientContext);
    }

    final Async registration = ctx.async();
    svc.add("tenant", data, ctx.asyncAssertSuccess(s -> {
      assertThat(s.getStatus(), is(HttpURLConnection.HTTP_CREATED));
      registration.complete();
    }));
    registration.await();
  }
}
origin: eclipse/hono

/**
 * Verifies that the service removes credentials for a given auth-id and type.
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testRemoveCredentialsByAuthIdAndTypeSucceeds(final TestContext ctx) {
  register(getCompleteCredentialsService(), "tenant", "device", "myId", "myType", ctx);
  final Async remove = ctx.async();
  getCompleteCredentialsService().remove("tenant", "myType", "myId", ctx.asyncAssertSuccess(s -> {
    assertThat(s.getStatus(), is(HttpURLConnection.HTTP_NO_CONTENT));
    assertNotRegistered(getCompleteCredentialsService(), "tenant", "myId", "myType", ctx);
    remove.complete();
  }));
  remove.await();
}
origin: eclipse/hono

/**
 * Verifies that the service removes all credentials for a device but keeps credentials
 * of other devices.
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testRemoveCredentialsByDeviceSucceeds(final TestContext ctx) {
  register(getCompleteCredentialsService(), "tenant", "device", "myId", "myType", ctx);
  register(getCompleteCredentialsService(), "tenant", "device", "myOtherId", "myOtherType", ctx);
  register(getCompleteCredentialsService(), "tenant", "other-device", "thirdId", "myType", ctx);
  final Async remove = ctx.async();
  getCompleteCredentialsService().removeAll("tenant", "device", ctx.asyncAssertSuccess(s -> {
    assertThat(s.getStatus(), is(HttpURLConnection.HTTP_NO_CONTENT));
    assertNotRegistered(getCompleteCredentialsService(), "tenant", "myId", "myType", ctx);
    assertNotRegistered(getCompleteCredentialsService(), "tenant", "myOtherId", "myOtherType", ctx);
    assertRegistered(getCompleteCredentialsService(), "tenant", "thirdId", "myType", ctx);
    remove.complete();
  }));
  remove.await();
}
origin: eclipse/hono

/**
 * Verifies that service returns existing credentials for proper client context.
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testGetCredentialsSucceedsForProperClientContext(final TestContext ctx) {
  final JsonObject clientContext = new JsonObject()
      .put("client-id", "gateway-one");
  register(getCompleteCredentialsService(), "tenant", "device", "myId", "myType", clientContext, new JsonArray(), ctx);
  final Async get = ctx.async();
  getCompleteCredentialsService().get("tenant", "myType", "myId", clientContext, ctx.asyncAssertSuccess(s -> {
    assertThat(s.getStatus(), is(HttpURLConnection.HTTP_OK));
    assertThat(s.getPayload().getString(CredentialsConstants.FIELD_AUTH_ID), is("myId"));
    assertThat(s.getPayload().getString(CredentialsConstants.FIELD_TYPE), is("myType"));
    get.complete();
  }));
  get.await(2000);
}
origin: eclipse/hono

/**
 * Verifies that only one set of credentials can be registered for an auth-id and type (per tenant).
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testAddCredentialsRefusesDuplicateRegistration(final TestContext ctx) {
  register(getCompleteCredentialsService(), "tenant", "device", "myId", "myType", ctx);
  final JsonObject payload2 = new JsonObject()
      .put(CredentialsConstants.FIELD_PAYLOAD_DEVICE_ID, "other-device")
      .put(CredentialsConstants.FIELD_AUTH_ID, "myId")
      .put(CredentialsConstants.FIELD_TYPE, "myType")
      .put(CredentialsConstants.FIELD_SECRETS, new JsonArray());
  final Async add = ctx.async();
  getCompleteCredentialsService().add("tenant", payload2, ctx.asyncAssertSuccess(s -> {
    assertThat(s.getStatus(), is(HttpURLConnection.HTTP_CONFLICT));
    add.complete();
  }));
  add.await();
}
origin: eclipse/hono

protected static void assertRegistered(
    final CompleteCredentialsService svc,
    final String tenant,
    final String authId,
    final String type,
    final TestContext ctx) {
  final Async registration = ctx.async();
  svc.get(tenant, type, authId, ctx.asyncAssertSuccess(t -> {
    assertThat(t.getStatus(), is(HttpURLConnection.HTTP_OK));
    registration.complete();
  }));
  registration.await();
}
origin: eclipse/hono

protected static void assertNotRegistered(
    final CompleteCredentialsService svc,
    final String tenant,
    final String authId,
    final String type,
    final TestContext ctx) {
  final Async registration = ctx.async();
  svc.get(tenant, type, authId, ctx.asyncAssertSuccess(t -> {
    assertThat(t.getStatus(), is(HttpURLConnection.HTTP_NOT_FOUND));
    registration.complete();
  }));
  registration.await();
}
origin: eclipse/hono

/**
 * Verifies that the service returns existing credentials.
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testGetCredentialsSucceedsForExistingCredentials(final TestContext ctx) {
  register(getCompleteCredentialsService(), "tenant", "device", "myId", "myType", ctx);
  final Async get = ctx.async();
  getCompleteCredentialsService().get("tenant", "myType", "myId", ctx.asyncAssertSuccess(s -> {
    assertThat(s.getStatus(), is(HttpURLConnection.HTTP_OK));
    assertThat(s.getPayload().getString(CredentialsConstants.FIELD_AUTH_ID), is("myId"));
    assertThat(s.getPayload().getString(CredentialsConstants.FIELD_TYPE), is("myType"));
    get.complete();
  }));
  get.await();
}
origin: eclipse/hono

/**
 * Verifies that the service returns 404 if a client wants to retrieve non-existing credentials.
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testGetCredentialsFailsForNonExistingCredentials(final TestContext ctx) {
  final Async get = ctx.async();
  getCompleteCredentialsService().get("tenant", "myType", "non-existing", ctx.asyncAssertSuccess(s -> {
    assertThat(s.getStatus(), is(HttpURLConnection.HTTP_NOT_FOUND));
    get.complete();
  }));
  get.await();
}
org.eclipse.hono.service.credentialsCompleteCredentialsService

Javadoc

A service for keeping record of device credentials. This interface presents all the available operations on the API.

Most used methods

  • add
    Adds credentials for a device.
  • get
  • getAll
    Gets all credentials registered for a device.
  • remove
    Removes credentials by authentication identifier and type.
  • removeAll
    Removes all credentials for a device.

Popular in Java

  • Updating database using SQL prepared statement
  • getSystemService (Context)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • notifyDataSetChanged (ArrayAdapter)
  • Menu (java.awt)
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • JButton (javax.swing)
  • JPanel (javax.swing)
  • Top 12 Jupyter Notebook extensions
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