@Override public void start(Future<Void> startFuture) throws Exception { ShellService service = ShellService.create(vertx, new ShellServiceOptions(). setHttpOptions( new HttpTermOptions(). setHost("localhost"). setPort(8080). setAuthOptions(new ShiroAuthOptions(). setConfig(new JsonObject().put("properties_path", "auth.properties"))))); service.start(ar -> { if (ar.succeeded()) { startFuture.succeeded(); } else { startFuture.fail(ar.cause()); } }); } }
server = createServer(context, new HttpTermOptions().setPort(8080)); server.authProvider(authProvider); server.termHandler(term -> {
@Test public void testSecure(TestContext context) { Async async = context.async(); server = createServer(context, new HttpTermOptions().setAuthOptions( new ShiroAuthOptions(). setType(ShiroAuthRealmType.PROPERTIES). setConfig(new JsonObject().put("properties_path", "classpath:test-auth.properties"))).setPort(8080)); server.termHandler(term -> { term.write("hello"); }); server.listen(context.asyncAssertSuccess(server -> { HttpClient client = vertx.createHttpClient(); client.websocket(8080, "localhost", basePath + "/shell/websocket", ws -> { context.fail(); }, err -> { // Retry now with auth client.websocket(8080, "localhost", basePath + "/shell/websocket", new CaseInsensitiveHeaders().add("Authorization", "Basic " + Base64.getEncoder().encodeToString("tim:sausages".getBytes())), ws -> { ws.handler(buf -> { context.assertEquals("hello", buf.toString()); async.complete(); }); }, context::fail); }); })); }
/** * 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()); }
case "charset": if (member.getValue() instanceof String) { obj.setCharset((String)member.getValue()); obj.setIntputrc((String)member.getValue()); obj.setShellHtmlResource(io.vertx.core.buffer.Buffer.buffer(java.util.Base64.getDecoder().decode((String)member.getValue()))); obj.setSockJSHandlerOptions(new io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions((JsonObject)member.getValue())); obj.setSockJSPath((String)member.getValue()); obj.setTermJsResource(io.vertx.core.buffer.Buffer.buffer(java.util.Base64.getDecoder().decode((String)member.getValue()))); obj.setVertsShellJsResource(io.vertx.core.buffer.Buffer.buffer(java.util.Base64.getDecoder().decode((String)member.getValue())));
@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); })); } }
@Test public void testDifferentCharset(TestContext context) throws Exception { Async async = context.async(); server = createServer(context, new HttpTermOptions().setPort(8080).setCharset("ISO_8859_1")); server.termHandler(term -> { term.write("\u20AC"); term.close(); }); 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.assertTrue(Arrays.equals(new byte[]{63}, buf.getBytes())); async.complete(); }); }, context::fail); })); }
private void init() { sockJSHandlerOptions = new SockJSHandlerOptions(); sockJSPath = DEFAULT_SOCKJSPATH; vertsShellJsResource = defaultVertxShellJsResource(); termJsResource = defaultTermJsResource(); shellHtmlResource = defaultShellHtmlResource(); charset = DEFAULT_CHARSET; intputrc = DEFAULT_INPUTRC; }
@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(); }); })); }
setTelnetOptions(new TelnetTermOptions().setPort(5000)). setSSHOptions(options). setHttpOptions(new HttpTermOptions(). setPort(8080). setAuthOptions(authOptions)
/** * Create a term server for the HTTP protocol, using an existing router. * * @param vertx the vertx instance * @param router the router * @return the term server */ static TermServer createHttpTermServer(Vertx vertx, Router router) { return createHttpTermServer(vertx, router, new HttpTermOptions()); }
@Test public void testServerRead(TestContext context) { Async async = context.async(); server = createServer(context, new HttpTermOptions().setPort(8080)); server.termHandler(term -> { term.stdinHandler(buf -> { context.assertEquals("hello_from_client", buf); async.complete(); }); }); server.listen(context.asyncAssertSuccess(server -> { HttpClient client = vertx.createHttpClient(); client.websocket(8080, "localhost", basePath + "/shell/websocket", ws -> { ws.writeFinalTextFrame(new JsonObject().put("action", "read").put("data", "hello_from_client").encode()); }, context::fail); })); }
public ShellServiceOptions(ShellServiceOptions that) { super(that); this.telnetOptions = that.telnetOptions != null ? new TelnetTermOptions(that.telnetOptions) : null; this.sshOptions = that.sshOptions != null ? new SSHTermOptions(that.sshOptions) : null; this.httpOptions = that.httpOptions != null ? new HttpTermOptions(that.httpOptions) : null; }
@Test public void testResizeInvalid(TestContext context) { Async async = context.async(); server = createServer(context, new HttpTermOptions().setPort(8080));; server.termHandler(term -> { term.resizehandler(v -> { context.fail(); }); }); server.listen(context.asyncAssertSuccess(server -> { HttpClient client = vertx.createHttpClient(); client.websocket(8080, "localhost", basePath + "/shell/websocket", ws -> { ws.writeFinalTextFrame(new JsonObject().put("action", "resize").put("cols", -50).encode()); vertx.setTimer(1000, id -> { async.complete(); }); }, context::fail); })); }
public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, ShellServiceOptions obj) { for (java.util.Map.Entry<String, Object> member : json) { switch (member.getKey()) { case "httpOptions": if (member.getValue() instanceof JsonObject) { obj.setHttpOptions(new io.vertx.ext.shell.term.HttpTermOptions((JsonObject)member.getValue())); } break; case "sshOptions": if (member.getValue() instanceof JsonObject) { obj.setSSHOptions(new io.vertx.ext.shell.term.SSHTermOptions((JsonObject)member.getValue())); } break; case "telnetOptions": if (member.getValue() instanceof JsonObject) { obj.setTelnetOptions(new io.vertx.ext.shell.term.TelnetTermOptions((JsonObject)member.getValue())); } break; } } }
private void testSize(TestContext context, String uri, int expectedCols, int expectedRows) { Async async = context.async(); server = createServer(context, new HttpTermOptions().setPort(8080));; server.termHandler(term -> { context.assertEquals(expectedCols, term.width()); context.assertEquals(expectedRows, term.height()); async.complete(); }); server.listen(context.asyncAssertSuccess(server -> { HttpClient client = vertx.createHttpClient(); client.websocket(8080, "localhost", uri, ws -> { }, context::fail); })); }
public static io.vertx.ext.shell.term.TermServer createHttpTermServer(io.vertx.ext.shell.term.TermServer j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.ext.shell.term.TermServer.createHttpTermServer(vertx, options != null ? new io.vertx.ext.shell.term.HttpTermOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null)); } public static io.vertx.ext.shell.term.TermServer createHttpTermServer(io.vertx.ext.shell.term.TermServer j_receiver, io.vertx.core.Vertx vertx, io.vertx.ext.web.Router router, java.util.Map<String, Object> options) {
@Test public void testServerWrite(TestContext context) { Async async = context.async(); server = createServer(context, new HttpTermOptions().setPort(8080)); server.termHandler(term -> { term.write("hello_from_server"); }); server.listen(context.asyncAssertSuccess(server -> { HttpClient client = vertx.createHttpClient(); client.websocket(8080, "localhost", basePath + "/shell/websocket", ws -> { ws.handler(buf -> { context.assertEquals("hello_from_server", buf.toString()); async.complete(); }); }, context::fail); })); }
public static io.vertx.ext.shell.term.TermServer createHttpTermServer(io.vertx.ext.shell.term.TermServer j_receiver, io.vertx.core.Vertx vertx, io.vertx.ext.web.Router router, java.util.Map<String, Object> options) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.ext.shell.term.TermServer.createHttpTermServer(vertx, router, options != null ? new io.vertx.ext.shell.term.HttpTermOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null)); } }
private void testResize(TestContext context, JsonObject event, int expectedCols, int expectedRows) { Async async = context.async(); server = createServer(context, new HttpTermOptions().setPort(8080));; server.termHandler(term -> { term.resizehandler(v -> { context.assertEquals(expectedCols, term.width()); context.assertEquals(expectedRows, term.height()); async.complete(); }); }); server.listen(context.asyncAssertSuccess(server -> { HttpClient client = vertx.createHttpClient(); client.websocket(8080, "localhost", basePath + "/shell/websocket", ws -> { ws.writeFinalTextFrame(event.encode()); }, context::fail); })); }