Search in sources :

Example 1 with PropertiesUserManagerFactory

use of org.apache.ftpserver.usermanager.PropertiesUserManagerFactory in project pentaho-kettle by pentaho.

the class FtpsServer method createServer.

/*
   * Adopted from https://mina.apache.org/ftpserver-project/embedding_ftpserver.html
   */
private FtpServer createServer(int port, String username, String password, boolean implicitSsl) throws Exception {
    ListenerFactory factory = new ListenerFactory();
    factory.setPort(port);
    if (implicitSsl) {
        SslConfigurationFactory ssl = new SslConfigurationFactory();
        ssl.setKeystoreFile(new File(SERVER_KEYSTORE));
        ssl.setKeystorePassword(PASSWORD);
        // set the SSL configuration for the listener
        factory.setSslConfiguration(ssl.createSslConfiguration());
        factory.setImplicitSsl(true);
    }
    FtpServerFactory serverFactory = new FtpServerFactory();
    // replace the default listener
    serverFactory.addListener("default", factory.createListener());
    PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
    userManagerFactory.setFile(new File(SERVER_USERS));
    UserManager userManager = userManagerFactory.createUserManager();
    if (!userManager.doesExist(username)) {
        BaseUser user = new BaseUser();
        user.setName(username);
        user.setPassword(password);
        user.setEnabled(true);
        user.setHomeDirectory(USER_HOME_DIR);
        user.setAuthorities(Collections.<Authority>singletonList(new WritePermission()));
        userManager.save(user);
    }
    serverFactory.setUserManager(userManager);
    return serverFactory.createServer();
}
Also used : BaseUser(org.apache.ftpserver.usermanager.impl.BaseUser) FtpServerFactory(org.apache.ftpserver.FtpServerFactory) UserManager(org.apache.ftpserver.ftplet.UserManager) PropertiesUserManagerFactory(org.apache.ftpserver.usermanager.PropertiesUserManagerFactory) SslConfigurationFactory(org.apache.ftpserver.ssl.SslConfigurationFactory) File(java.io.File) WritePermission(org.apache.ftpserver.usermanager.impl.WritePermission) ListenerFactory(org.apache.ftpserver.listener.ListenerFactory)

Example 2 with PropertiesUserManagerFactory

use of org.apache.ftpserver.usermanager.PropertiesUserManagerFactory in project wildfly-camel by wildfly-extras.

the class FtpIntegrationTest method startFtpServer.

@Before
public void startFtpServer() throws Exception {
    recursiveDelete(resolvePath(FTP_ROOT_DIR).toFile());
    File usersFile = USERS_FILE.toFile();
    usersFile.createNewFile();
    NativeFileSystemFactory fsf = new NativeFileSystemFactory();
    fsf.setCreateHome(true);
    PropertiesUserManagerFactory pumf = new PropertiesUserManagerFactory();
    pumf.setAdminName("admin");
    pumf.setPasswordEncryptor(new ClearTextPasswordEncryptor());
    pumf.setFile(usersFile);
    UserManager userMgr = pumf.createUserManager();
    BaseUser user = new BaseUser();
    user.setName("admin");
    user.setPassword("admin");
    user.setHomeDirectory(FTP_ROOT_DIR.toString());
    List<Authority> authorities = new ArrayList<>();
    WritePermission writePermission = new WritePermission();
    writePermission.authorize(new WriteRequest());
    authorities.add(writePermission);
    user.setAuthorities(authorities);
    userMgr.save(user);
    ListenerFactory factory1 = new ListenerFactory();
    factory1.setPort(PORT);
    FtpServerFactory serverFactory = new FtpServerFactory();
    serverFactory.setUserManager(userMgr);
    serverFactory.setFileSystem(fsf);
    serverFactory.setConnectionConfig(new ConnectionConfigFactory().createConnectionConfig());
    serverFactory.addListener("default", factory1.createListener());
    FtpServerFactory factory = serverFactory;
    ftpServer = factory.createServer();
    ftpServer.start();
}
Also used : BaseUser(org.apache.ftpserver.usermanager.impl.BaseUser) Authority(org.apache.ftpserver.ftplet.Authority) WriteRequest(org.apache.ftpserver.usermanager.impl.WriteRequest) FtpServerFactory(org.apache.ftpserver.FtpServerFactory) ArrayList(java.util.ArrayList) NativeFileSystemFactory(org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory) ConnectionConfigFactory(org.apache.ftpserver.ConnectionConfigFactory) ClearTextPasswordEncryptor(org.apache.ftpserver.usermanager.ClearTextPasswordEncryptor) WritePermission(org.apache.ftpserver.usermanager.impl.WritePermission) UserManager(org.apache.ftpserver.ftplet.UserManager) PropertiesUserManagerFactory(org.apache.ftpserver.usermanager.PropertiesUserManagerFactory) File(java.io.File) ListenerFactory(org.apache.ftpserver.listener.ListenerFactory) Before(org.junit.Before)

Example 3 with PropertiesUserManagerFactory

use of org.apache.ftpserver.usermanager.PropertiesUserManagerFactory in project alliance by codice.

the class MockNsili method startFtpWebServer.

public void startFtpWebServer(int port) {
    FtpServerFactory ftpServerFactory = new FtpServerFactory();
    ListenerFactory listenerFactory = new ListenerFactory();
    listenerFactory.setPort(port);
    ftpServerFactory.addListener("default", listenerFactory.createListener());
    PropertiesUserManagerFactory propertiesUserManagerFactory = new PropertiesUserManagerFactory();
    UserManager userManager = propertiesUserManagerFactory.createUserManager();
    BaseUser baseUser = new BaseUser();
    baseUser.setName(MOCK_SERVER_USERNAME);
    baseUser.setPassword(MOCK_SERVER_PASSWORD);
    try {
        ftpHomeDirectoryPath = Files.createTempDirectory("home_");
        Runtime.getRuntime().addShutdownHook(new Thread(() -> FileUtils.deleteQuietly(ftpHomeDirectoryPath.toFile())));
        baseUser.setHomeDirectory(ftpHomeDirectoryPath.toString());
    } catch (IOException e) {
        LOGGER.info("Unable to set ftp endpoint to a temporary home directory.");
    }
    try {
        userManager.save(baseUser);
        ftpServerFactory.setUserManager(userManager);
        FtpServer ftpServer = ftpServerFactory.createServer();
        ftpServer.start();
    } catch (FtpException e) {
        LOGGER.error("Unable to start FTP server.", e);
    }
    LOGGER.info("Setting the ftp server's publish address to be ftp://localhost:{}/", port);
}
Also used : BaseUser(org.apache.ftpserver.usermanager.impl.BaseUser) FtpServerFactory(org.apache.ftpserver.FtpServerFactory) UserManager(org.apache.ftpserver.ftplet.UserManager) PropertiesUserManagerFactory(org.apache.ftpserver.usermanager.PropertiesUserManagerFactory) FtpServer(org.apache.ftpserver.FtpServer) FtpException(org.apache.ftpserver.ftplet.FtpException) IOException(java.io.IOException) ListenerFactory(org.apache.ftpserver.listener.ListenerFactory)

Example 4 with PropertiesUserManagerFactory

use of org.apache.ftpserver.usermanager.PropertiesUserManagerFactory in project mule by mulesoft.

the class EmbeddedFtpServer method setupUserManagerFactory.

private void setupUserManagerFactory(FtpServerFactory serverFactory) throws IOException, URISyntaxException {
    PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
    URL usersFile = IOUtils.getResourceAsUrl("users.properties", getClass());
    if (usersFile == null) {
        throw new IOException("users.properties file not found in the classpath");
    }
    userManagerFactory.setFile(new File(usersFile.toURI()));
    serverFactory.setUserManager(userManagerFactory.createUserManager());
}
Also used : PropertiesUserManagerFactory(org.apache.ftpserver.usermanager.PropertiesUserManagerFactory) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL)

Example 5 with PropertiesUserManagerFactory

use of org.apache.ftpserver.usermanager.PropertiesUserManagerFactory in project activemq-artemis by apache.

the class FTPTestSupport method setUp.

@Override
protected void setUp() throws Exception {
    if (ftpHomeDirFile.getParentFile().exists()) {
        IOHelper.deleteFile(ftpHomeDirFile.getParentFile());
    }
    ftpHomeDirFile.mkdirs();
    ftpHomeDirFile.getParentFile().deleteOnExit();
    FtpServerFactory serverFactory = new FtpServerFactory();
    ListenerFactory factory = new ListenerFactory();
    PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
    UserManager userManager = userManagerFactory.createUserManager();
    BaseUser user = new BaseUser();
    user.setName("activemq");
    user.setPassword("activemq");
    user.setHomeDirectory(ftpHomeDirFile.getParent());
    // authorize user
    List<Authority> auths = new ArrayList<>();
    Authority auth = new WritePermission();
    auths.add(auth);
    user.setAuthorities(auths);
    userManager.save(user);
    BaseUser guest = new BaseUser();
    guest.setName("guest");
    guest.setPassword("guest");
    guest.setHomeDirectory(ftpHomeDirFile.getParent());
    userManager.save(guest);
    serverFactory.setUserManager(userManager);
    factory.setPort(0);
    serverFactory.addListener(ftpServerListenerName, factory.createListener());
    server = serverFactory.createServer();
    server.start();
    ftpPort = serverFactory.getListener(ftpServerListenerName).getPort();
    super.setUp();
}
Also used : BaseUser(org.apache.ftpserver.usermanager.impl.BaseUser) Authority(org.apache.ftpserver.ftplet.Authority) FtpServerFactory(org.apache.ftpserver.FtpServerFactory) UserManager(org.apache.ftpserver.ftplet.UserManager) PropertiesUserManagerFactory(org.apache.ftpserver.usermanager.PropertiesUserManagerFactory) ArrayList(java.util.ArrayList) WritePermission(org.apache.ftpserver.usermanager.impl.WritePermission) ListenerFactory(org.apache.ftpserver.listener.ListenerFactory)

Aggregations

PropertiesUserManagerFactory (org.apache.ftpserver.usermanager.PropertiesUserManagerFactory)8 FtpServerFactory (org.apache.ftpserver.FtpServerFactory)6 UserManager (org.apache.ftpserver.ftplet.UserManager)6 ListenerFactory (org.apache.ftpserver.listener.ListenerFactory)6 File (java.io.File)5 BaseUser (org.apache.ftpserver.usermanager.impl.BaseUser)4 NativeFileSystemFactory (org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory)3 ClearTextPasswordEncryptor (org.apache.ftpserver.usermanager.ClearTextPasswordEncryptor)3 WritePermission (org.apache.ftpserver.usermanager.impl.WritePermission)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ConnectionConfigFactory (org.apache.ftpserver.ConnectionConfigFactory)2 Authority (org.apache.ftpserver.ftplet.Authority)2 SslConfigurationFactory (org.apache.ftpserver.ssl.SslConfigurationFactory)2 ChannelSftp (com.jcraft.jsch.ChannelSftp)1 JSch (com.jcraft.jsch.JSch)1 Session (com.jcraft.jsch.Session)1 URL (java.net.URL)1 FtpServer (org.apache.ftpserver.FtpServer)1 FtpException (org.apache.ftpserver.ftplet.FtpException)1