use of org.eclipse.hono.service.amqp.AmqpEndpoint in project hono by eclipse.
the class SimpleAuthenticationServer method handleSenderOpen.
/**
* Handles a request from a client to establish a link for receiving messages from this server.
*
* @param con the connection to the client.
* @param sender the sender created for the link.
*/
@Override
protected void handleSenderOpen(final ProtonConnection con, final ProtonSender sender) {
final Source remoteSource = sender.getRemoteSource();
LOG.debug("client [{}] wants to open a link for receiving messages [address: {}]", con.getRemoteContainer(), remoteSource);
try {
final ResourceIdentifier targetResource = getResourceIdentifier(remoteSource.getAddress());
final AmqpEndpoint endpoint = getEndpoint(targetResource);
if (endpoint == null) {
LOG.debug("no endpoint registered for node [{}]", targetResource);
con.setCondition(ProtonHelper.condition(AmqpError.NOT_FOUND, "no such node")).close();
} else {
HonoUser user = Constants.getClientPrincipal(con);
if (Constants.SUBJECT_ANONYMOUS.equals(user.getName())) {
con.setCondition(ProtonHelper.condition(AmqpError.UNAUTHORIZED_ACCESS, "client must authenticate using SASL")).close();
} else {
Constants.copyProperties(con, sender);
sender.setSource(sender.getRemoteSource());
endpoint.onLinkAttach(con, sender, targetResource);
vertx.setTimer(5000, closeCon -> {
if (!con.isDisconnected()) {
LOG.debug("connection with client [{}] timed out after 5 seconds, closing connection", con.getRemoteContainer());
con.setCondition(ProtonHelper.condition("hono: inactivity", "client must retrieve token within 5 secs after opening connection")).close();
}
});
}
}
} catch (final IllegalArgumentException e) {
LOG.debug("client has provided invalid resource identifier as source address", e);
con.setCondition(ProtonHelper.condition(AmqpError.INVALID_FIELD, "malformed source address")).close();
}
}
Aggregations