/** * Validate the UserAccount for the specified username. If valid, return true. If the UserAccount does * not exist or is invalid, log an error message, send back a reply code of 530 with an appropriate * error message, and return false. A UserAccount is considered invalid if the homeDirectory property * is not set or is set to a non-existent directory. * * @param username - the username * @param session - the session; used to send back an error reply if necessary * @return true only if the UserAccount for the named user is valid */ protected boolean validateUserAccount(String username, Session session) { UserAccount userAccount = serverConfiguration.getUserAccount(username); if (userAccount == null || !userAccount.isValid()) { LOG.error("UserAccount missing or not valid for username [" + username + "]: " + userAccount); sendReply(session, ReplyCodes.USER_ACCOUNT_NOT_VALID, "login.userAccountNotValid", list(username)); return false; } String home = userAccount.getHomeDirectory(); if (!getFileSystem().isDirectory(home)) { LOG.error("Home directory configured for username [" + username + "] is not valid: " + home); sendReply(session, ReplyCodes.USER_ACCOUNT_NOT_VALID, "login.homeDirectoryNotValid", list(username, home)); return false; } return true; }
protected void handle(Command command, Session session) { verifyLoggedIn(session); String path = getRealPath(session, command.getRequiredParameter(0)); this.replyCodeForFileSystemException = ReplyCodes.READ_FILE_ERROR; verifyFileSystemCondition(getFileSystem().exists(path), path, "filesystem.doesNotExist"); verifyFileSystemCondition(getFileSystem().isDirectory(path), path, "filesystem.isNotADirectory"); // User must have execute permission to the directory verifyExecutePermission(session, path); session.setAttribute(SessionKeys.CURRENT_DIRECTORY, path); sendReply(session, ReplyCodes.CWD_OK, "cwd", list(path)); }
protected void handle(Command command, Session session) { verifyLoggedIn(session); String path = getRealPath(session, command.getRequiredParameter(0)); this.replyCodeForFileSystemException = ReplyCodes.READ_FILE_ERROR; verifyFileSystemCondition(getFileSystem().exists(path), path, "filesystem.doesNotExist"); verifyFileSystemCondition(getFileSystem().isDirectory(path), path, "filesystem.isNotADirectory"); verifyFileSystemCondition(getFileSystem().listNames(path).size() == 0, path, "filesystem.directoryIsNotEmpty"); // User must have write permission to the parent directory verifyWritePermission(session, getFileSystem().getParent(path)); getFileSystem().delete(path); sendReply(session, ReplyCodes.RMD_OK, "rmd", list(path)); }
protected void handle(Command command, Session session) { verifyLoggedIn(session); String currentDirectory = (String) getRequiredSessionAttribute(session, SessionKeys.CURRENT_DIRECTORY); String path = getFileSystem().getParent(currentDirectory); this.replyCodeForFileSystemException = ReplyCodes.READ_FILE_ERROR; verifyFileSystemCondition(notNullOrEmpty(path), currentDirectory, "filesystem.parentDirectoryDoesNotExist"); verifyFileSystemCondition(getFileSystem().isDirectory(path), path, "filesystem.isNotADirectory"); // User must have execute permission to the parent directory verifyExecutePermission(session, path); session.setAttribute(SessionKeys.CURRENT_DIRECTORY, path); sendReply(session, ReplyCodes.CDUP_OK, "cdup", list(path)); }
verifyFileSystemCondition(!getFileSystem().isDirectory(path), path, "filesystem.isDirectory"); String parentPath = getFileSystem().getParent(path); verifyFileSystemCondition(getFileSystem().isDirectory(parentPath), parentPath, "filesystem.isNotADirectory");
protected void handle(Command command, Session session) { verifyLoggedIn(session); String toPath = getRealPath(session, command.getRequiredParameter(0)); String fromPath = (String) getRequiredSessionAttribute(session, SessionKeys.RENAME_FROM); this.replyCodeForFileSystemException = ReplyCodes.WRITE_FILE_ERROR; verifyFileSystemCondition(!getFileSystem().isDirectory(toPath), toPath, "filesystem.isDirectory"); // User must have write permission to the directory String parentPath = getFileSystem().getParent(toPath); verifyFileSystemCondition(notNullOrEmpty(parentPath), parentPath, "filesystem.doesNotExist"); verifyFileSystemCondition(getFileSystem().exists(parentPath), parentPath, "filesystem.doesNotExist"); verifyWritePermission(session, parentPath); getFileSystem().rename(fromPath, toPath); session.removeAttribute(SessionKeys.RENAME_FROM); sendReply(session, ReplyCodes.RNTO_OK, "rnto", list(fromPath, toPath)); }