org.apache.sshd.server.Environment Java Examples
The following examples show how to use
org.apache.sshd.server.Environment.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WindowAdjustTest.java From termd with Apache License 2.0 | 6 votes |
@Override public void start(Environment env) throws IOException { log.info("Starting"); ExecutorService service = ThreadUtils.newSingleThreadExecutor(getClass().getSimpleName() + "-" + POOL_COUNT.incrementAndGet()); executorHolder.set(service); futureHolder.set(service.submit(new Runnable() { @SuppressWarnings("synthetic-access") @Override public void run() { log.info("Start heavy load sending " + sendCount + " messages of " + msg.length + " bytes"); for (int i = 0; i < sendCount; i++) { pendingWrapper.write(new ByteArrayBuffer(msg)); } log.info("Sending EOF signal"); pendingWrapper.write(new ByteArrayBuffer(new byte[]{eofSignal})); } })); log.info("Started"); }
Example #2
Source File: ConsoleShellFactory.java From Bukkit-SSHD with Apache License 2.0 | 6 votes |
public void start(Environment env) throws IOException { try { consoleReader = new ConsoleReader(in, new FlushyOutputStream(out), new SshTerminal()); consoleReader.setExpandEvents(true); consoleReader.addCompleter(new ConsoleCommandCompleter()); StreamHandler streamHandler = new FlushyStreamHandler(out, new ConsoleLogFormatter(), consoleReader); streamHandlerAppender = new StreamHandlerAppender(streamHandler); ((Logger) LogManager.getRootLogger()).addAppender(streamHandlerAppender); environment = env; thread = new Thread(this, "SSHD ConsoleShell " + env.getEnv().get(Environment.ENV_USER)); thread.start(); } catch (Exception e) { throw new IOException("Error starting shell", e); } }
Example #3
Source File: WindowAdjustTest.java From termd with Apache License 2.0 | 6 votes |
@Override public void start(Environment env) throws IOException { log.info("Starting"); ExecutorService service = ThreadUtils.newSingleThreadExecutor(getClass().getSimpleName() + "-" + POOL_COUNT.incrementAndGet()); executorHolder.set(service); futureHolder.set(service.submit(new Runnable() { @SuppressWarnings("synthetic-access") @Override public void run() { log.info("Start heavy load sending " + sendCount + " messages of " + msg.length + " bytes"); for (int i = 0; i < sendCount; i++) { pendingWrapper.write(new ByteArrayBuffer(msg)); } log.info("Sending EOF signal"); pendingWrapper.write(new ByteArrayBuffer(new byte[]{eofSignal})); } })); log.info("Started"); }
Example #4
Source File: Server.java From sftpserver with Apache License 2.0 | 5 votes |
@Override public void start(final ChannelSession channel, final Environment env) throws IOException { if (err != null) { err.write("shell not allowed\r\n".getBytes("ISO-8859-1")); err.flush(); } if (callback != null) callback.onExit(-1, "shell not allowed"); }
Example #5
Source File: ConsoleShellFactory.java From Bukkit-SSHD with Apache License 2.0 | 5 votes |
public void run() { try { if (!SshdPlugin.instance.getConfig().getString("mode").equals("RPC")) printPreamble(consoleReader); while (true) { String command = consoleReader.readLine("\r>", null); if (command == null) continue; if (command.equals("exit") || command.equals("quit")) break; Bukkit.getScheduler().runTask(SshdPlugin.instance, () -> { if (SshdPlugin.instance.getConfig().getString("mode").equals("RPC") && command.startsWith("rpc")) { //NO ECHO NO PREAMBLE AND SHIT String cmd = command.substring("rpc".length() + 1, command.length()); Bukkit.dispatchCommand(sshdCommandSender, cmd); } else { SshdPlugin.instance.getLogger() .info("<" + environment.getEnv().get(Environment.ENV_USER) + "> " + command); Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); } }); } } catch (IOException e) { SshdPlugin.instance.getLogger().log(Level.SEVERE, "Error processing command from SSH", e); } finally { callback.onExit(0); } }
Example #6
Source File: ConsoleCommandFactory.java From Bukkit-SSHD with Apache License 2.0 | 5 votes |
@Override public void start(Environment environment) throws IOException { try { SshdPlugin.instance.getLogger() .info("[U: " + environment.getEnv().get(Environment.ENV_USER) + "] " + command); Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); } catch (Exception e) { SshdPlugin.instance.getLogger().severe("Error processing command from SSH -" + e.getMessage()); } finally { callback.onExit(0); } }
Example #7
Source File: NetconfSshdTestSubsystem.java From onos with Apache License 2.0 | 5 votes |
@Override public void start(Environment env) throws IOException { this.env = env; state = NetconfMessageState.NO_MATCHING_PATTERN; outputStream = new PrintWriter(out, false); try { pendingFuture = executors.submit(this); } catch (RuntimeException e) { // e.g., RejectedExecutionException log.error("Failed (" + e.getClass().getSimpleName() + ") to start command: " + e.getMessage(), e); throw new IOException(e); } }
Example #8
Source File: SshdServerMock.java From gerrit-events with MIT License | 5 votes |
/** * Default implementation just waits for the command to be destroyed. * * @param environment env. * @throws IOException if so. */ @Override public void start(Environment environment) throws IOException { System.out.println("Starting command: " + command); //Default implementation just waits for a disconnect while (!isDestroyed()) { try { synchronized (this) { this.wait(WAIT_FOR_DESTROYED); } } catch (InterruptedException e) { System.err.println("[SSHD-CommandMock] Awake."); } } }
Example #9
Source File: SshEchoCommandFactory.java From ExpectIt with Apache License 2.0 | 5 votes |
@Override public Command create() { return new Command() { @Override public void setInputStream(InputStream in) { SshEchoCommandFactory.this.in = in; } @Override public void setOutputStream(OutputStream out) { SshEchoCommandFactory.this.out = out; } @Override public void setErrorStream(OutputStream err) { } @Override public void setExitCallback(ExitCallback callback) { } @Override public void start(Environment env) throws IOException { executor.scheduleWithFixedDelay( SshEchoCommandFactory.this, 0, 100, TimeUnit.MILLISECONDS); } @Override public void destroy() { executor.shutdownNow(); } }; }
Example #10
Source File: NewScpHelper.java From artifactory_ssh_proxy with Apache License 2.0 | 5 votes |
public NewScpHelper(@Nonnull final InputStream in, @Nonnull final OutputStream out, @Nonnull final FileSystemView root, final LoggingHelper loggingHelper, @Nonnull Environment env, @Nonnull Map<String, String> envToAfPropertyMapping) { super(in, out, root); this.loggingHelper = loggingHelper; this.env = env; this.envToAfPropertyMapping = envToAfPropertyMapping; }
Example #11
Source File: MkdirCommand.java From artifactory_ssh_proxy with Apache License 2.0 | 5 votes |
@Override public void start(Environment env) throws IOException { if (error != null) { throw error; } new Thread(this, "MkdirCommand: " + name).start(); }
Example #12
Source File: ForwardingShellWrapper.java From artifactory_ssh_proxy with Apache License 2.0 | 5 votes |
@Override public synchronized void start(Environment env) throws IOException { // TODO propagate the Environment itself and support signal sending. executor.execute(new Runnable() { @Override public void run() { runShell(); } }); LOGGER.info("Leaving start"); }
Example #13
Source File: GroovyShellWrapper.java From artifactory_ssh_proxy with Apache License 2.0 | 5 votes |
@Override public synchronized void start(Environment env) throws IOException { // TODO propagate the Environment itself and support signal sending. executor.execute(new Runnable() { @Override public void run() { runGroovy(); } }); LOGGER.info("Leaving start"); }
Example #14
Source File: AdminCommand.java From gameserver with Apache License 2.0 | 5 votes |
@Override public void start(Environment env) throws IOException { this.out.write(("Welcome to " + InetAddress.getLocalHost().getHostName() + "! \n").getBytes(ENCODING)); this.out.write(("It is " + new Date() + " now. \n>").getBytes(ENCODING)); this.out.flush(); Thread t = new Thread(this); t.start(); }
Example #15
Source File: EchoShell.java From termd with Apache License 2.0 | 5 votes |
@Override public void start(Environment env) throws IOException { environment = env; thread = new Thread(this, "EchoShell"); thread.setDaemon(true); thread.start(); }
Example #16
Source File: TtyCommand.java From termd with Apache License 2.0 | 5 votes |
@Override public void start(final Environment env) throws IOException { String lcctype = env.getEnv().get("LC_CTYPE"); if (lcctype != null) { charset = parseCharset(lcctype); } if (charset == null) { charset = defaultCharset; } env.addSignalListener(signal -> updateSize(env), EnumSet.of(org.apache.sshd.server.Signal.WINCH)); updateSize(env); // Event handling int vintr = getControlChar(env, PtyMode.VINTR, 3); int vsusp = getControlChar(env, PtyMode.VSUSP, 26); int veof = getControlChar(env, PtyMode.VEOF, 4); // eventDecoder = new TtyEventDecoder(vintr, vsusp, veof); decoder = new BinaryDecoder(512, charset, eventDecoder); stdout = new TtyOutputMode(new BinaryEncoder(charset, out)); term = env.getEnv().get("TERM"); conn = new Connection(); // session.setDataReceiver(this); handler.accept(conn); }
Example #17
Source File: DisableShellAccess.java From onedev with MIT License | 5 votes |
@Override public void start(Environment env) throws IOException { err.write(Constants.encode(generateWelcomeMessage())); err.flush(); callback.onExit(0); in.close(); out.close(); err.close(); }
Example #18
Source File: EchoShell.java From termd with Apache License 2.0 | 5 votes |
@Override public void start(Environment env) throws IOException { environment = env; thread = new Thread(this, "EchoShell"); thread.setDaemon(true); thread.start(); }
Example #19
Source File: SingleCommand.java From java-11-examples with Apache License 2.0 | 5 votes |
@Override public void start(Environment env) throws IOException { long sessionId = sshClientSessionCounter.getNewSessionId(); OutputWriter outputWriter = new OutputWriterImpl(stdout, stderr); commandProcessor.onSessionStart(sessionId, outputWriter); LOG.info("start single command processor with sessionId: {}", sessionId); CommandResult commandResult = commandProcessor.processCommand(command); exitCallback.onExit(commandResult.getReturnCode()); }
Example #20
Source File: EchoShellFactory.java From aesh-readline with Apache License 2.0 | 5 votes |
@Override public void start(Environment env) throws IOException { environment = env; thread = new Thread(this, "EchoShell"); thread.setDaemon(true); thread.start(); }
Example #21
Source File: TtyCommand.java From aesh-readline with Apache License 2.0 | 5 votes |
@Override public void start(final Environment env) throws IOException { String lcctype = env.getEnv().get("LC_CTYPE"); if (lcctype != null) { charset = parseCharset(lcctype); } if (charset == null) { charset = defaultCharset; } env.addSignalListener(signal -> updateSize(env), EnumSet.of(org.apache.sshd.server.Signal.WINCH)); updateSize(env); // Event handling int vintr = getControlChar(env, PtyMode.VINTR, 3); int veof = getControlChar(env, PtyMode.VEOF, 4); int vsusp = getControlChar(env, PtyMode.VSUSP, 26); device = new SSHDevice(env.getEnv().get("TERM")); attributes = SSHAttributesBuilder.builder().environment(env).build(); eventDecoder = new EventDecoder(attributes); decoder = new Decoder(512, charset, eventDecoder); stdout = new TtyOutputMode(new Encoder(charset, out)); conn = new SSHConnection(); session.setDataReceiver(this); handler.accept(conn); }
Example #22
Source File: SshClientCommand.java From java-11-examples with Apache License 2.0 | 5 votes |
@Override public void start(Environment env) throws IOException { long sessionId = sshClientSessionCounter.getNewSessionId(); OutputWriterImpl outputWriter = new OutputWriterImpl(stdout, stderr); commandProcessor.onSessionStart(sessionId, outputWriter); LOG.info("start ssh-client command processor with sessionId: {}", sessionId); SshClientSession sshClientSession = new SshClientSessionImpl(sessionId, stdout, exitCallback); SshClientCommandProcessor robotCommandProcessor = new SshClientCommandProcessor(stdin, outputWriter, exitCallback, commandProcessor, keyMap); executorService.submit(robotCommandProcessor); sshClientMessageDispatcherRegistration.onNewSession(sshClientSession); }
Example #23
Source File: SshSessionInstance.java From sshd-shell-spring-boot with Apache License 2.0 | 5 votes |
@Override public void start(ChannelSession channel, Environment env) throws IOException { terminalType = env.getEnv().get(Environment.ENV_TERM); this.channel = channel; sshThread = new Thread(this, "ssh-cli " + channel.getSession().getIoSession().getAttribute(Constants.USER)); sshThread.start(); }
Example #24
Source File: REPLCommand.java From java-11-examples with Apache License 2.0 | 5 votes |
@Override public void start(Environment env) throws IOException { long sessionId = sshClientSessionCounter.getNewSessionId(); OutputWriterImpl outputWriter = new OutputWriterImpl(stdout, stderr); commandProcessor.onSessionStart(sessionId, outputWriter); LOG.info("start REPL command processor with sessionId: {}", sessionId); REPLCommandProcessor replCommandProcessor = new REPLCommandProcessor(prompt, keyMap, commandProcessor, stdin, outputWriter, exitCallback); executorService.submit(replCommandProcessor); }
Example #25
Source File: OpenEJBCommands.java From tomee with Apache License 2.0 | 4 votes |
@Override public void start(Environment env) throws IOException { start(); }
Example #26
Source File: StreamWatchdogTest.java From gerrit-events with MIT License | 4 votes |
@Override public void start(Environment environment) throws IOException { thread = new Thread(this, "WaitLongTimeCommand " + this.command); thread.setDaemon(true); thread.start(); }
Example #27
Source File: AsyncEchoShellFactory.java From termd with Apache License 2.0 | 4 votes |
@Override public void start(Environment env) throws IOException { environment = env; session.setDataReceiver(this); }
Example #28
Source File: NewScpCommand.java From artifactory_ssh_proxy with Apache License 2.0 | 4 votes |
@Override public void start(Environment env) throws IOException { super.start(env); }
Example #29
Source File: EmbeddedSSHServer.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Override public void start(Environment env) throws IOException { this.thread = new Thread(this, "EchoCommand"); this.thread.start(); }
Example #30
Source File: AsyncEchoShellFactory.java From termd with Apache License 2.0 | 4 votes |
public Environment getEnvironment() { return environment; }