org.apache.ftpserver.ftplet.User Java Examples

The following examples show how to use org.apache.ftpserver.ftplet.User. 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: FtpProviderUserDirTestCase.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Gets option file system factory for local FTP server.
 */
@Override
protected FileSystemFactory getFtpFileSystem() throws IOException {
    // simulate a non-root home directory by copying test directory to it
    final File testDir = new File(getTestDirectory());
    final File rootDir = new File(testDir, "homeDirIsRoot");
    final File homesDir = new File(rootDir, "home");
    final File initialDir = new File(homesDir, "test");
    FileUtils.deleteDirectory(rootDir);
    // noinspection ResultOfMethodCallIgnored
    rootDir.mkdir();
    FileUtils.copyDirectory(testDir, initialDir, pathname -> !pathname.getPath().contains(rootDir.getName()));

    return new NativeFileSystemFactory() {
        @Override
        public FileSystemView createFileSystemView(final User user) throws FtpException {
            final FileSystemView fsView = super.createFileSystemView(user);
            fsView.changeWorkingDirectory("home/test");
            return fsView;
        }
    };
}
 
Example #2
Source File: FtpUserManager.java    From ProjectX with Apache License 2.0 6 votes vote down vote up
@Override
public User authenticate(Authentication authentication) throws AuthenticationFailedException {
    if (authentication instanceof UsernamePasswordAuthentication) {
        if (mUsers.isEmpty())
            throw new AuthenticationFailedException("Authentication failed");
        final UsernamePasswordAuthentication auth =
                (UsernamePasswordAuthentication) authentication;
        final String username = auth.getUsername();
        final String password = auth.getPassword();
        final Collection<FtpUser> users = mUsers.values();
        for (FtpUser user : users) {
            if (username.equals(user.getName()) &&
                    TextUtils.equals(password, user.getPassword()))
                return user;
        }
        throw new AuthenticationFailedException("Authentication failed");
    } else if (authentication instanceof AnonymousAuthentication) {
        if (isAnonymousLoginEnabled()) {
            return getUserByName(FtpUser.NAME_ANONYMOUS);
        } else {
            throw new AuthenticationFailedException("Authentication failed");
        }
    }
    throw new AuthenticationFailedException("Authentication failed");
}
 
Example #3
Source File: CamelFtpBaseTest.java    From jbpm-work-items with Apache License 2.0 6 votes vote down vote up
public FtpServerBuilder addUser(final String username,
                                final String password,
                                final File home,
                                final boolean write) throws FtpException {
    UserFactory userFactory = new UserFactory();
    userFactory.setHomeDirectory(home.getAbsolutePath());
    userFactory.setName(username);
    userFactory.setPassword(password);

    if (write) {
        List<Authority> authorities = new ArrayList<Authority>();
        Authority writePermission = new WritePermission();
        authorities.add(writePermission);
        userFactory.setAuthorities(authorities);
    }
    User user = userFactory.createUser();
    ftpServerFactory.getUserManager().save(user);

    return this;
}
 
Example #4
Source File: DHuSFtpUserManager.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public String[] getAllUserNames() throws FtpException
{
   DetachedCriteria criteria = DetachedCriteria.forClass (
         fr.gael.dhus.database.object.User.class);
   criteria.add (Restrictions.eq ("deleted", false));

   List<fr.gael.dhus.database.object.User> users = userService.getUsers (
         criteria, 0, 0);
   List<String> names = new LinkedList<> ();
   for (fr.gael.dhus.database.object.User user : users)
   {
      names.add (user.getUsername ());
   }
   return names.toArray(new String[names.size()]);
}
 
Example #5
Source File: DHuSFtpUserManager.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 #6
Source File: FtpUserManager.java    From google-drive-ftp-adapter with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public User authenticate(Authentication authentication) {
    if (UsernamePasswordAuthentication.class.isAssignableFrom(authentication.getClass())) {
        UsernamePasswordAuthentication upAuth = (UsernamePasswordAuthentication) authentication;
        BaseUser user = users.get(upAuth.getUsername());
        if (user != null && user.getPassword().equals(upAuth.getPassword())) {
            return user;
        }
    } else if (AnonymousAuthentication.class.isAssignableFrom(authentication.getClass())) {
        return users.get("anonymous");
    }
    return null;
}
 
Example #7
Source File: FtpFileSystemFactory.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
@Override
public FileSystemView createFileSystemView(User user) throws FtpException {
    if (!(user instanceof FtpUser))
        throw new FtpException("Unsupported user type.");
    final FileSystemView view =
            ((FtpUser) user).getFileSystemViewAdapter().createFileSystemView();
    if (view == null)
        throw new FtpException("Cannot create file system view.");
    return view;
}
 
Example #8
Source File: FtpUserManager.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
@Override
public void save(User user) {
    final String name = user.getName();
    if (name == null)
        throw new UnsupportedOperationException("User name can not be empty!");
    final FtpUser u = user instanceof FtpUser ? (FtpUser) user : new FtpUser(user);
    if (!u.isEditable())
        throw new UnsupportedOperationException("User info can not edit!");
    mUsers.put(name, u);
    mUserNames = null;
    if (mListener != null)
        mListener.onUserSaved(u);
}
 
Example #9
Source File: FtpUserManager.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
@Override
public void delete(String username) {
    if (mUsers.isEmpty())
        return;
    final User deleted = mUsers.remove(username);
    if (deleted == null)
        return;
    mUserNames = null;
    if (mListener != null)
        mListener.onUserDeleted(deleted);
}
 
Example #10
Source File: FtpUserManager.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
@Override
public String[] getAllUserNames() {
    if (mUserNames != null)
        return mUserNames;
    final ArrayList<String> names = new ArrayList<>();
    if (!mUsers.isEmpty()) {
        final Collection<FtpUser> users = mUsers.values();
        for (User user : users) {
            names.add(user.getName());
        }
        Collections.sort(names);
    }
    mUserNames = names.toArray(new String[0]);
    return mUserNames;
}
 
Example #11
Source File: InMemoryUserManagerTest.java    From portable-ftp-server with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Delete not work test.
 *
 * @throws FtpException the ftp exception
 */
@Test
public void deleteNotWorkTest() throws FtpException{
	imum.delete(USER);
	User user = imum.getUserByName(USER);	
	assertNotNull(user);
}
 
Example #12
Source File: InMemoryUserManagerTest.java    From portable-ftp-server with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 #13
Source File: StorageUserManager.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public User authenticate(Authentication authentication) throws AuthenticationFailedException {
	if (authentication instanceof UsernamePasswordAuthentication) {
		UsernamePasswordAuthentication upauth = (UsernamePasswordAuthentication) authentication;
		String name = upauth.getUsername();
		String password = upauth.getPassword();
		if (name == null) {
			throw new AuthenticationFailedException("Authentication failed");
		}
		if (password == null) {
			password = "";
		}
		User user;
		try {
			user = getUserByName(name);
		} catch (FtpException e) {
			throw new AuthenticationFailedException("Authentication failed");
		}
		if (null == user) {
			throw new AuthenticationFailedException("Authentication failed");
		}
		if (StringUtils.equals(user.getPassword(), password)) {
			return user;
		} else {
			throw new AuthenticationFailedException("Authentication failed");
		}
	} else if (authentication instanceof AnonymousAuthentication) {
		throw new AuthenticationFailedException("Authentication failed");
	} else {
		throw new IllegalArgumentException("Authentication not supported by this user manager");
	}
}
 
Example #14
Source File: StorageUserManager.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public boolean doesExist(String arg) throws FtpException {
	User user = this.getUserByName(arg);
	if (null != user) {
		return true;
	}
	return false;
}
 
Example #15
Source File: InMemoryUserManager.java    From portable-ftp-server with GNU General Public License v3.0 5 votes vote down vote up
@Override
public User authenticate(Authentication auth) throws AuthenticationFailedException {
	if(auth!=null && auth instanceof UsernamePasswordAuthentication){
		UsernamePasswordAuthentication userAuth = (UsernamePasswordAuthentication) auth;
		if(user.getName().equals(userAuth.getUsername()) && user.getPassword().equals(userAuth.getPassword())){
			return user;
		}
	}
	return null;
}
 
Example #16
Source File: StorageUserManager.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public User getUserByName(String arg) throws FtpException {
	for (User o : users) {
		if (StringUtils.equals(o.getName(), arg)) {
			return o;
		}
	}
	return null;
}
 
Example #17
Source File: FtpTestSupport.java    From spring-cloud-stream-app-starters with Apache License 2.0 4 votes vote down vote up
@Override
public void save(User user) throws FtpException {
}
 
Example #18
Source File: FtpUserManager.java    From google-drive-ftp-adapter with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void save(User user) {
    // no opt
    LOG.info("save");
}
 
Example #19
Source File: FtpUserManager.java    From google-drive-ftp-adapter with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public User getUserByName(String username) {
    return users.get(username);
}
 
Example #20
Source File: FtpTestSupport.java    From spring-cloud-stream-app-starters with Apache License 2.0 4 votes vote down vote up
@Override
public User getUserByName(String s) throws FtpException {
	return this.testUser;
}
 
Example #21
Source File: InMemoryUserManager.java    From portable-ftp-server with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void save(User login) throws FtpException {}
 
Example #22
Source File: FtpTestSupport.java    From spring-cloud-stream-app-starters with Apache License 2.0 4 votes vote down vote up
@Override
public User authenticate(Authentication authentication) throws AuthenticationFailedException {
	return this.testUser;
}
 
Example #23
Source File: FtpUserManager.java    From ProjectX with Apache License 2.0 4 votes vote down vote up
@Override
public User getUserByName(String username) {
    return mUsers.get(username);
}
 
Example #24
Source File: FtpUser.java    From ProjectX with Apache License 2.0 4 votes vote down vote up
FtpUser(User user) {
    this(user.getName(), user.getPassword(),
            new FileFtpFileSystemViewAdapter(user.getHomeDirectory()));
    mMaxIdleTime = user.getMaxIdleTime();
    mEnabled = user.getEnabled();
}
 
Example #25
Source File: DHuSFtpFileSystemFactory.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public FileSystemView createFileSystemView(User user) throws FtpException
{
   return new DHuSFtpProductViewByCollection (user);
}
 
Example #26
Source File: DHuSFtpUserManager.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void save(User user) throws FtpException
{
   throw new FtpException ("Not allowed to save user by ftp.");
}
 
Example #27
Source File: StorageUserManager.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public StorageUserManager(List<? extends User> users) {
	// super(adminName, passwordEncryptor);
	this.users = users;
}
 
Example #28
Source File: InMemoryUserManager.java    From portable-ftp-server with GNU General Public License v3.0 4 votes vote down vote up
@Override
public User getUserByName(String login) throws FtpException {
	return user;
}
 
Example #29
Source File: StorageUserManager.java    From o2oa with GNU Affero General Public License v3.0 2 votes vote down vote up
@Override
public void save(User arg0) throws FtpException {

}
 
Example #30
Source File: FtpUserManager.java    From ProjectX with Apache License 2.0 2 votes vote down vote up
/**
 * 用户删除
 *
 * @param user 删除的用户
 */
void onUserDeleted(User user);