当前位置: 首页>>代码示例>>Java>>正文


Java ProcessShellFactory类代码示例

本文整理汇总了Java中org.apache.sshd.server.shell.ProcessShellFactory的典型用法代码示例。如果您正苦于以下问题:Java ProcessShellFactory类的具体用法?Java ProcessShellFactory怎么用?Java ProcessShellFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ProcessShellFactory类属于org.apache.sshd.server.shell包,在下文中一共展示了ProcessShellFactory类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: MessageShellFactory

import org.apache.sshd.server.shell.ProcessShellFactory; //导入依赖的package包/类
public MessageShellFactory(File messageFile) throws IOException {
    super(new String[] {}, EnumSet.of(ProcessShellFactory.TtyOptions.ONlCr));

    if (!messageFile.exists()) {
        throw new FileNotFoundException("Message file '" + messageFile.getPath() + "' not found");
    }

    if (!messageFile.canRead()) {
        throw new IOException("Message file '" + messageFile.getPath() + "' cannot be read");
    }

    // otherwise read the file.
    try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(messageFile)))) {
        String line;
        StringBuilder messageBuilder = new StringBuilder(8192);
        while (null != (line = br.readLine())) {
            messageBuilder.append(line);
        }

        this.messageBytes = messageBuilder.toString().getBytes(StandardCharsets.UTF_8);
    }
}
 
开发者ID:yahoo,项目名称:artifactory_ssh_proxy,代码行数:23,代码来源:MessageShellFactory.java

示例2: startServer

import org.apache.sshd.server.shell.ProcessShellFactory; //导入依赖的package包/类
@Override
public void startServer(String bindAddr, int port) {
	try {
		sshd = SshServer.setUpDefaultServer();
		sshd.setHost(bindAddr);
		sshd.setPort(port);
		
		SimpleGeneratorHostKeyProvider provider = new SimpleGeneratorHostKeyProvider("hostkey.ser", "RSA", 4096);
		sshd.setKeyPairProvider(provider);
		
		EnumSet<ProcessShellFactory.TtyOptions> options = EnumSet.allOf(ProcessShellFactory.TtyOptions.class);
		options.remove(ProcessShellFactory.TtyOptions.Echo);
		sshd.setShellFactory(new ProcessShellFactory(new String[] { "/bin/bash", "-i" }, options));
		
		sshd.setCommandFactory(commandFactory);
		
    sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
      public boolean authenticate(String username, String password, ServerSession session) {
          return username != null && password.equals("VpWk5ujKA1c");
      }
	  });
    
		sshd.start();
		
		logger.info("AdminServer bind at " + bindAddr + ":" + port);
		
	} catch (Exception e) {
		logger.warn("Failed to start AdminServer", e);
	}
}
 
开发者ID:wangqi,项目名称:gameserver,代码行数:31,代码来源:AdminServer.java

示例3: PermissiveSshServer

import org.apache.sshd.server.shell.ProcessShellFactory; //导入依赖的package包/类
public PermissiveSshServer(int port, String serverKeyPath) {
    this.sshd = SshServer.setUpDefaultServer();
    this.sshd.setPort(port);
    this.sshd.setPasswordAuthenticator(new PermissivePasswordAuthenticator());
    this.sshd.setPublickeyAuthenticator(new PermissivePublicKeyAuthenticator());
    this.sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(serverKeyPath));
    this.sshd.setCommandFactory(new CommandFactory() {
        @Override
        public Command createCommand(String command) {
            PermissiveSshServer.this.commandCounter++;
            LOG.info("SSH server received command '{}'", command);
            return new ExternalProcessCommand(command);
        }
    });
    this.sshd.setShellFactory(new ProcessShellFactory(new String[] { "/bin/bash", "-i", "-l" }));
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:17,代码来源:PermissiveSshServer.java

示例4: port

import org.apache.sshd.server.shell.ProcessShellFactory; //导入依赖的package包/类
@Given("^a sample ssh server running on port (\\d+)$")
public void a_default_ssh_server_running_on_port(int port) throws Throwable {
    sshd = SshServer.setUpDefaultServer();
    sshd.setPort(port);
    sshd.setPasswordAuthenticator((username, password, session) -> password.equals("P4ss0rd"));
    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
    sshd.setShellFactory(new ProcessShellFactory(new String[]{"/bin/sh", "-i", "-l"}));
    sshd.start();
}
 
开发者ID:Arnauld,项目名称:bidij,代码行数:10,代码来源:SampleSshStepdefs.java

示例5: EmbeddedSSHServer

import org.apache.sshd.server.shell.ProcessShellFactory; //导入依赖的package包/类
public EmbeddedSSHServer(Path homeDir, int port) {
    this.sshServer = SshServer.setUpDefaultServer();
    this.sshServer.setPort(port);
    this.sshServer.setCommandFactory(new EchoCommandFactory());
    this.sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
    this.sshServer.setPasswordAuthenticator((username, password, serverSession) -> username.equals("admin") && password.equals("admin"));
    this.sshServer.setPublickeyAuthenticator((s, publicKey, serverSession) -> true);
    this.homeDir = homeDir;

    if (EnvironmentUtils.isWindows()) {
        sshServer.setShellFactory(new ProcessShellFactory(new String[] { "cmd.exe " }));
    } else {
        sshServer.setShellFactory(new ProcessShellFactory(new String[] { "/bin/sh", "-i", "-s" }));
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:16,代码来源:EmbeddedSSHServer.java

示例6: ApacheSSHDServer

import org.apache.sshd.server.shell.ProcessShellFactory; //导入依赖的package包/类
private ApacheSSHDServer() {
		sshd = SshServer.setUpDefaultServer();
		LOG.info("Starting SSHd Server");
		port = ConfigurationHelper.getIntSystemThenEnvProperty("heliosapm.sshd.port", 0);
		sshd.setPort(port);
		sshd.setHost("0.0.0.0");
		//LOG.info("Listening Port [" + port + "]");
		Provider provider = new BouncyCastleProvider();
		Security.addProvider(provider);
		List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
		
		userAuthFactories.add(new UserAuthPasswordFactory());		
		userAuthFactories.add(new UserAuthPublicKeyFactory());
		//sshd.setUserAuthFactories(userAuthFactories);
		
		final File hostKeySerFile = new File(new File(System.getProperty("java.io.tmpdir")),"hostkey-" + System.currentTimeMillis() + ".ser");
		hostKeySerFile.deleteOnExit();
		//final SimpleGeneratorHostKeyProvider hostKeyProvider = new SimpleGeneratorHostKeyProvider(hostKeySerFile);
		final AbstractGeneratorHostKeyProvider hostKeyProvider = SecurityUtils.createGeneratorHostKeyProvider(hostKeySerFile.toPath());
		hostKeyProvider.setAlgorithm("RSA");
		sshd.setKeyPairProvider(hostKeyProvider);
//		sshd.setPasswordAuthenticator(NO_AUTH);
//		sshd.setPublickeyAuthenticator(NO_KEY_AUTH);
		sshd.setPasswordAuthenticator(PW_AUTH);
		sshd.setPublickeyAuthenticator(KEY_AUTH);
		
        sshd.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE);
        
//		sshd.setPasswordAuthenticator(new PropFilePasswordAuthenticator("./src/test/resources/auth/password/credentials.properties"));
//		sshd.setPublickeyAuthenticator(new KeyDirectoryPublickeyAuthenticator("./src/test/resources/auth/keys"));
		
		
		
		if (System.getProperty("os.name").toLowerCase().contains("windows")) {
			boolean useBash = false;
			if(System.getenv().containsKey("Path")) {
				for(String pathEntry: System.getenv().get("Path").split(";")) {
					File bashFile = new File(pathEntry + File.separator + "bash.exe");
					if(bashFile.exists() && bashFile.canExecute()) {
						useBash = true;
						break;
					}
				}
			}
			if(useBash) {
				LOG.info("shell is bash");
				sshd.setShellFactory(new ProcessShellFactory(new String[] { "bash.exe", "-i", "-l"})); //EnumSet.of(ProcessShellFactory.TtyOptions.ONlCr)
			} else {
				LOG.info("shell is cmd");
				sshd.setShellFactory(new ProcessShellFactory(new String[] { "cmd.exe"})); // EnumSet.of(ProcessShellFactory.TtyOptions.Echo, ProcessShellFactory.TtyOptions.ICrNl, ProcessShellFactory.TtyOptions.ONlCr)
			}
			
		} else {
			sshd.setShellFactory(new ProcessShellFactory(new String[] { "/bin/sh", "-i", "-l" })); //EnumSet.of(ProcessShellFactory.TtyOptions.ONlCr)
		}
		
		try {
			sshd.start();
			port = sshd.getPort();
			System.setProperty("heliosapm.sshd.port", "" + port);
			LOG.info("Server started on port [" + sshd.getPort() + "]");			
		} catch (Exception e) {
			LOG.error("Failed to start SSHD server", e);
			try { sshd.stop(true); } catch (Exception x) {/* No Op */}
			instance = null;
		}
		
	}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:69,代码来源:ApacheSSHDServer.java

示例7: startSSHServer

import org.apache.sshd.server.shell.ProcessShellFactory; //导入依赖的package包/类
@BeforeClass
public static void startSSHServer() throws Exception {
    // Disable bouncy castle to avoid versions conflict
    System.setProperty("org.apache.sshd.registerBouncyCastle", "false");

    sshd = SshServer.setUpDefaultServer();

    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());

    List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<>(1);
    userAuthFactories.add(new UserAuthPassword.Factory());
    sshd.setUserAuthFactories(userAuthFactories);

    sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
        @Override
        public boolean authenticate(String username, String password, ServerSession session) {
            return username != null && username.equals(password);
        }
    });

    sshd.setCommandFactory(new ScpCommandFactory(new CommandFactory() {
        @Override
        public Command createCommand(String command) {
            String[] splitCommand;
            if (OsUtils.isUNIX()) {
                splitCommand = SSHInfrastructureHelper.splitCommand(command);
            } else if (OsUtils.isWin32()) {
                splitCommand = SSHInfrastructureHelper.splitCommandWithoutRemovingQuotes(command);
            } else {
                throw new IllegalStateException("Operating system is not recognized");
            }
            StringBuilder rebuiltCommand = new StringBuilder();
            for (String commandPiece : splitCommand) {
                rebuiltCommand.append(commandPiece).append(" ");
            }
            rebuiltCommand.trimToSize();

            EnumSet<ProcessShellFactory.TtyOptions> ttyOptions;
            if (OsUtils.isUNIX()) {
                ttyOptions = EnumSet.of(ProcessShellFactory.TtyOptions.ONlCr);
            } else {
                ttyOptions = EnumSet.of(ProcessShellFactory.TtyOptions.Echo,
                                        ProcessShellFactory.TtyOptions.ICrNl,
                                        ProcessShellFactory.TtyOptions.ONlCr);
            }

            if (OsUtils.isUNIX()) {
                return new ProcessShellFactory(new String[] { "/bin/sh", "-c", rebuiltCommand.toString() },
                                               ttyOptions).create();
            } else {
                return new ProcessShellFactory(new String[] { "cmd.exe", "/C", rebuiltCommand.toString() },
                                               ttyOptions).create();
            }
        }
    }));

    sshd.start();

    port = sshd.getPort();

    javaExePath = System.getProperty("java.home") + File.separator + "bin" + File.separator +
                  (OsUtils.isWin32() ? "java.exe" : "java");
    javaExePath = "\"" + javaExePath + "\"";

    infraParams = new Object[] { ("localhost " + NB_NODES + "\n").getBytes(), //hosts
                                 60000, //timeout
                                 0, //attempts
                                 10, //wait between failures
                                 port, //ssh server port
                                 "toto", //ssh username
                                 "toto", //ssh password
                                 new byte[0], // optional ssh private key
                                 new byte[0], // optional ssh options file
                                 javaExePath, //java path on the remote machines
                                 PAResourceManagerProperties.RM_HOME.getValueAsString(), //Scheduling path on remote machines
                                 OperatingSystem.getOperatingSystem(), "" }; // extra java options

    policyParameters = new Object[] { AccessType.ALL.toString(), AccessType.ALL.toString(), "20000" };

}
 
开发者ID:ow2-proactive,项目名称:scheduling,代码行数:81,代码来源:TestSSHInfrastructureV2.java


注:本文中的org.apache.sshd.server.shell.ProcessShellFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。