Java Code Examples for org.apache.ftpserver.usermanager.impl.BaseUser#setName()
The following examples show how to use
org.apache.ftpserver.usermanager.impl.BaseUser#setName() .
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 |
@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: FtpServerManager.java From db with GNU Affero General Public License v3.0 | 6 votes |
public void setUser(final String datastore, final String password) throws OperationException { removeUser(datastore); //is a no-op if the user is not present BaseUser baseUser = new BaseUser(); baseUser.setAuthorities(defaultAuthorities); baseUser.setName(datastore); baseUser.setPassword(password); baseUser.setHomeDirectory(PathUtil.datastoreFtpFolder(datastore)); try { userManager.save(baseUser); } catch (FtpException e) { e.printStackTrace(); throw new OperationException(ErrorCode.INTERNAL_OPERATION_ERROR, "Error occurred in creating FTP user for datastore: " + datastore); } }
Example 3
Source File: StorageServerTools.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
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 4
Source File: PFtpServer.java From PHONK with GNU General Public License v3.0 | 6 votes |
public void addUser(String name, String pass, String directory, boolean canWrite) { BaseUser user = new BaseUser(); user.setName(name); user.setPassword(pass); //String root = ProjectManager.getInstance().getCurrentProject().getStoragePath() + "/" + directory; user.setHomeDirectory(directory); //check if user can write if (canWrite) { List<Authority> auths = new ArrayList<Authority>(); Authority auth = new WritePermission(); auths.add(auth); user.setAuthorities(auths); } try { um.save(user); } catch (FtpException e) { e.printStackTrace(); } }
Example 5
Source File: FtpUserManager.java From google-drive-ftp-adapter with GNU Lesser General Public License v3.0 | 6 votes |
private BaseUser loadUser(String suffix, String defaultUser, String defaultPassword) { final String username = configuration.getProperty("ftp.user" + suffix, defaultUser); final String password = configuration.getProperty("ftp.pass" + suffix, defaultPassword); if ((username == null || username.length() == 0) || (password == null || password.length() == 0)) { return null; } BaseUser user = new BaseUser(); user.setEnabled(true); user.setHomeDirectory(configuration.getProperty("ftp.home" + suffix, "")); user.setMaxIdleTime(300); user.setName(username); user.setPassword(password); List<Authority> authorities = new ArrayList<>(); // configure permissions final String rights = configuration.getProperty("ftp.rights" + suffix, "pwd|cd|dir|put|get|rename|delete|mkdir|rmdir|append"); parseAuthorities(authorities, rights); authorities.add(new WritePermission()); authorities.add(new ConcurrentLoginPermission(10, 5)); user.setAuthorities(authorities); LOG.info("FTP User Manager configured for user '" + user.getName() + "'"); LOG.info("FTP rights '" + rights + "'"); return user; }
Example 6
Source File: FTPServer.java From portable-ftp-server with GNU General Public License v3.0 | 5 votes |
/** * Sets the user. * * @param login the login * @param password the password * @param home the home */ public void setUser(String login,char[] password,String home){ BaseUser user = new BaseUser(); user.setName(login); if(password !=null && password.length>0){ user.setPassword(new String(password)); } user.setHomeDirectory(home); user.setEnabled(true); userManager.setUser(user); }
Example 7
Source File: InMemoryUserManagerTest.java From portable-ftp-server with GNU General Public License v3.0 | 5 votes |
/** * Instantiates a new in memory user manager test. */ public InMemoryUserManagerTest(){ imum = new InMemoryUserManager(); BaseUser user = new BaseUser(); user.setName(USER); user.setPassword(USER); user.setEnabled(true); imum.setUser(user); }
Example 8
Source File: InMemoryUserManagerTest.java From portable-ftp-server with GNU General Public License v3.0 | 5 votes |
/** * Save ignored T est. * * @throws FtpException the ftp exception */ @Test public void saveIgnoredTEst() throws FtpException{ BaseUser user = new BaseUser(); user.setName("admin2"); user.setPassword(USER); user.setEnabled(true); imum.save(user); User u1 = imum.getUserByName("admin2"); assertNotNull(u1); assertEquals(USER,u1.getName()); }
Example 9
Source File: OctopusFTPServer.java From bjoern with GNU General Public License v3.0 | 5 votes |
private BaseUser configureAnonymousUser() { BaseUser user = new BaseUser(); user.setName("anonymous"); List<Authority> auths = new ArrayList<Authority>(); Authority auth = new WritePermission(); auths.add(auth); user.setAuthorities(auths); return user; }
Example 10
Source File: DHuSFtpUserManager.java From DataHubSystem with GNU Affero General Public License v3.0 | 5 votes |
@Override public User getUserByName(final String name) throws FtpException { if (name == null) return null; fr.gael.dhus.database.object.User u = userService.getUserNoCheck (name); if (u==null) return null; BaseUser user = new BaseUser(); user.setName(u.getUsername()); user.setPassword(u.getPassword()); user.setEnabled( u.isEnabled() && u.isAccountNonExpired() && u.isAccountNonLocked() && u.isCredentialsNonExpired() && !u.isDeleted()); user.setHomeDirectory("/"); List<Authority> authorities = new ArrayList<>(); authorities.add(new WritePermission ()); // No special limit int maxLogin = 0; int maxLoginPerIP = 0; authorities.add(new ConcurrentLoginPermission(maxLogin, maxLoginPerIP)); int uploadRate = 0; int downloadRate = 0; authorities.add(new TransferRatePermission(downloadRate, uploadRate)); user.setAuthorities(authorities); user.setMaxIdleTime(1000); return user; }
Example 11
Source File: AntHarnessTest.java From ExpectIt with Apache License 2.0 | 5 votes |
@BeforeClass public static void startFtpServer() throws FtpException { FtpServerFactory serverFactory = new FtpServerFactory(); BaseUser user = new BaseUser(); user.setName("ftp"); user.setPassword("secret"); serverFactory.getUserManager().save(user); ListenerFactory factory = new ListenerFactory(); factory.setPort(0); Listener listener = factory.createListener(); serverFactory.addListener("default", listener); ftpServer = serverFactory.createServer(); ftpServer.start(); ftpPort = listener.getPort(); }
Example 12
Source File: FtpsServer.java From pentaho-kettle with Apache License 2.0 | 5 votes |
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 13
Source File: FtpTestResource.java From camel-quarkus with Apache License 2.0 | 4 votes |
@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); } }
Example 14
Source File: FTPTestSupport.java From activemq-artemis with Apache License 2.0 | 4 votes |
@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 15
Source File: FtpIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@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(); }