As far as I can determine, it looks like the example shows how you can restrict the entire event bus to only connections that have a current login session, which definitely addresses question 1. Unless I'm stupid (which is certainly possible) I didn't see anything to address question 2.
I'm actually quite interested in this topic. I've been experimenting with using Vert.x in web apps for a while now but haven't ever taken on the auth portion. From my quick research, I think you can solve question 2 by changing his example to be something like this:
Turn line 109 in Server.java to this:
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
sockJSHandler.bridge(options, event -> {
String address = event.rawMessage().getString("address");
String token = address.replace("address.", "");
User user = event.socket().webUser();
user.isAuthorised(token, result -> {
if (result.failed()) {
event.fail("Failed to determine if user is authorized");
return;
}
if (result.result()) {
event.complete(true);
} else {
event.complete(false);
}
});
});
router.route("/eventbus/*").handler(sockJSHandler);
This should let you make a decision to let the message through the event bus based on the token. The other interesting thing that this allows you to do is inject the username or other user information into the message itself or the message headers by interacting with the rawMessage.
Paulo, did everything I write sound correct? I haven't actually done this before :-).