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();
}
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();
}
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);
}
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());
}
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();
}
Aggregations