Java源码示例:org.apache.ftpserver.usermanager.ClearTextPasswordEncryptor
示例1
public static void initFtpServer() throws Exception {
FtpServerFactory serverFactory = new FtpServerFactory();
// setup user management to read our users.properties and use clear text passwords
URL url = ObjectHelper.loadResourceAsURL("users.properties");
UserManager uman = new PropertiesUserManager(new ClearTextPasswordEncryptor(), url, "admin");
serverFactory.setUserManager(uman);
NativeFileSystemFactory fsf = new NativeFileSystemFactory();
fsf.setCreateHome(true);
serverFactory.setFileSystem(fsf);
ListenerFactory factory = new ListenerFactory();
factory.setPort(port);
serverFactory.addListener("default", factory.createListener());
ftpServer = serverFactory.createServer();
}
示例2
public void initFtpServer() throws Exception {
FtpServerFactory serverFactory = new FtpServerFactory();
// setup user management to read our users.properties and use clear text passwords
URL url = ObjectHelper.loadResourceAsURL("users.properties");
UserManager uman = new PropertiesUserManager(new ClearTextPasswordEncryptor(), url, "admin");
serverFactory.setUserManager(uman);
NativeFileSystemFactory fsf = new NativeFileSystemFactory();
fsf.setCreateHome(true);
serverFactory.setFileSystem(fsf);
ListenerFactory factory = new ListenerFactory();
factory.setPort(port);
serverFactory.addListener("default", factory.createListener());
ftpServer = serverFactory.createServer();
}
示例3
public static void initFtpServer() throws Exception {
FtpServerFactory serverFactory = new FtpServerFactory();
// setup user management to read our users.properties and use clear text passwords
URL url = ObjectHelper.loadResourceAsURL("users.properties");
UserManager uman = new PropertiesUserManager(new ClearTextPasswordEncryptor(), url, "admin");
serverFactory.setUserManager(uman);
NativeFileSystemFactory fsf = new NativeFileSystemFactory();
fsf.setCreateHome(true);
serverFactory.setFileSystem(fsf);
ListenerFactory factory = new ListenerFactory();
factory.setPort(port);
serverFactory.addListener("default", factory.createListener());
ftpServer = serverFactory.createServer();
}
示例4
public static void initFtpServer() throws Exception {
FtpServerFactory serverFactory = new FtpServerFactory();
// setup user management to read our users.properties and use clear text passwords
URL url = ObjectHelper.loadResourceAsURL("users.properties");
UserManager uman = new PropertiesUserManager(new ClearTextPasswordEncryptor(), url, "admin");
serverFactory.setUserManager(uman);
NativeFileSystemFactory fsf = new NativeFileSystemFactory();
fsf.setCreateHome(true);
serverFactory.setFileSystem(fsf);
ListenerFactory factory = new ListenerFactory();
factory.setPort(port);
serverFactory.addListener("default", factory.createListener());
ftpServer = serverFactory.createServer();
}
示例5
public static void initFtpServer() throws Exception {
FtpServerFactory serverFactory = new FtpServerFactory();
// setup user management to read our users.properties and use clear text passwords
URL url = ObjectHelper.loadResourceAsURL("users.properties");
UserManager uman = new PropertiesUserManager(new ClearTextPasswordEncryptor(), url, "admin");
serverFactory.setUserManager(uman);
NativeFileSystemFactory fsf = new NativeFileSystemFactory();
fsf.setCreateHome(true);
serverFactory.setFileSystem(fsf);
ListenerFactory factory = new ListenerFactory();
factory.setPort(port);
serverFactory.addListener("default", factory.createListener());
ftpServer = serverFactory.createServer();
}
示例6
@Override
public Map<String, String> start() {
try {
final int port = AvailablePortFinder.getNextAvailable();
ftpRoot = Files.createTempDirectory("ftp-");
usrFile = Files.createTempFile("ftp-", ".properties");
NativeFileSystemFactory fsf = new NativeFileSystemFactory();
fsf.setCreateHome(true);
PropertiesUserManagerFactory pumf = new PropertiesUserManagerFactory();
pumf.setAdminName("admin");
pumf.setPasswordEncryptor(new ClearTextPasswordEncryptor());
pumf.setFile(usrFile.toFile());
UserManager userMgr = pumf.createUserManager();
BaseUser user = new BaseUser();
user.setName("admin");
user.setPassword("admin");
user.setHomeDirectory(ftpRoot.toString());
List<Authority> authorities = new ArrayList<>();
WritePermission writePermission = new WritePermission();
writePermission.authorize(new WriteRequest());
authorities.add(writePermission);
user.setAuthorities(authorities);
userMgr.save(user);
ListenerFactory factory = new ListenerFactory();
factory.setPort(port);
FtpServerFactory serverFactory = new FtpServerFactory();
serverFactory.setUserManager(userMgr);
serverFactory.setFileSystem(fsf);
serverFactory.setConnectionConfig(new ConnectionConfigFactory().createConnectionConfig());
serverFactory.addListener("default", factory.createListener());
FtpServerFactory ftpServerFactory = serverFactory;
ftpServer = ftpServerFactory.createServer();
ftpServer.start();
return CollectionHelper.mapOf(
"camel.ftp.test-port", Integer.toString(port),
"camel.ftp.test-root-dir", ftpRoot.toString(),
"camel.ftp.test-user-file", usrFile.toString());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例7
@Override
public UserManager createUserManager() {
return new FtpUserManager(configuration, "admin", new ClearTextPasswordEncryptor());
}
示例8
@Before
public void startFtpServer() throws Exception {
FileUtils.deleteDirectory(resolvePath(FTP_ROOT_DIR));
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();
}