ConnectPacketAuthHandler extends ExecutionContextAuthHandler<MqttConnectContext> { @Override public Future<JsonObject> parseCredentials(final MqttConnectContext context) { Objects.requireNonNull(context); if (context.deviceEndpoint() == null) { throw new IllegalArgumentException("no device endpoint"); } final Promise<JsonObject> result = Promise.promise(); final MqttAuth auth = context.deviceEndpoint().auth(); if (auth == null) { result.fail(new ClientErrorException( HttpURLConnection.HTTP_UNAUTHORIZED, "device did not provide credentials in CONNECT packet")); } else if (auth.getUsername() == null || auth.getPassword() == null) { result.fail(new ClientErrorException( HttpURLConnection.HTTP_UNAUTHORIZED, "device provided malformed credentials in CONNECT packet")); } else { final JsonObject credentialsJSON = new JsonObject() .put("username", auth.getUsername()) .put("password", auth.getPassword()) .put(PROPERTY_CLIENT_IDENTIFIER, context.deviceEndpoint().clientIdentifier()); result.complete(credentialsJSON); } return result.future(); } ConnectPacketAuthHandler(final DeviceCredentialsAuthProvider<UsernamePasswordCredentials> authProvider);  ConnectPacketAuthHandler(
            final DeviceCredentialsAuthProvider<UsernamePasswordCredentials> authProvider,
            final PreCredentialsValidationHandler<MqttConnectContext> preCredentialsValidationHandler); @Override Future<JsonObject> parseCredentials(final MqttConnectContext context);  }
@Test public void testParseCredentialsIncludesMqttClientId(final VertxTestContext ctx) { final MqttAuth auth = mock(MqttAuth.class); when(auth.getUsername()).thenReturn("sensor1@DEFAULT_TENANT"); when(auth.getPassword()).thenReturn("secret"); final MqttEndpoint endpoint = mock(MqttEndpoint.class); when(endpoint.auth()).thenReturn(auth); when(endpoint.clientIdentifier()).thenReturn("mqtt-device"); final MqttConnectContext context = MqttConnectContext.fromConnectPacket(endpoint, span); authHandler.parseCredentials(context) .onComplete(ctx.succeeding(info -> { ctx.verify(() -> { assertThat(info.getString("username")).isEqualTo("sensor1@DEFAULT_TENANT"); assertThat(info.getString("password")).isEqualTo("secret"); assertThat(info.getString(X509AuthHandler.PROPERTY_CLIENT_IDENTIFIER)).isEqualTo("mqtt-device"); }); ctx.completeNow(); })); }