use of org.eclipse.hono.util.ResourceIdentifier in project hono by eclipse.
the class FileBasedAuthenticationServiceTest method testVerifyPlainAddsAuthoritiesForOperations.
@Test
public void testVerifyPlainAddsAuthoritiesForOperations(final TestContext ctx) {
final ResourceIdentifier registration = ResourceIdentifier.fromString("registration/tenant");
authService.verifyPlain(null, "hono-client@HONO", "secret", ctx.asyncAssertSuccess(res -> {
assertTrue(res.getAuthorities().isAuthorized(registration, "assert"));
assertTrue(res.getAuthorities().isAuthorized(registration, "add"));
}));
}
use of org.eclipse.hono.util.ResourceIdentifier in project hono by eclipse.
the class ForwardingDownstreamAdapter method onClientAttach.
@Override
public final void onClientAttach(final UpstreamReceiver client, final Handler<AsyncResult<Void>> resultHandler) {
if (!running) {
throw new IllegalStateException("adapter must be started first");
}
Objects.requireNonNull(client);
Objects.requireNonNull(resultHandler);
ProtonSender sender = activeSenders.get(client);
if (sender != null && sender.isOpen()) {
logger.info("reusing existing downstream sender [con: {}, link: {}]", client.getConnectionId(), client.getLinkId());
resultHandler.handle(Future.succeededFuture());
} else {
removeSender(client);
// register the result handler to be failed if the connection to the downstream container fails during
// the attempt to create a downstream sender
clientAttachHandlers.add(resultHandler);
Future<Void> tracker = Future.future();
tracker.setHandler(attempt -> {
if (attempt.succeeded()) {
logger.info("created downstream sender [con: {}, link: {}]", client.getConnectionId(), client.getLinkId());
} else {
logger.warn("can't create downstream sender [con: {}, link: {}]: {}", client.getConnectionId(), client.getLinkId(), attempt.cause().getMessage());
}
clientAttachHandlers.remove(resultHandler);
resultHandler.handle(attempt);
});
final ResourceIdentifier targetAddress = ResourceIdentifier.fromString(client.getTargetAddress());
createSender(targetAddress, replenishedSender -> handleFlow(replenishedSender, client), closeHook -> {
removeSender(client);
closeReceiver(client);
}).compose(createdSender -> {
addSender(client, createdSender);
tracker.complete();
}, tracker);
}
}
use of org.eclipse.hono.util.ResourceIdentifier in project hono by eclipse.
the class MessageForwardingEndpoint method forwardMessage.
final void forwardMessage(final UpstreamReceiver link, final ProtonDelivery delivery, final Message msg) {
final ResourceIdentifier messageAddress = ResourceIdentifier.fromString(getAnnotation(msg, MessageHelper.APP_PROPERTY_RESOURCE, String.class));
final String token = MessageHelper.getAndRemoveRegistrationAssertion(msg);
if (assertRegistration(token, messageAddress)) {
downstreamAdapter.processMessage(link, delivery, msg);
} else {
logger.debug("failed to validate device registration status");
rejectMessage(delivery, ProtonHelper.condition(AmqpError.PRECONDITION_FAILED, "device non-existent/disabled"), link);
}
}
use of org.eclipse.hono.util.ResourceIdentifier in project hono by eclipse.
the class EventEndpointTest method testOnLinkAttachDisconnectsClientsUsingWrongQos.
/**
* Verifies that the endpoint rejects a client's attempt to create a link using <em>AT_MOST_ONCE</em>
* delivery mode.
*/
@Test
public void testOnLinkAttachDisconnectsClientsUsingWrongQos() {
ProtonConnection con = mock(ProtonConnection.class);
ProtonReceiver receiver = mock(ProtonReceiver.class);
when(receiver.getRemoteQoS()).thenReturn(ProtonQoS.AT_MOST_ONCE);
ResourceIdentifier targetAddress = ResourceIdentifier.from("event", "tenant", null);
endpoint.onLinkAttach(con, receiver, targetAddress);
ArgumentCaptor<ErrorCondition> errorCondition = ArgumentCaptor.forClass(ErrorCondition.class);
verify(receiver).setCondition(errorCondition.capture());
assertThat(errorCondition.getValue(), is(ErrorConditions.ERROR_UNSUPPORTED_DELIVERY_MODE));
verify(receiver).close();
}
use of org.eclipse.hono.util.ResourceIdentifier in project hono by eclipse.
the class HonoMessagingMessageFilterTest method testVerifyDetectsMissingDeviceId.
@Test
public void testVerifyDetectsMissingDeviceId() {
// GIVEN a valid telemetry message without device id
final Message msg = givenAMessageHavingProperties(null);
// WHEN receiving the message via a link with mismatching tenant
final ResourceIdentifier linkTarget = getResourceIdentifier(MY_TENANT);
// THEN message validation fails
assertFalse(HonoMessagingMessageFilter.verify(linkTarget, msg));
}
Aggregations