use of io.vertx.proton.sasl.ProtonSaslAuthenticator in project vertx-proton by vert-x3.
the class ProtonServerImplTest method testCustomAuthenticatorHasInitCalled.
@Test(timeout = 20000)
public void testCustomAuthenticatorHasInitCalled(TestContext context) {
Async initCalledAsync = context.async();
ProtonServer.create(vertx).saslAuthenticatorFactory(new ProtonSaslAuthenticatorFactory() {
@Override
public ProtonSaslAuthenticator create() {
return new ProtonSaslAuthenticator() {
@Override
public void init(NetSocket socket, ProtonConnection protonConnection, Transport transport) {
initCalledAsync.complete();
}
@Override
public void process(Handler<Boolean> completionHandler) {
completionHandler.handle(false);
}
@Override
public boolean succeeded() {
return false;
}
};
}
}).connectHandler(protonConnection -> {
}).listen(server -> ProtonClient.create(vertx).connect("localhost", server.result().actualPort(), protonConnectionAsyncResult -> {
}));
}
use of io.vertx.proton.sasl.ProtonSaslAuthenticator in project vertx-proton by vert-x3.
the class ProtonServerImpl method connectHandler.
@Override
public ProtonServerImpl connectHandler(Handler<ProtonConnection> handler) {
this.handler = handler;
server.connectHandler(netSocket -> {
String hostname = null;
try {
hostname = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
// ignore
}
final ProtonConnectionImpl connection = new ProtonConnectionImpl(vertx, hostname);
if (advertiseAnonymousRelayCapability) {
connection.setOfferedCapabilities(new Symbol[] { ProtonConnectionImpl.ANONYMOUS_RELAY });
}
final ProtonSaslAuthenticator authenticator = authenticatorFactory.create();
ProtonTransportOptions transportOptions = new ProtonTransportOptions();
transportOptions.setHeartbeat(this.options.getHeartbeat());
transportOptions.setMaxFrameSize(this.options.getMaxFrameSize());
connection.bindServer(netSocket, new ProtonSaslAuthenticator() {
@Override
public void init(NetSocket socket, ProtonConnection protonConnection, Transport transport) {
authenticator.init(socket, protonConnection, transport);
}
@Override
public void process(Handler<Boolean> completionHandler) {
final Context context = Vertx.currentContext();
authenticator.process(complete -> {
final Context callbackContext = vertx.getOrCreateContext();
if (context != callbackContext) {
throw new IllegalStateException("Callback was not made on the original context");
}
if (complete) {
// The authenticator completed, now check success, do required post processing
if (succeeded()) {
handler.handle(connection);
connection.flush();
} else {
// auth failed, flush any pending data and disconnect client
connection.flush();
connection.disconnect();
}
}
completionHandler.handle(complete);
});
}
@Override
public boolean succeeded() {
return authenticator.succeeded();
}
}, transportOptions);
});
return this;
}
Aggregations