@Override public void start(Future<Void> startFuture) throws Exception { termServer = TermServer.createTelnetTermServer(vertx, new TelnetTermOptions().setHost("localhost").setPort(3000).setInBinary(false)); Robot robot = new Robot(); termServer.termHandler(term -> { new ScreenCaster(vertx, robot, term).handle(); }); termServer.listen(ar -> { if (ar.succeeded()) { startFuture.complete(); } else { startFuture.fail(ar.cause()); } }); }
@Override public void stop() throws Exception { termServer.close(); } }
}); termServer.termHandler(this::handleTerm); termServer.listen(handler); }); return this;
protected void startShell(SSHTermOptions options) throws ExecutionException, InterruptedException, TimeoutException { if (server != null) { throw new IllegalStateException(); } server = TermServer.createSSHTermServer(vertx, options); CompletableFuture<Void> fut = new CompletableFuture<>(); server.termHandler(termHandler); ((SSHServer)server).setExecHandler(execHandler); server.authProvider(authProvider); server.listen(ar -> { if (ar.succeeded()) { fut.complete(null); } else { fut.completeExceptionally(ar.cause()); } }); fut.get(10, TimeUnit.SECONDS); }
/** * Create a term server for the HTTP protocol. * * @param vertx the vertx instance * @return the term server */ static TermServer createHttpTermServer(Vertx vertx) { return createHttpTermServer(vertx, new HttpTermOptions()); }
@Test public void testExternalAuthProviderFails(TestContext context) throws Exception { AtomicInteger count = new AtomicInteger(); AuthProvider authProvider = (authInfo, resultHandler) -> { count.incrementAndGet(); resultHandler.handle(Future.failedFuture("not authenticated")); }; Async async = context.async(); server = createServer(context, new HttpTermOptions().setPort(8080)); server.authProvider(authProvider); server.termHandler(term -> { context.fail(); }); server.listen(context.asyncAssertSuccess(server -> { HttpClient client = vertx.createHttpClient(); client.websocket(8080, "localhost", basePath + "/shell/websocket", new CaseInsensitiveHeaders().add("Authorization", "Basic " + Base64.getEncoder().encodeToString("paulo:anothersecret".getBytes())), ws -> { context.fail(); }, err -> { assertEquals(1, count.get()); async.complete(); }); })); }
}); TelnetTermOptions tto = new TelnetTermOptions().setPort(3000).setHost("localhost"); TermServer telnetTermServer = TermServer.createTelnetTermServer(vertx,tto); server.registerTermServer(telnetTermServer);
/** * Create a term server for the SSH protocol. * * @param vertx the vertx instance * @return the term server */ static TermServer createSSHTermServer(Vertx vertx) { return createSSHTermServer(vertx, new SSHTermOptions()); }
/** * Bind the term server, the {@link io.vertx.rxjava.ext.shell.term.TermServer#termHandler} must be set before. * @return this object */ public io.vertx.rxjava.ext.shell.term.TermServer listen() { delegate.listen(); return this; }
/** * The actual port the server is listening on. This is useful if you bound the server specifying 0 as port number * signifying an ephemeral port * @return the actual port the server is listening on. */ public int actualPort() { int ret = delegate.actualPort(); return ret; }
/** * Set the term handler that will receive incoming client connections. When a remote terminal connects * the <code>handler</code> will be called with the {@link io.vertx.rxjava.ext.shell.term.Term} which can be used to interact with the remote * terminal. * @param handler the term handler * @return this object */ public io.vertx.rxjava.ext.shell.term.TermServer termHandler(Handler<io.vertx.rxjava.ext.shell.term.Term> handler) { delegate.termHandler(new Handler<io.vertx.ext.shell.term.Term>() { public void handle(io.vertx.ext.shell.term.Term event) { handler.handle(io.vertx.rxjava.ext.shell.term.Term.newInstance(event)); } }); return this; }
/** * Set an auth provider to use, any provider configured in options will override this provider. This should be used * when a custom auth provider should be used. * @param provider the auth to use * @return this object */ public io.vertx.rxjava.ext.shell.term.TermServer authProvider(io.vertx.rxjava.ext.auth.AuthProvider provider) { delegate.authProvider(provider.getDelegate()); return this; }
@Test public void testKeymapFromFilesystem(TestContext context) throws Exception { URL url = TermServer.class.getResource(SSHTermOptions.DEFAULT_INPUTRC); File f = new File(url.toURI()); Async async = context.async(); server = createServer(context, new HttpTermOptions().setPort(8080).setIntputrc(f.getAbsolutePath())); server.termHandler(term -> { term.close(); async.complete(); }); server.listen(context.asyncAssertSuccess(server -> { HttpClient client = vertx.createHttpClient(); client.websocket(8080, "localhost", basePath + "/shell/websocket", new CaseInsensitiveHeaders().add("Authorization", "Basic " + Base64.getEncoder().encodeToString("paulo:anothersecret".getBytes())), ws -> { ws.handler(buf -> { }); }, context::fail); })); } }
@Override protected TermServer createServer(TestContext context, HttpTermOptions options) { return TermServer.createHttpTermServer(vertx, options); } }
Async async = context.async(2); server = createServer(context, new HttpTermOptions().setPort(8080)); server.authProvider(authProvider); server.termHandler(term -> { context.assertEquals(1, count.get()); async.countDown(); }); server.listen(context.asyncAssertSuccess(server -> { HttpClient client = vertx.createHttpClient(); client.websocket(8080, "localhost", basePath + "/shell/websocket", new CaseInsensitiveHeaders().add("Authorization", "Basic " + Base64.getEncoder().encodeToString("paulo:anothersecret".getBytes())), ws -> {
/** * Create a term server for the Telnet protocol. * * @param vertx the vertx instance * @return the term server */ static TermServer createTelnetTermServer(Vertx vertx) { return createTelnetTermServer(vertx, new TelnetTermOptions()); }
/** * Create a term server for the SSH protocol. * @param vertx the vertx instance * @param options the ssh options * @return the term server */ public static io.vertx.rxjava.ext.shell.term.TermServer createSSHTermServer(io.vertx.rxjava.core.Vertx vertx, SSHTermOptions options) { io.vertx.rxjava.ext.shell.term.TermServer ret = io.vertx.rxjava.ext.shell.term.TermServer.newInstance(io.vertx.ext.shell.term.TermServer.createSSHTermServer(vertx.getDelegate(), options)); return ret; }
/** * Bind the term server, the {@link io.vertx.rxjava.ext.shell.term.TermServer#termHandler} must be set before. * @return this object */ public io.vertx.rxjava.ext.shell.term.TermServer listen() { delegate.listen(); return this; }
/** * The actual port the server is listening on. This is useful if you bound the server specifying 0 as port number * signifying an ephemeral port * @return the actual port the server is listening on. */ public int actualPort() { int ret = delegate.actualPort(); return ret; }
/** * Set the term handler that will receive incoming client connections. When a remote terminal connects * the <code>handler</code> will be called with the {@link io.vertx.rxjava.ext.shell.term.Term} which can be used to interact with the remote * terminal. * @param handler the term handler * @return this object */ public io.vertx.rxjava.ext.shell.term.TermServer termHandler(Handler<io.vertx.rxjava.ext.shell.term.Term> handler) { delegate.termHandler(new Handler<io.vertx.ext.shell.term.Term>() { public void handle(io.vertx.ext.shell.term.Term event) { handler.handle(io.vertx.rxjava.ext.shell.term.Term.newInstance(event)); } }); return this; }