Search in sources :

Example 1 with SslConfigurationFactory

use of org.apache.ftpserver.ssl.SslConfigurationFactory in project quickstarts by jboss-switchyard.

the class CamelFtpBindingTest method startUp.

@BeforeClass
public static void startUp() throws Exception {
    FtpServerFactory serverFactory = new FtpServerFactory();
    ListenerFactory listenerFactory = new ListenerFactory();
    listenerFactory.setPort(2222);
    serverFactory.addListener("default", listenerFactory.createListener());
    ListenerFactory sslListenerFactory = new ListenerFactory();
    sslListenerFactory.setPort(2221);
    SslConfigurationFactory ssl = new SslConfigurationFactory();
    ssl.setKeystoreFile(new File("src/test/resources/ftpserver.jks"));
    ssl.setKeystorePassword("password");
    sslListenerFactory.setSslConfiguration(ssl.createSslConfiguration());
    // Setting it to true will not read the file
    sslListenerFactory.setImplicitSsl(false);
    serverFactory.addListener("ftps", sslListenerFactory.createListener());
    PropertiesUserManagerFactory managerFactory = new PropertiesUserManagerFactory();
    managerFactory.setPasswordEncryptor(new ClearTextPasswordEncryptor());
    managerFactory.setFile(new File("src/test/resources/users.properties"));
    UserManager createUserManager = managerFactory.createUserManager();
    serverFactory.setUserManager(createUserManager);
    NativeFileSystemFactory fileSystemFactory = new NativeFileSystemFactory();
    fileSystemFactory.setCreateHome(true);
    serverFactory.setFileSystem(fileSystemFactory);
    File file = new File("target/ftp/ftps");
    file.mkdirs();
    file = new File("target/ftp/sftp");
    file.mkdirs();
    ftpServer = serverFactory.createServer();
    ftpServer.start();
    SshServer sshd = SshServer.setUpDefaultServer();
    sshd.setPort(2220);
    sshd.setKeyPairProvider(createTestKeyPairProvider("src/test/resources/hostkey.pem"));
    sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
    sshd.setCommandFactory(new ScpCommandFactory());
    sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
    sshd.start();
    JSch sch = new JSch();
    Session session = sch.getSession("camel", "localhost", 2220);
    session.setUserInfo(new SimpleUserInfo("isMyFriend"));
    session.connect();
    ChannelSftp c = (ChannelSftp) session.openChannel("sftp");
    c.connect();
    System.out.println("Home: " + c.getHome());
    c.chmod(777, ".");
    c.chmod(777, "target");
    c.chmod(777, "target/ftp");
    c.chmod(777, "target/ftp/sftp");
    c.disconnect();
    session.disconnect();
}
Also used : FtpServerFactory(org.apache.ftpserver.FtpServerFactory) NativeFileSystemFactory(org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory) NativeFileSystemFactory(org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory) ScpCommandFactory(org.apache.sshd.server.command.ScpCommandFactory) PropertiesUserManagerFactory(org.apache.ftpserver.usermanager.PropertiesUserManagerFactory) ListenerFactory(org.apache.ftpserver.listener.ListenerFactory) SslConfigurationFactory(org.apache.ftpserver.ssl.SslConfigurationFactory) FtpServerFactory(org.apache.ftpserver.FtpServerFactory) NamedFactory(org.apache.sshd.common.NamedFactory) JSch(com.jcraft.jsch.JSch) ClearTextPasswordEncryptor(org.apache.ftpserver.usermanager.ClearTextPasswordEncryptor) SshServer(org.apache.sshd.SshServer) ScpCommandFactory(org.apache.sshd.server.command.ScpCommandFactory) ChannelSftp(com.jcraft.jsch.ChannelSftp) Command(org.apache.sshd.server.Command) UserManager(org.apache.ftpserver.ftplet.UserManager) PropertiesUserManagerFactory(org.apache.ftpserver.usermanager.PropertiesUserManagerFactory) SslConfigurationFactory(org.apache.ftpserver.ssl.SslConfigurationFactory) File(java.io.File) ListenerFactory(org.apache.ftpserver.listener.ListenerFactory) ServerSession(org.apache.sshd.server.session.ServerSession) Session(com.jcraft.jsch.Session) BeforeClass(org.junit.BeforeClass)

Example 2 with SslConfigurationFactory

use of org.apache.ftpserver.ssl.SslConfigurationFactory in project camel by apache.

the class FtpsServerTestSupport method createSslConfiguration.

protected SslConfigurationFactory createSslConfiguration() {
    // comment in, if you have trouble with SSL
    // System.setProperty("javax.net.debug", "all");
    SslConfigurationFactory sslConfigFactory = new SslConfigurationFactory();
    sslConfigFactory.setSslProtocol(getAuthValue());
    sslConfigFactory.setKeystoreFile(FTPSERVER_KEYSTORE);
    sslConfigFactory.setKeystoreType("JKS");
    sslConfigFactory.setKeystoreAlgorithm("SunX509");
    sslConfigFactory.setKeystorePassword(FTPSERVER_KEYSTORE_PASSWORD);
    sslConfigFactory.setKeyPassword(FTPSERVER_KEYSTORE_PASSWORD);
    sslConfigFactory.setClientAuthentication(getClientAuth());
    if (Boolean.valueOf(getClientAuth())) {
        sslConfigFactory.setTruststoreFile(FTPSERVER_KEYSTORE);
        sslConfigFactory.setTruststoreType("JKS");
        sslConfigFactory.setTruststoreAlgorithm("SunX509");
        sslConfigFactory.setTruststorePassword(FTPSERVER_KEYSTORE_PASSWORD);
    }
    return sslConfigFactory;
}
Also used : SslConfigurationFactory(org.apache.ftpserver.ssl.SslConfigurationFactory)

Example 3 with SslConfigurationFactory

use of org.apache.ftpserver.ssl.SslConfigurationFactory in project ddf by codice.

the class FtpServerStarterTest method setup.

@Before
public void setup() {
    Ftplet ftplet = mock(FtpRequestHandler.class);
    ftpServerFactory = mock(FtpServerFactory.class);
    listenerFactory = mock(ListenerFactory.class);
    UserManager userManager = mock(UserManagerImpl.class);
    sslConfigurationFactory = mock(SslConfigurationFactory.class);
    defaultListener = mock(Listener.class);
    server = mock(DefaultFtpServer.class, RETURNS_DEEP_STUBS);
    sessions = new HashSet<>();
    ftpServerStarter = new FtpServerStarter(ftplet, ftpServerFactory, listenerFactory, userManager, sslConfigurationFactory);
}
Also used : DefaultFtpServer(org.apache.ftpserver.impl.DefaultFtpServer) Ftplet(org.apache.ftpserver.ftplet.Ftplet) Listener(org.apache.ftpserver.listener.Listener) FtpServerFactory(org.apache.ftpserver.FtpServerFactory) UserManager(org.apache.ftpserver.ftplet.UserManager) SslConfigurationFactory(org.apache.ftpserver.ssl.SslConfigurationFactory) ListenerFactory(org.apache.ftpserver.listener.ListenerFactory) Before(org.junit.Before)

Aggregations

SslConfigurationFactory (org.apache.ftpserver.ssl.SslConfigurationFactory)3 FtpServerFactory (org.apache.ftpserver.FtpServerFactory)2 UserManager (org.apache.ftpserver.ftplet.UserManager)2 ListenerFactory (org.apache.ftpserver.listener.ListenerFactory)2 ChannelSftp (com.jcraft.jsch.ChannelSftp)1 JSch (com.jcraft.jsch.JSch)1 Session (com.jcraft.jsch.Session)1 File (java.io.File)1 NativeFileSystemFactory (org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory)1 Ftplet (org.apache.ftpserver.ftplet.Ftplet)1 DefaultFtpServer (org.apache.ftpserver.impl.DefaultFtpServer)1 Listener (org.apache.ftpserver.listener.Listener)1 ClearTextPasswordEncryptor (org.apache.ftpserver.usermanager.ClearTextPasswordEncryptor)1 PropertiesUserManagerFactory (org.apache.ftpserver.usermanager.PropertiesUserManagerFactory)1 SshServer (org.apache.sshd.SshServer)1 NamedFactory (org.apache.sshd.common.NamedFactory)1 Command (org.apache.sshd.server.Command)1 ScpCommandFactory (org.apache.sshd.server.command.ScpCommandFactory)1 ServerSession (org.apache.sshd.server.session.ServerSession)1 Before (org.junit.Before)1