org.apache.ftpserver.ftplet.UserManager Java Examples

The following examples show how to use org.apache.ftpserver.ftplet.UserManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractFTPTest.java    From cyberduck with GNU General Public License v3.0 7 votes vote down vote up
@Before
public void start() throws Exception {
    final FtpServerFactory serverFactory = new FtpServerFactory();
    final PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
    final UserManager userManager = userManagerFactory.createUserManager();
    BaseUser user = new BaseUser();
    user.setName("test");
    user.setPassword("test");
    user.setHomeDirectory(new TemporaryApplicationResourcesFinder().find().getAbsolute());
    List<Authority> authorities = new ArrayList<Authority>();
    authorities.add(new WritePermission());
    //authorities.add(new ConcurrentLoginPermission(2, Integer.MAX_VALUE));
    user.setAuthorities(authorities);
    userManager.save(user);
    serverFactory.setUserManager(userManager);
    final ListenerFactory factory = new ListenerFactory();
    factory.setPort(PORT_NUMBER);
    serverFactory.addListener("default", factory.createListener());
    server = serverFactory.createServer();
    server.start();
}
 
Example #2
Source File: StorageServerTools.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private static UserManager concreteUserManager(List<Account> list) throws Exception {
	List<BaseUser> users = new ArrayList<>();
	for (Account o : list) {
		BaseUser user = new BaseUser();
		user.setEnabled(true);
		user.setName(o.getUsername());
		String password = o.getPassword();
		if (StringUtils.isEmpty(password)) {
			password = Config.token().getPassword();
		}
		user.setPassword(password);
		File file = new File(Config.base(), "local/repository/storage/" + o.getUsername());
		FileUtils.forceMkdir(file);
		user.setHomeDirectory(file.getAbsolutePath());
		user.setMaxIdleTime(0);
		List<Authority> authorities = new ArrayList<Authority>();
		authorities.add(new WritePermission());
		authorities.add(new ConcurrentLoginPermission(0, 0));
		authorities.add(new TransferRatePermission(0, 0));
		user.setAuthorities(authorities);
		users.add(user);
	}
	StorageUserManager userManager = new StorageUserManager(users);
	return userManager;
}
 
Example #3
Source File: FtpServerBean.java    From camelinaction2 with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #4
Source File: FtpServerBean.java    From camelinaction2 with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #5
Source File: FtpServerBean.java    From camelinaction2 with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #6
Source File: FtpServerBean.java    From camelinaction with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #7
Source File: FtpServer.java    From ProjectX with Apache License 2.0 6 votes vote down vote up
/**
 * 创建FTP服务器
 *
 * @param listeners         服务器监听
 * @param ftplets           服务器程序
 * @param userManager       用户管理器
 * @param fileSystemFactory 文件系统工厂
 * @param commandFactory    命令工厂
 * @param messageResource   消息资源
 * @param connectionConfig  连接配置
 * @return FTP服务器
 */
public static FtpServer createServer(final Map<String, Listener> listeners,
                                     final Map<String, Ftplet> ftplets,
                                     final UserManager userManager,
                                     final FileSystemFactory fileSystemFactory,
                                     final CommandFactory commandFactory,
                                     final MessageResource messageResource,
                                     final ConnectionConfig connectionConfig) {
    final FtpServerFactory factory = new FtpServerFactory();
    factory.setListeners(listeners);
    if (ftplets != null && !ftplets.isEmpty())
        factory.setFtplets(ftplets);
    factory.setUserManager(userManager);
    factory.setFileSystem(fileSystemFactory);
    if (commandFactory != null)
        factory.setCommandFactory(commandFactory);
    if (messageResource != null)
        factory.setMessageResource(messageResource);
    factory.setConnectionConfig(connectionConfig);
    return new FtpServer(factory.createServer());
}
 
Example #8
Source File: FtpServerBean.java    From camelinaction with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #9
Source File: TestFTPFileSystem.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
private void startServer() {
  try {
    DefaultFtpServerContext context = new DefaultFtpServerContext(false);
    MinaListener listener = new MinaListener();
    // Set port to 0 for OS to give a free port
    listener.setPort(0);
    context.setListener("default", listener);

    // Create a test user.
    UserManager userManager = context.getUserManager();
    BaseUser adminUser = new BaseUser();
    adminUser.setName("admin");
    adminUser.setPassword("admin");
    adminUser.setEnabled(true);
    adminUser.setAuthorities(new Authority[] { new WritePermission() });

    Path adminUserHome = new Path(ftpServerRoot, "user/admin");
    adminUser.setHomeDirectory(adminUserHome.toUri().getPath());
    adminUser.setMaxIdleTime(0);
    userManager.save(adminUser);

    // Initialize the server and start.
    server = new FtpServer(context);
    server.start();

  } catch (Exception e) {
    throw new RuntimeException("FTP server start-up failed", e);
  }
}
 
Example #10
Source File: FtpsServer.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #11
Source File: FtpProviderTestCase.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and starts an embedded Apache FTP Server (MINA).
 *
 * @param rootDirectory the local FTP server rootDirectory
 * @param fileSystemFactory optional local FTP server FileSystemFactory
 * @throws FtpException
 * @throws IOException
 */
static void setUpClass(final String rootDirectory, final FileSystemFactory fileSystemFactory)
        throws FtpException, IOException {
    if (Server != null) {
        return;
    }
    init();
    final FtpServerFactory serverFactory = new FtpServerFactory();
    final PropertiesUserManagerFactory propertiesUserManagerFactory = new PropertiesUserManagerFactory();
    final URL userPropsResource = ClassLoader.getSystemClassLoader().getResource(USER_PROPS_RES);
    Assert.assertNotNull(USER_PROPS_RES, userPropsResource);
    propertiesUserManagerFactory.setUrl(userPropsResource);
    final UserManager userManager = propertiesUserManagerFactory.createUserManager();
    final BaseUser user = (BaseUser) userManager.getUserByName("test");
    // Pickup the home dir value at runtime even though we have it set in the user prop file
    // The user prop file requires the "homedirectory" to be set
    user.setHomeDirectory(rootDirectory);
    userManager.save(user);
    serverFactory.setUserManager(userManager);
    if (fileSystemFactory != null) {
        serverFactory.setFileSystem(fileSystemFactory);
    }
    final ListenerFactory factory = new ListenerFactory();
    // set the port of the listener
    factory.setPort(SocketPort);

    // replace the default listener
    serverFactory.addListener("default", factory.createListener());

    // start the server
    Server = serverFactory.createServer();
    Server.start();
}
 
Example #12
Source File: TestFTPFileSystem.java    From RDFS with Apache License 2.0 5 votes vote down vote up
private void startServer() {
  try {
    DefaultFtpServerContext context = new DefaultFtpServerContext(false);
    MinaListener listener = new MinaListener();
    // Set port to 0 for OS to give a free port
    listener.setPort(0);
    context.setListener("default", listener);

    // Create a test user.
    UserManager userManager = context.getUserManager();
    BaseUser adminUser = new BaseUser();
    adminUser.setName("admin");
    adminUser.setPassword("admin");
    adminUser.setEnabled(true);
    adminUser.setAuthorities(new Authority[] { new WritePermission() });

    Path adminUserHome = new Path(ftpServerRoot, "user/admin");
    adminUser.setHomeDirectory(adminUserHome.toUri().getPath());
    adminUser.setMaxIdleTime(0);
    userManager.save(adminUser);

    // Initialize the server and start.
    server = new FtpServer(context);
    server.start();

  } catch (Exception e) {
    throw new RuntimeException("FTP server start-up failed", e);
  }
}
 
Example #13
Source File: FtpsProvider.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and starts an embedded Apache FTPS Server (MINA).
 *
 * @throws FtpException
 * @throws IOException
 */
static void startFtpsServer() throws FtpException, IOException {
    if (Server != null) {
        return;
    }
    init();
    final FtpServerFactory serverFactory = new FtpServerFactory();
    final PropertiesUserManagerFactory propertiesUserManagerFactory = new PropertiesUserManagerFactory();
    final URL userPropsResource = ClassLoader.getSystemClassLoader().getResource(USER_PROPS_RES);
    Assert.assertNotNull(USER_PROPS_RES, userPropsResource);
    propertiesUserManagerFactory.setUrl(userPropsResource);
    final UserManager userManager = propertiesUserManagerFactory.createUserManager();
    serverFactory.setUserManager(userManager);
    final ListenerFactory factory = new ListenerFactory();
    // set the port of the listener
    factory.setPort(SocketPort);

    // define SSL configuration
    final URL serverJksResource = ClassLoader.getSystemClassLoader().getResource(SERVER_JKS_RES);
    Assert.assertNotNull(SERVER_JKS_RES, serverJksResource);
    final SslConfigurationFactory ssl = new SslConfigurationFactory();
    final File keyStoreFile = FileUtils.toFile(serverJksResource);
    Assert.assertTrue(keyStoreFile.toString(), keyStoreFile.exists());
    ssl.setKeystoreFile(keyStoreFile);
    ssl.setKeystorePassword(Constants.KEYSTORE_PASSWORD);
    factory.setSslConfiguration(ssl.createSslConfiguration());

    serverFactory.addListener("default", factory.createListener());

    // start the server
    Server = serverFactory.createServer();
    Server.start();
}
 
Example #14
Source File: StorageServerTools.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private static UserManager calculateUserManager(List<Account> list) throws Exception {
	// if (ListTools.isNotEmpty(list)) {
	// return concreteUserManager(list);
	// } else {
	// return concreteDefaultUserManager();
	// }
	return concreteUserManager(list);
}
 
Example #15
Source File: FTPTestSupport.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example #16
Source File: FtpUserManagerFactory.java    From google-drive-ftp-adapter with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public UserManager createUserManager() {
    return new FtpUserManager(configuration, "admin", new ClearTextPasswordEncryptor());
}
 
Example #17
Source File: FtpServerConverter.java    From citrus-admin with Apache License 2.0 4 votes vote down vote up
@Override
protected Map<String, Class<?>> getOptionTypeMappings() {
    Map<String, Class<?>> mappings = super.getOptionTypeMappings();
    mappings.put("userManager", UserManager.class);
    return mappings;
}
 
Example #18
Source File: AbstractFtpsProviderTestCase.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
/**
 * Creates and starts an embedded Apache FTP Server (MINA).
 *
 * @param implicit FTPS connection mode
 * @throws FtpException
 * @throws IOException
 */
static void setUpClass(final boolean implicit) throws FtpException, IOException {
    if (Server != null) {
        return;
    }
    init();
    final FtpServerFactory serverFactory = new FtpServerFactory();
    final PropertiesUserManagerFactory propertiesUserManagerFactory = new PropertiesUserManagerFactory();
    final URL userPropsResource = ClassLoader.getSystemClassLoader().getResource(USER_PROPS_RES);
    Assert.assertNotNull(USER_PROPS_RES, userPropsResource);
    propertiesUserManagerFactory.setUrl(userPropsResource);
    final UserManager userManager = propertiesUserManagerFactory.createUserManager();
    final BaseUser user = (BaseUser) userManager.getUserByName("test");
    // Pickup the home dir value at runtime even though we have it set in the user prop file
    // The user prop file requires the "homedirectory" to be set
    user.setHomeDirectory(getTestDirectory());
    serverFactory.setUserManager(userManager);
    final ListenerFactory factory = new ListenerFactory();
    // set the port of the listener
    factory.setPort(SocketPort);

    // define SSL configuration
    final URL serverJksResource = ClassLoader.getSystemClassLoader().getResource(SERVER_JKS_RES);
    Assert.assertNotNull(SERVER_JKS_RES, serverJksResource);
    final SslConfigurationFactory ssl = new SslConfigurationFactory();
    final File keyStoreFile = FileUtils.toFile(serverJksResource);
    Assert.assertTrue(keyStoreFile.toString(), keyStoreFile.exists());
    ssl.setKeystoreFile(keyStoreFile);
    ssl.setKeystorePassword("password");

    // set the SSL configuration for the listener
    factory.setSslConfiguration(ssl.createSslConfiguration());
    factory.setImplicitSsl(implicit);

    // replace the default listener
    serverFactory.addListener("default", factory.createListener());

    // start the server
    Server = serverFactory.createServer();
    Server.start();
}
 
Example #19
Source File: FtpIntegrationTest.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example #20
Source File: FtpTestResource.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
@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);
    }
}