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


Java SshServer.setUpDefaultServer方法代码示例

本文整理汇总了Java中org.apache.sshd.SshServer.setUpDefaultServer方法的典型用法代码示例。如果您正苦于以下问题:Java SshServer.setUpDefaultServer方法的具体用法?Java SshServer.setUpDefaultServer怎么用?Java SshServer.setUpDefaultServer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.sshd.SshServer的用法示例。


在下文中一共展示了SshServer.setUpDefaultServer方法的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()));
}
 
开发者ID:northlander,项目名称:activemft,代码行数:25,代码来源:EmbeddedSftp.java

示例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());
}
 
开发者ID:litesolutions,项目名称:scm-ssh-plugin,代码行数:37,代码来源:ScmSshServer.java

示例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();
}
 
开发者ID:Alexey1Gavrilov,项目名称:ExpectIt,代码行数:22,代码来源:AntHarnessTest.java

示例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();
}
 
开发者ID:AludraTest,项目名称:aludratest,代码行数:29,代码来源:SftpFileServiceTest.java

示例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);
    }
}
 
开发者ID:signed,项目名称:in-memory-infrastructure,代码行数:25,代码来源:SftpServer.java

示例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
    }
}
 
开发者ID:apache,项目名称:tomee,代码行数:27,代码来源:SSHServer.java

示例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.");
}
 
开发者ID:dana-i2cat,项目名称:netconf-server,代码行数:18,代码来源:Server.java

示例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();
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:30,代码来源:TestSFTPFileSystem.java

示例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();
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:15,代码来源:SFTPCryptomatorInteroperabilityTest.java

示例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();
    }
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:40,代码来源:ESBJAVA3470.java

示例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;
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:34,代码来源:SftpServerTestSupport.java

示例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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:15,代码来源:SshComponentTestSupport.java

示例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);
	}
}
 
开发者ID:wangqi,项目名称:gameserver,代码行数:31,代码来源:AdminServer.java

示例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();
}
 
开发者ID:KleeGroup,项目名称:vertigo-labs,代码行数:9,代码来源:AppShell.java

示例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" }));
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:17,代码来源:PermissiveSshServer.java


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