Search in sources :

Example 1 with WriteRequest

use of org.apache.ftpserver.usermanager.impl.WriteRequest 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)

Aggregations

File (java.io.File)1 ArrayList (java.util.ArrayList)1 ConnectionConfigFactory (org.apache.ftpserver.ConnectionConfigFactory)1 FtpServerFactory (org.apache.ftpserver.FtpServerFactory)1 NativeFileSystemFactory (org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory)1 Authority (org.apache.ftpserver.ftplet.Authority)1 UserManager (org.apache.ftpserver.ftplet.UserManager)1 ListenerFactory (org.apache.ftpserver.listener.ListenerFactory)1 ClearTextPasswordEncryptor (org.apache.ftpserver.usermanager.ClearTextPasswordEncryptor)1 PropertiesUserManagerFactory (org.apache.ftpserver.usermanager.PropertiesUserManagerFactory)1 BaseUser (org.apache.ftpserver.usermanager.impl.BaseUser)1 WritePermission (org.apache.ftpserver.usermanager.impl.WritePermission)1 WriteRequest (org.apache.ftpserver.usermanager.impl.WriteRequest)1 Before (org.junit.Before)1