本文整理汇总了Java中org.apache.sshd.server.SshServer类的典型用法代码示例。如果您正苦于以下问题:Java SshServer类的具体用法?Java SshServer怎么用?Java SshServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SshServer类属于org.apache.sshd.server包,在下文中一共展示了SshServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startServer
import org.apache.sshd.server.SshServer; //导入依赖的package包/类
public void startServer() throws IOException {
SshServer sshd = SshServer.setUpDefaultServer();
port = getPort();
sshd.setPort(port);
sshd.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE);
SimpleGeneratorHostKeyProvider provider = new SimpleGeneratorHostKeyProvider();
sshd.setKeyPairProvider(provider);
SftpSubsystemFactory.Builder builder = new SftpSubsystemFactory.Builder();
SftpSubsystemFactory sftpFactory = builder.build();
sshd.setSubsystemFactories(new ArrayList<NamedFactory<Command>>() {
{
add(sftpFactory);
}
});
sshd.setHost(LOCALHOST);
String msg = String.format("Local SSH Server started on [%s] and listening on port [%d]", sshd.getHost(), sshd
.getPort());
LOGGER.info(msg);
ScpCommandFactory factory = new ScpCommandFactory();
factory.setDelegateCommandFactory(new FakeCommandFactory());
sshd.setCommandFactory(factory);
Runtime.getRuntime().addShutdownHook(new Thread(new Close(sshd)));
sshd.start();
}
示例2: sshServer
import org.apache.sshd.server.SshServer; //导入依赖的package包/类
@Bean
SshServer sshServer() {
SshdShellProperties.Shell props = properties.getShell();
if (Objects.isNull(props.getPassword())) {
props.setPassword(UUID.randomUUID().toString());
log.info("********** User password not set. Use following password to login: {} **********",
props.getPassword());
}
SshServer server = SshServer.setUpDefaultServer();
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File(props.getHostKeyFile())));
server.setPublickeyAuthenticator(Objects.isNull(props.getPublicKeyFile())
? RejectAllPublickeyAuthenticator.INSTANCE
: new SshdAuthorizedKeysAuthenticator(new File(props.getPublicKeyFile())));
server.setHost(props.getHost());
server.setPasswordAuthenticator(passwordAuthenticator());
server.setPort(props.getPort());
server.setShellFactory(() -> sshSessionInstance());
server.setCommandFactory(command -> sshSessionInstance());
return server;
}
示例3: startServer
import org.apache.sshd.server.SshServer; //导入依赖的package包/类
private SshServer startServer(
FileSystem fileSystem
) throws IOException {
SshServer server = SshServer.setUpDefaultServer();
server.setPort(port);
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
server.setPasswordAuthenticator(new StaticPasswordAuthenticator(true));
server.setSubsystemFactories(singletonList(new SftpSubsystemFactory()));
/* When a channel is closed SshServer calls close() on the file system.
* In order to use the file system for multiple channels/sessions we
* have to use a file system wrapper whose close() does nothing.
*/
server.setFileSystemFactory(session -> new DoNotClose(fileSystem));
server.start();
this.server = server;
return server;
}
示例4: testSingleHop
import org.apache.sshd.server.SshServer; //导入依赖的package包/类
@Test(timeout = TEST_TIMEOUT_MILLIS)
public void testSingleHop() throws Exception {
SshServer sshServer = setUpSshServer();
int sshServerPort = sshServer.getPort();
String hostConfigName = "localhost-" + sshServerPort;
appendToSshFile(CONFIG_FILENAME, "Host " + hostConfigName + "\n\tHostName localhost\n\tPort " + sshServerPort + "\n\n");
try (DummyServerSocketThread dummyServerSocketThread = new DummyServerSocketThread(TRANSFER_CHARSET, TEST_TEXT);
SshProxy sshProxy = new SshProxy()) {
int port = sshProxy.connect(hostConfigName, "localhost", dummyServerSocketThread.getPort());
final String receivedText;
try (Socket s = new Socket(SshProxy.LOCALHOST, port);
InputStream is = s.getInputStream()) {
log.info("connected to port: {}", port);
receivedText = readLine(is);
}
assertEquals(TEST_TEXT, receivedText);
} finally {
tryStop(sshServer);
}
}
示例5: testSingleHop_EcDsaServer
import org.apache.sshd.server.SshServer; //导入依赖的package包/类
@Test(timeout = TEST_TIMEOUT_MILLIS)
public void testSingleHop_EcDsaServer() throws Exception {
SshServer sshServer = setUpSshServer(KeyUtils.EC_ALGORITHM);
int sshServerPort = sshServer.getPort();
String hostConfigName = "localhost-" + sshServerPort;
appendToSshFile(CONFIG_FILENAME, "Host " + hostConfigName + "\n\tHostName localhost\n\tPort " + sshServerPort + "\n\n");
try (DummyServerSocketThread dummyServerSocketThread = new DummyServerSocketThread(TRANSFER_CHARSET, TEST_TEXT);
SshProxy sshProxy = new SshProxy()) {
int port = sshProxy.connect(hostConfigName, "localhost", dummyServerSocketThread.getPort());
final String receivedText;
try (Socket s = new Socket(SshProxy.LOCALHOST, port);
InputStream is = s.getInputStream()) {
log.info("connected to port: {}", port);
receivedText = readLine(is);
}
assertEquals(TEST_TEXT, receivedText);
} finally {
tryStop(sshServer);
}
}
示例6: testSingleHopWithLocalPort
import org.apache.sshd.server.SshServer; //导入依赖的package包/类
@Test(timeout = TEST_TIMEOUT_MILLIS)
public void testSingleHopWithLocalPort() throws Exception {
SshServer sshServer = setUpSshServer();
int sshServerPort = sshServer.getPort();
String hostConfigName = "localhost-" + sshServerPort;
appendToSshFile(CONFIG_FILENAME, "Host " + hostConfigName + "\n\tHostName localhost\n\tPort " + sshServerPort + "\n\n");
try (DummyServerSocketThread dummyServerSocketThread = new DummyServerSocketThread(TRANSFER_CHARSET, TEST_TEXT);
SshProxy sshProxy = new SshProxy()) {
int port = sshProxy.connect(hostConfigName, "localhost", dummyServerSocketThread.getPort(), 2345);
final String receivedText;
try (Socket s = new Socket(SshProxy.LOCALHOST, port);
InputStream is = s.getInputStream()) {
log.info("connected to port: {}", port);
receivedText = readLine(is);
}
assertEquals(TEST_TEXT, receivedText);
} finally {
tryStop(sshServer);
}
}
示例7: doTestTwoHops
import org.apache.sshd.server.SshServer; //导入依赖的package包/类
private void doTestTwoHops(String proxyConfiguration) throws Exception {
SshServer firstSshServer = setUpSshServer();
int firstServerPort = firstSshServer.getPort();
SshServer secondSshServer = setUpSshServer();
int secondServerPort = secondSshServer.getPort();
appendToSshFile(CONFIG_FILENAME, "Host firsthop\n\tHostName localhost\n\tPort " + firstServerPort + "\n\n");
appendToSshFile(CONFIG_FILENAME, "Host secondhop\n\tHostName localhost\n\tPort " + secondServerPort + "\n\t" + proxyConfiguration + "\n\n");
try (DummyServerSocketThread dummyServerSocketThread = new DummyServerSocketThread(TRANSFER_CHARSET, TEST_TEXT);
SshProxy sshProxy = new SshProxy()) {
int port = sshProxy.connect("secondhop", "localhost", dummyServerSocketThread.getPort());
final String receivedText;
try (Socket s = new Socket(SshProxy.LOCALHOST, port);
InputStream is = s.getInputStream()) {
log.info("connected to port: {}", port);
receivedText = readLine(is);
}
assertEquals(TEST_TEXT, receivedText);
} finally {
tryStop(firstSshServer);
tryStop(secondSshServer);
}
}
示例8: setUpSshServer
import org.apache.sshd.server.SshServer; //导入依赖的package包/类
private SshServer setUpSshServer(String algorithm) throws IOException {
SshServer sshServer = SshServer.setUpDefaultServer();
sshServer.setPort(0);
AbstractGeneratorHostKeyProvider hostKeyProvider = SecurityUtils.createGeneratorHostKeyProvider(getServerKeyFile(algorithm));
hostKeyProvider.setAlgorithm(algorithm);
if (algorithm.equals(KeyUtils.EC_ALGORITHM)) {
hostKeyProvider.setKeySize(256);
}
sshServer.setKeyPairProvider(hostKeyProvider);
sshServer.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE);
sshServer.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE);
writeFingerprintToKnownHosts(algorithm);
sshServer.start();
int sshServerPort = sshServer.getPort();
assertTrue(sshServerPort > 0);
return sshServer;
}
示例9: start
import org.apache.sshd.server.SshServer; //导入依赖的package包/类
public void start(Consumer<Connection> factory, Consumer<Throwable> doneHandler) {
server = SshServer.setUpDefaultServer();
server.setIoServiceFactoryFactory(new NettyIoServiceFactoryFactory(childGroup));
server.setPort(port);
server.setHost(host);
server.setKeyPairProvider(keyPairProvider);
server.setPasswordAuthenticator(passwordAuthenticator);
if (publicKeyAuthenticator != null) {
server.setPublickeyAuthenticator(publicKeyAuthenticator);
}
server.setShellFactory(() -> new TtyCommand(charset, factory));
try {
server.start();
} catch (Exception e) {
doneHandler.accept(e);
return;
}
doneHandler.accept(null);
}
示例10: close
import org.apache.sshd.server.SshServer; //导入依赖的package包/类
public void close(Handler<AsyncResult<Void>> completionHandler) {
if (!status.compareAndSet(STATUS_STARTED, STATUS_STOPPING)) {
completionHandler.handle(Future.failedFuture("Invalid state:" + status.get()));
return;
}
vertx.executeBlocking(fut-> {
try {
SshServer server = this.nativeServer;
this.nativeServer = null;
server.close();
completionHandler.handle(Future.succeededFuture());
} catch (Exception t) {
completionHandler.handle(Future.failedFuture(t));
} finally {
status.set(STATUS_STOPPED);
}
}, completionHandler);
}
示例11: testCheckTimeout
import org.apache.sshd.server.SshServer; //导入依赖的package包/类
@Test
public void testCheckTimeout() throws Exception {
final GitSSHService sshService = new GitSSHService();
final File certDir = createTempDirectory();
sshService.setup(certDir,
null,
"10000",
"RSA",
mock(ReceivePackFactory.class),
mock(JGitFileSystemProvider.RepositoryResolverImpl.class),
executorService);
sshService.start();
assertTrue(sshService.isRunning());
assertTrue("10000".equals(sshService.getSshServer().getProperties().get(SshServer.IDLE_TIMEOUT)));
sshService.stop();
assertFalse(sshService.isRunning());
}
示例12: before
import org.apache.sshd.server.SshServer; //导入依赖的package包/类
@Override
protected void before() throws Throwable {
sshd = SshServer.setUpDefaultServer();
sshd.setPort(findRandomOpenPortOnAllLocalInterfaces());
sshd.setKeyPairProvider(
new ClassLoadableResourceKeyPairProvider(getClass().getClassLoader(), "server_key"));
sshd.setCommandFactory(new ScpCommandFactory());
sshd.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory()));
sshd.setUserAuthFactories(Collections.singletonList(new UserAuthPublicKeyFactory()));
sshd.setHost("localhost");
sshd.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE);
sshd.setHostBasedAuthenticator(new StaticHostBasedAuthenticator(true));
VirtualFileSystemFactory fileSystemFactory = new VirtualFileSystemFactory();
fileSystemFactory.setDefaultHomeDir(currentFolder.get().toPath());
sshd.setFileSystemFactory(fileSystemFactory);
sshd.start();
}
示例13: start
import org.apache.sshd.server.SshServer; //导入依赖的package包/类
public void start(Consumer<TtyConnection> factory, Consumer<Throwable> doneHandler) {
server = SshServer.setUpDefaultServer();
server.setIoServiceFactoryFactory(new NettyIoServiceFactoryFactory(childGroup));
server.setPort(port);
server.setHost(host);
server.setKeyPairProvider(keyPairProvider);
server.setPasswordAuthenticator(passwordAuthenticator);
server.setShellFactory(() -> new TtyCommand(charset, factory));
try {
server.start();
} catch (Exception e) {
doneHandler.accept(e);
return;
}
doneHandler.accept(null);
}
示例14: start
import org.apache.sshd.server.SshServer; //导入依赖的package包/类
public void start(int port) throws IOException {
if (sshServerMap.get(port) == null) {
SshServer sshServer = SshServer.setUpDefaultServer();
AbstractFileKeyPairProvider fileKeyPairProvider = SecurityUtils.createFileKeyPairProvider();
fileKeyPairProvider.setFiles(Collections.singleton(getHostkey()));
fileKeyPairProvider.setPasswordFinder(resourceKey -> "cloudbreak");
sshServer.setKeyPairProvider(fileKeyPairProvider);
sshServer.setPublickeyAuthenticator((username, key, session) -> true);
setCommandFactory(sshServer);
sshServer.setFileSystemFactory(new MockFileSystemFactory());
sshServer.setPort(port);
sshServer.start();
LOGGER.debug(sshServer.getHost());
sshServerMap.put(port, sshServer);
}
}
示例15: onEnable
import org.apache.sshd.server.SshServer; //导入依赖的package包/类
@Override
public void onEnable() {
instance = this;
sshd = SshServer.setUpDefaultServer();
sshd.setPort(getConfig().getInt("port", 22));
String host = getConfig().getString("listenAddress", "all");
sshd.setHost(host.equals("all") ? null : host);
File hostKey = new File(getDataFolder(), "hostkey");
File authorizedKeys = new File(getDataFolder(), "authorized_keys");
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(hostKey));
sshd.setShellFactory(new ConsoleShellFactory());
sshd.setPasswordAuthenticator(new ConfigPasswordAuthenticator());
sshd.setPublickeyAuthenticator(new PublicKeyAuthenticator(authorizedKeys));
sshd.setCommandFactory(new ConsoleCommandFactory());
try {
sshd.start();
} catch (IOException e) {
getLogger().severe("Failed to start SSH server! " + e.getMessage());
}
}