/** * Create and register a file with the given name in the home directory of the given user. The created file is * empty. * * @param user * The owner of the file * @param filename * The file name. * @return <code>true</code> if the file was successfully created, <code>false</code> otherwise. * @throws IOException * An error occurs creating the file */ public boolean registerFile(final User user, final String filename) throws IOException { final File userHomeDirectory = new File(user.getHomeDirectory()); return new File(userHomeDirectory, filename).createNewFile(); }
/** * Constructor - set the user object. */ protected HdfsFileSystemView(User user, boolean caseInsensitive) throws FtpException { if (user == null) { throw new IllegalArgumentException("user can not be null"); } if (user.getHomeDirectory() == null) { throw new IllegalArgumentException( "User home directory can not be null"); } this.caseInsensitive = caseInsensitive; // add last '/' if necessary String rootDir = user.getHomeDirectory(); // rootDir = NativeFileObject.normalizeSeparateChar(rootDir); if (!rootDir.endsWith("/")) { rootDir += '/'; } this.rootDir = rootDir; this.user = user; }
/** * Create and register a temporary file in the home directory of the given user. The created file is empty. * * @param user * The owner of the file * @return The name of temporary file created, relative to the user home directory. * @throws IOException * The temporary file can not be created */ public String registerTempFile(final User user) throws IOException { final File userHomeDirectory = new File(user.getHomeDirectory()); final File tempFile = File.createTempFile(user.getName(), ".tmp", userHomeDirectory); return userHomeDirectory.toURI().relativize(tempFile.toURI()).toString(); }
/** * Create and register a temporary file in the home directory of the given user. The created file is empty. The * created file will have the given extension. * * @param user * The owner of the file * @param extension * The extension of the file to create. The '.' delimiting the base name and the extension will be * automatically added. * @return The name of temporary file created, relative to the user home directory. * @throws IOException * The temporary file can not be created */ public String registerTempFile(final User user, final String extension) throws IOException { final File userHomeDirectory = new File(user.getHomeDirectory()); final File tempFile = File.createTempFile(user.getName(), "." + extension, userHomeDirectory); return userHomeDirectory.toURI().relativize(tempFile.toURI()).toString(); }
/** * <p> * Register a new user that will accepted on new connections. * </p> * <p> * If a user home directory is set, it will be created if it does not exist. * </p> * * @param user * The new user with its all data * @throws FtpException */ public void registerUser(final User user) throws FtpException { this.userManager.save(user); // If the user home directory does not exist, we create it final File userHomeDirectory = new File(user.getHomeDirectory()); if (!userHomeDirectory.exists()) { userHomeDirectory.mkdirs(); } }
/** * Constructor - internal do not use directly, use {@link NativeFileSystemFactory} instead */ public NativeFileSystemView(User user, boolean caseInsensitive) throws FtpException { if (user == null) { throw new IllegalArgumentException("user can not be null"); } if (user.getHomeDirectory() == null) { throw new IllegalArgumentException( "User home directory can not be null"); } this.caseInsensitive = caseInsensitive; // add last '/' if necessary String rootDir = user.getHomeDirectory(); rootDir = normalizeSeparateChar(rootDir); rootDir = appendSlash(rootDir); LOG.debug("Native filesystem view created for user \"{}\" with root \"{}\"", user.getName(), rootDir); this.rootDir = rootDir; this.user = user; currDir = "/"; }
private void initWorkingDirectory() { if (currentDir == null) { synchronized (this) { if (currentDir == null) { LOG.info("Initializing ftp view..."); // TODO: what happen if a file is named "root"? this.home = user.getHomeDirectory().equals("") ? new FtpFileWrapper(this, controller, null, model.getFile("root"), "/") : getFileByRelativePath(new FtpFileWrapper(this, controller, null, model.getFile("root"), "/"), user.getHomeDirectory()); this.currentDir = this.home; } } } }
/** * Extracts the working directory of the current session to an absolute file system path * (contrary to what {@link FileSystemView#getWorkingDirectory() returns, which is relative to * the user's home dir}) */ private File workingDir(FtpSession session) throws FtpException { FtpFile workingDirectory = session.getFileSystemView().getWorkingDirectory(); String home = session.getUser().getHomeDirectory(); String absolutePath = workingDirectory.getAbsolutePath().substring(1); File workingDir = new File(new File(home), absolutePath); return workingDir; }
/** * Create the appropriate user file system view. */ public FileSystemView createFileSystemView(User user) throws FtpException { synchronized (user) { // create home if does not exist if (createHome) { String homeDirStr = user.getHomeDirectory(); File homeDir = new File(homeDirStr); if (homeDir.isFile()) { LOG.warn("Not a directory :: " + homeDirStr); throw new FtpException("Not a directory :: " + homeDirStr); } if ((!homeDir.exists()) && (!homeDir.mkdirs())) { LOG.warn("Cannot create user home :: " + homeDirStr); throw new FtpException("Cannot create user home :: " + homeDirStr); } } FileSystemView fsView = new NativeFileSystemView(user, caseInsensitive); return fsView; } }
@Override public FileSystemView createFileSystemView(User user) { final String home = user.getHomeDirectory(); final String owner = user.getName(); final String group = user.getName(); final int streamSize = FTPFile.DEFAULT_SIZE; synchronized (this) { if (mViews.isEmpty()) { return new FTPFileSystemView(home, owner, group, streamSize); } else { final FTPFileSystemView view = mViews.remove(0); view.init(home, owner, group, streamSize); return view; } } }
/** * Copy constructor. */ public BaseUser(User user) { name = user.getName(); password = user.getPassword(); authorities = user.getAuthorities(); maxIdleTimeSec = user.getMaxIdleTime(); homeDir = user.getHomeDirectory(); isEnabled = user.getEnabled(); }
/** * Copy constructor. */ public HdfsUser(User user) { name = user.getName(); password = user.getPassword(); authorities = user.getAuthorities(); maxIdleTimeSec = user.getMaxIdleTime(); homeDir = user.getHomeDirectory(); isEnabled = user.getEnabled(); }
sb.append("userid : ").append(user.getName()).append("\n"); sb.append("userpassword : ********\n"); sb.append("homedirectory : ").append(user.getHomeDirectory()).append( "\n"); sb.append("writepermission : ").append(
varVal = session.getUser().getHomeDirectory();
String home = user.getHomeDirectory(); if (home == null) { home = "/";
static FTPUser from(User user) { final String name = user.getName(); final String password = user.getPassword(); final String homeDirectory = user.getHomeDirectory(); final boolean enable = user.getEnabled(); final int idleSec = user.getMaxIdleTime(); boolean hasWritePermission = false; List<? extends Authority> authorities = user.getAuthorities(); if (authorities != null) { for (Authority authority : authorities) { if (authority instanceof WritePermission) { hasWritePermission = true; break; } } } return new FTPUser(name, password, homeDirectory, false, enable, idleSec, hasWritePermission, 0, 0, 10, 10); }
String home = usr.getHomeDirectory(); if (home == null) { home = "/";
String home = usr.getHomeDirectory(); if (home == null) { home = "/";
String home = usr.getHomeDirectory(); if (home == null) { home = "/";