}
protected ContextSelector<EJBClientContext> setupEJBClientContextSelector(String username, String password) throws IOException {
// create the endpoint
final Endpoint endpoint = Remoting.createEndpoint("remoting-test", OptionMap.create(Options.THREAD_DAEMON, true));
endpoint.addConnectionProvider("remote", new RemoteConnectionProviderFactory(), OptionMap.create(Options.SSL_ENABLED, false));
final URI connectionURI = managementClient.getRemoteEjbURL();
OptionMap.Builder builder = OptionMap.builder().set(Options.SASL_POLICY_NOANONYMOUS, true);
builder.set(Options.SASL_POLICY_NOPLAINTEXT, false);
if (password != null) {
builder.set(Options.SASL_DISALLOWED_MECHANISMS, Sequence.of("JBOSS-LOCAL-USER"));
} else {
builder.set(Options.SASL_MECHANISMS, Sequence.of("JBOSS-LOCAL-USER"));
}
final IoFuture<Connection> futureConnection = endpoint.connect(connectionURI, builder.getMap(), new AuthenticationCallbackHandler(username, password));
// wait for the connection to be established
final Connection connection = IoFutureHelper.get(futureConnection, 5000, TimeUnit.MILLISECONDS);
// create a remoting EJB receiver for this connection
final EJBReceiver receiver = new RemotingConnectionEJBReceiver(connection);
// associate it with the client context