@Override public void start(Future<Void> startFuture) throws Exception { ShellService service = ShellService.create(vertx, new ShellServiceOptions(). setSSHOptions( new SSHTermOptions(). setHost("localhost"). setPort(3000). setKeyPairOptions(new JksOptions(). setPath("keystore.jks"). setPassword("wibble")). setAuthOptions(new ShiroAuthOptions(). setConfig(new JsonObject().put("properties_path", "auth.properties"))))); service.start(ar -> { if (ar.succeeded()) { startFuture.succeeded(); } else { startFuture.fail(ar.cause()); } }); } }
case "defaultCharset": if (member.getValue() instanceof String) { obj.setDefaultCharset((String)member.getValue()); obj.setHost((String)member.getValue()); obj.setIntputrc((String)member.getValue()); obj.setKeyPairOptions(new io.vertx.core.net.JksOptions((JsonObject)member.getValue())); obj.setPemKeyPairOptions(new io.vertx.core.net.PemKeyCertOptions((JsonObject)member.getValue())); obj.setPfxKeyPairOptions(new io.vertx.core.net.PfxOptions((JsonObject)member.getValue())); obj.setPort(((Number)member.getValue()).intValue());
public SSHServer(Vertx vertx, SSHTermOptions options) { this.vertx = vertx; this.options = new SSHTermOptions(options); }
/** * 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()); }
protected void startShell() throws Exception { startShell(new SSHTermOptions().setPort(5000).setHost("localhost").setKeyPairOptions( new JksOptions().setPath("src/test/resources/server-keystore.jks").setPassword("wibble")). setAuthOptions(new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig( new JsonObject().put("properties_path", "classpath:test-auth.properties")))); }
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 testNoKeyPairConfigured() throws Exception { try { startShell(new SSHTermOptions().setPort(5000).setHost("localhost"). setAuthOptions(new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig( new JsonObject().put("properties_path", "classpath:test-auth.properties"))) ); } catch (ExecutionException e) { assertTrue(e.getCause() instanceof VertxException); assertEquals("No key pair store configured", e.getCause().getMessage()); } }
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; } } }
@Test public void testKeymapFromFilesystem() throws Exception { URL url = TermServer.class.getResource(SSHTermOptions.DEFAULT_INPUTRC); File f = new File(url.toURI()); termHandler = Term::close; startShell(new SSHTermOptions().setIntputrc(f.getAbsolutePath()).setPort(5000).setHost("localhost").setKeyPairOptions( new JksOptions().setPath("src/test/resources/server-keystore.jks").setPassword("wibble")). setAuthOptions(new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig( new JsonObject().put("properties_path", "classpath:test-auth.properties")))); Session session = createSession("paulo", "secret", false); session.connect(); Channel channel = session.openChannel("shell"); channel.connect(); }
public static io.vertx.ext.shell.term.TermServer createSSHTermServer(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.createSSHTermServer(vertx, options != null ? new io.vertx.ext.shell.term.SSHTermOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null)); } public static io.vertx.ext.shell.term.TermServer createTelnetTermServer(io.vertx.ext.shell.term.TermServer j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options) {
@Test public void testNoAuthenticationConfigured() throws Exception { try { startShell(new SSHTermOptions().setPort(5000).setHost("localhost").setKeyPairOptions( new JksOptions().setPath("src/test/resources/server-keystore.jks").setPassword("wibble")) ); fail(); } catch (ExecutionException e) { assertTrue(e.getCause() instanceof VertxException); assertEquals("No authenticator", e.getCause().getMessage()); } }
@Test public void testDifferentCharset(TestContext context) throws Exception { termHandler = term -> { term.write("\u20AC"); term.close(); }; startShell(new SSHTermOptions().setDefaultCharset("ISO_8859_1").setPort(5000).setHost("localhost").setKeyPairOptions( new JksOptions().setPath("src/test/resources/server-keystore.jks").setPassword("wibble")). setAuthOptions(new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig( new JsonObject().put("properties_path", "classpath:test-auth.properties")))); Session session = createSession("paulo", "secret", false); session.connect(); Channel channel = session.openChannel("shell"); channel.connect(); InputStream in = channel.getInputStream(); int b = in.read(); context.assertEquals(63, b); }
@Test public void testExternalAuthProviderFails(TestContext context) throws Exception { AtomicInteger count = new AtomicInteger(); authProvider = (authInfo, resultHandler) -> { count.incrementAndGet(); resultHandler.handle(Future.failedFuture("not authenticated")); }; termHandler = term -> { context.fail(); }; startShell(new SSHTermOptions().setPort(5000).setHost("localhost").setKeyPairOptions( new JksOptions().setPath("src/test/resources/server-keystore.jks").setPassword("wibble"))); Session session = createSession("paulo", "anothersecret", false); try { session.connect(); context.fail("Was not expected to login"); } catch (JSchException e) { assertEquals("Auth cancel", e.getMessage()); } context.assertEquals(1, count.get()); }
async.complete(); }; startShell(new SSHTermOptions().setPort(5000).setHost("localhost").setKeyPairOptions( new JksOptions().setPath("src/test/resources/server-keystore.jks").setPassword("wibble"))); Session session = createSession("paulo", "anothersecret", false);
setType(ShiroAuthRealmType.PROPERTIES). setConfig(new JsonObject().put("properties_path", "file:src/test/resources/test-auth.properties")); SSHTermOptions options = new SSHTermOptions().setPort(5001); options.setKeyPairOptions(new JksOptions(). setPath("src/test/resources/server-keystore.jks"). setPassword("wibble")). setAuthOptions( authOptions );