/** * Return the full, absolute path for the specified abstract pathname. * If path is null, return the current directory (stored in the session). If * path represents an absolute path, then return path as is. Otherwise, path * is relative, so assemble the full path from the current directory * and the specified relative path. * * @param session - the Session * @param path - the abstract pathname; may be null * @return the resulting full, absolute path */ protected String getRealPath(Session session, String path) { String currentDirectory = (String) session.getAttribute(SessionKeys.CURRENT_DIRECTORY); if (path == null) { return currentDirectory; } if (getFileSystem().isAbsolute(path)) { return path; } return getFileSystem().path(currentDirectory, path); }
/** * Verify that the current user has execute permission to the specified path * * @param session - the Session * @param path - the file system path * @throws FileSystemException - if the condition is not true */ protected void verifyExecutePermission(Session session, String path) { UserAccount userAccount = getUserAccount(session); FileSystemEntry entry = getFileSystem().getEntry(path); verifyFileSystemCondition(userAccount.canExecute(entry), path, "filesystem.cannotExecute"); }
/** * Verify that the current user has write permission to the specified path * * @param session - the Session * @param path - the file system path * @throws FileSystemException - if the condition is not true */ protected void verifyWritePermission(Session session, String path) { UserAccount userAccount = getUserAccount(session); FileSystemEntry entry = getFileSystem().getEntry(path); verifyFileSystemCondition(userAccount.canWrite(entry), path, "filesystem.cannotWrite"); }
/** * Verify that the current user has read permission to the specified path * * @param session - the Session * @param path - the file system path * @throws FileSystemException - if the condition is not true */ protected void verifyReadPermission(Session session, String path) { UserAccount userAccount = getUserAccount(session); FileSystemEntry entry = getFileSystem().getEntry(path); verifyFileSystemCondition(userAccount.canRead(entry), path, "filesystem.cannotRead"); }
/** * 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; }