本文整理汇总了Java中org.apache.sshd.SshServer类的典型用法代码示例。如果您正苦于以下问题:Java SshServer类的具体用法?Java SshServer怎么用?Java SshServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SshServer类属于org.apache.sshd包,在下文中一共展示了SshServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupSftp
import org.apache.sshd.SshServer; //导入依赖的package包/类
protected void setupSftp(int port, final String username, final String password, File fileSystemFolder)
throws IOException {
sshd = SshServer.setUpDefaultServer();
sshd.setPort(port);
SftpSubsystem.Factory factory = new SftpSubsystem.Factory();
@SuppressWarnings("unchecked")
List<NamedFactory<Command>> factoryList = Arrays.<NamedFactory<Command>> asList(new NamedFactory[] {factory});
this.sshd.setSubsystemFactories(factoryList);
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
public boolean authenticate(String tryUsername, String tryPassword, ServerSession session) {
return (username.equals(tryUsername)) && (password.equals(tryPassword));
}
});
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
sshd.start();
VirtualFileSystemFactory vfSysFactory = new VirtualFileSystemFactory();
vfSysFactory.setDefaultHomeDir(fileSystemFolder.getCanonicalPath());
sshd.setFileSystemFactory(vfSysFactory);
LOGGER.info("Embedded SFTP started on port {}", Integer.valueOf(sshd.getPort()));
}
示例2: ScmSshServer
import org.apache.sshd.SshServer; //导入依赖的package包/类
/**
* Constructor. Meant to be called by Guice.
*
* @param passwordAuthenticator
* authenticator used for password authentication.
* @param publickeyAuthenticator
* authenticator used for public-key authentication.
* @param commandFactory
* factory used to create SSH commands.
* @param configStore
* store the the SSH server configuration.
* @param keyPairProvider
* provider for SSH host keys.
*/
@Inject
public ScmSshServer(PasswordAuthenticator passwordAuthenticator,
PublickeyAuthenticator publickeyAuthenticator,
CommandFactory commandFactory,
ScmSshServerConfigurationStore configStore,
ScmKeyPairProvider keyPairProvider) {
ScmSshServerConfiguration config = configStore.load();
if (config == null) {
config = new ScmSshServerConfiguration();
}
sshServer = SshServer.setUpDefaultServer();
String listenAddress = config.getListenAddress();
if (listenAddress != null && !listenAddress.trim().isEmpty()) {
sshServer.setHost(config.getListenAddress());
}
sshServer.setPort(config.getListenPort());
sshServer.setKeyPairProvider(keyPairProvider);
sshServer.setPasswordAuthenticator(passwordAuthenticator);
sshServer.setPublickeyAuthenticator(publickeyAuthenticator);
sshServer.setCommandFactory(commandFactory);
sshServer.setShellFactory(new NoShellCommandFactory());
}
示例3: startSshServer
import org.apache.sshd.SshServer; //导入依赖的package包/类
@BeforeClass
public static void startSshServer() throws IOException {
sshServer = SshServer.setUpDefaultServer();
ServerSocket serverSocket = new ServerSocket(0);
sshPort = serverSocket.getLocalPort();
serverSocket.close();
sshServer.setPort(sshPort);
sshServer.setPasswordAuthenticator(
new PasswordAuthenticator() {
@Override
public boolean authenticate(
String username,
String password,
ServerSession session) {
return "ssh".equals(username) && "secret".equals(password);
}
});
sshServer.setShellFactory(new SshEchoCommandFactory());
sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
sshServer.start();
}
示例4: setupSftpServer
import org.apache.sshd.SshServer; //导入依赖的package包/类
public void setupSftpServer() throws IOException {
sshd = SshServer.setUpDefaultServer();
sshd.setHost("127.0.0.1");
sshd.setPort(4922);
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("target/hostkey.ser"));
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String username, String password, ServerSession session) {
return "ftpuser".equals(username) && "topsecret".equals(password);
}
});
List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
userAuthFactories.add(new UserAuthPassword.Factory());
sshd.setUserAuthFactories(userAuthFactories);
sshd.setCommandFactory(new ScpCommandFactory());
List<NamedFactory<Command>> namedFactoryList = new ArrayList<NamedFactory<Command>>();
namedFactoryList.add(new SftpSubsystem.Factory());
sshd.setSubsystemFactories(namedFactoryList);
// prepare directory for test files
VirtualFileSystemFactory fileSystemFactory = new VirtualFileSystemFactory(ROOT.getAbsolutePath());
sshd.setFileSystemFactory(fileSystemFactory);
sshd.start();
}
示例5: start
import org.apache.sshd.SshServer; //导入依赖的package包/类
public void start() {
sshd = SshServer.setUpDefaultServer();
sshd.setPort(configuration.port());
sshd.setKeyPairProvider(keyPairProvider);
setupUserHomeDirectories();
List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
userAuthFactories.add(new UserAuthPassword.Factory());
sshd.setPasswordAuthenticator(new SftpUserBackedPasswordAuthenticator(loginToUserDictionary()));
userAuthFactories.add(new UserAuthPublicKey.Factory());
sshd.setPublickeyAuthenticator(new SftpUserBackedPublicKeyAuthenticator(loginToUserDictionary()));
sshd.setUserAuthFactories(userAuthFactories);
sshd.setCommandFactory(new ScpCommandFactory());
List<NamedFactory<Command>> namedFactoryList = new ArrayList<NamedFactory<Command>>();
namedFactoryList.add(new SftpSubsystem.Factory());
sshd.setSubsystemFactories(namedFactoryList);
try {
sshd.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例6: start
import org.apache.sshd.SshServer; //导入依赖的package包/类
@Override
public void start() throws ServiceException {
sshServer = SshServer.setUpDefaultServer();
sshServer.setPort(port);
sshServer.setHost(bind);
final String basePath = SystemInstance.get().getBase().getDirectory().getAbsolutePath();
if (SecurityUtils.isBouncyCastleRegistered()) {
sshServer.setKeyPairProvider(new PEMGeneratorHostKeyProvider(new File(basePath, KEY_NAME + ".pem").getPath()));
} else {
sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File(basePath, KEY_NAME + ".ser").getPath()));
}
final OpenEJBShellFactory sf = new OpenEJBShellFactory(bind, port);
sshServer.setShellFactory(sf);
final JaasPasswordAuthenticator authenticator = new OpenEJBJaasPasswordAuthenticator();
authenticator.setDomain(domain);
sshServer.setPasswordAuthenticator(authenticator);
try {
sshServer.start();
} catch (IOException e) {
// no-op
}
}
示例7: initializeServer
import org.apache.sshd.SshServer; //导入依赖的package包/类
private void initializeServer(String host, int listeningPort) {
log.info("Configuring server...");
sshd = SshServer.setUpDefaultServer();
sshd.setHost(host);
sshd.setPort(listeningPort);
log.info("Host: '" + host + "', listenig port: " + listeningPort);
sshd.setPasswordAuthenticator(new AlwaysTruePasswordAuthenticator());
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(""));
List<NamedFactory<Command>> subsystemFactories = new ArrayList<NamedFactory<Command>>();
subsystemFactories.add(NetconfSubsystem.Factory.createFactory(this, this));
sshd.setSubsystemFactories(subsystemFactories);
log.info("Server configured.");
}
示例8: startSshdServer
import org.apache.sshd.SshServer; //导入依赖的package包/类
private static void startSshdServer() throws IOException {
sshd = SshServer.setUpDefaultServer();
// ask OS to assign a port
sshd.setPort(0);
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
List<NamedFactory<UserAuth>> userAuthFactories =
new ArrayList<NamedFactory<UserAuth>>();
userAuthFactories.add(new UserAuthPassword.Factory());
sshd.setUserAuthFactories(userAuthFactories);
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String username, String password,
ServerSession session) {
if (username.equals("user") && password.equals("password")) {
return true;
}
return false;
}
});
sshd.setSubsystemFactories(
Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
sshd.start();
port = sshd.getPort();
}
示例9: startSerer
import org.apache.sshd.SshServer; //导入依赖的package包/类
@Before
public void startSerer() throws Exception {
server = SshServer.setUpDefaultServer();
server.setPort(PORT_NUMBER);
server.setPasswordAuthenticator((username, password, session) -> true);
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
server.setSubsystemFactories(Collections.singletonList(new SftpSubsystem.Factory()));
final java.nio.file.Path tempDir = Files.createTempDirectory(String.format("%s-", this.getClass().getName()));
final java.nio.file.Path vault = tempDir.resolve("vault");
passphrase = new AlphanumericRandomStringService().random();
cryptoFileSystem = new CryptoFileSystemProvider().newFileSystem(CryptoFileSystemUris.createUri(vault), CryptoFileSystemProperties.cryptoFileSystemProperties().withPassphrase(passphrase).build());
server.setFileSystemFactory(new VirtualFileSystemFactory(cryptoFileSystem.getPathToVault().getParent().toAbsolutePath().toString()));
server.start();
}
示例10: setupSftpServer
import org.apache.sshd.SshServer; //导入依赖的package包/类
/**
* Starts a SFTP server on port 22
*/
private void setupSftpServer() {
SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(9009);
//sshd.setKeyPairProvider(new FileKeyPairProvider(new String[]{"/home/ravi/WORK/SUPPORT/JIRA/SKYTVNZDEV-26/SftpTest/dist/hostkey.ser"}));
ClassLoader classLoader = getClass().getClassLoader();
log.info("Using identity file: " + classLoader.getResource("sftp/id_rsa.pub").getFile());
File file = new File(classLoader.getResource("sftp/id_rsa.pub").getFile());
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(file.getAbsolutePath()));
System.out.println(file.getAbsolutePath());
List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
userAuthFactories.add(new UserAuthPublicKey.Factory());
sshd.setUserAuthFactories(userAuthFactories);
sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {
public boolean authenticate(String username, PublicKey key, ServerSession session) {
if ("sftpuser".equals(username)) {
return true;
}
return false;
}
});
sshd.setCommandFactory(new ScpCommandFactory());
List<NamedFactory<Command>> namedFactoryList = new ArrayList<NamedFactory<Command>>();
namedFactoryList.add(new SftpSubsystem.Factory());
sshd.setSubsystemFactories(namedFactoryList);
try {
sshd.start();
} catch (Exception e) {
e.printStackTrace();
}
}
示例11: setUpServer
import org.apache.sshd.SshServer; //导入依赖的package包/类
protected void setUpServer() throws Exception {
canTest = true;
try {
sshd = SshServer.setUpDefaultServer();
sshd.setPort(getPort());
sshd.setKeyPairProvider(new FileKeyPairProvider(new String[]{"src/test/resources/hostkey.pem"}));
sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
sshd.setCommandFactory(new ScpCommandFactory());
sshd.setPasswordAuthenticator(new MyPasswordAuthenticator());
PublickeyAuthenticator publickeyAuthenticator = new PublickeyAuthenticator() {
// consider all keys as authorized for all users
@Override
public boolean authenticate(String username, PublicKey key, ServerSession session) {
return true;
}
};
sshd.setPublickeyAuthenticator(publickeyAuthenticator);
sshd.start();
} catch (Exception e) {
// ignore if algorithm is not on the OS
NoSuchAlgorithmException nsae = ObjectHelper.getException(NoSuchAlgorithmException.class, e);
if (nsae != null) {
canTest = false;
String name = System.getProperty("os.name");
String message = nsae.getMessage();
log.warn("SunX509 is not avail on this platform [{}] Testing is skipped! Real cause: {}", name, message);
} else {
// some other error then throw it so the test can fail
throw e;
}
}
}
示例12: setUp
import org.apache.sshd.SshServer; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
port = AvailablePortFinder.getNextAvailable(22000);
sshd = SshServer.setUpDefaultServer();
sshd.setPort(port);
sshd.setKeyPairProvider(new FileKeyPairProvider(new String[]{"src/test/resources/hostkey.pem"}));
sshd.setCommandFactory(new TestEchoCommandFactory());
sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
sshd.setPublickeyAuthenticator(new BogusPublickeyAuthenticator());
sshd.start();
super.setUp();
}
示例13: startServer
import org.apache.sshd.SshServer; //导入依赖的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);
}
}
示例14: startShell
import org.apache.sshd.SshServer; //导入依赖的package包/类
public static void startShell(final int port) throws IOException {
final SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(port);
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser"));
sshd.setPasswordAuthenticator(new InAppPasswordAuthenticator());
sshd.setShellFactory(new InAppShellFactory());
sshd.start();
}
示例15: PermissiveSshServer
import org.apache.sshd.SshServer; //导入依赖的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" }));
}