/** * Send a reply for this command on the control connection. * * <p>The reply code is designated by the <code>replyCode</code> property, and the reply text * is retrieved from the <code>replyText</code> ResourceBundle, using the specified messageKey. * * @param session - the Session * @param replyCode - the reply code * @param messageKey - the resource bundle key for the reply text * @throws AssertionError - if session is null * @see MessageFormat */ protected void sendReply(Session session, int replyCode, String messageKey) { sendReply(session, replyCode, messageKey, Collections.EMPTY_LIST); }
/** * Send a reply for this command on the control connection. * * <p>The reply code is designated by the <code>replyCode</code> property, and the reply text * is retrieved from the <code>replyText</code> ResourceBundle, using the reply code as the key. * * @param session - the Session * @param replyCode - the reply code * @throws AssertionError - if session is null * @see MessageFormat */ protected void sendReply(Session session, int replyCode) { sendReply(session, replyCode, Collections.EMPTY_LIST); }
/** * Handle the exception caught during handleCommand() * * @param command - the Command * @param session - the Session * @param exception - the caught exception * @param replyCode - the reply code that should be sent back */ private void handleException(Command command, Session session, Throwable exception, int replyCode) { LOG.warn("Error handling command: " + command + "; " + exception, exception); sendReply(session, replyCode); }
/** * Send a reply for this command on the control connection. * * <p>The reply code is designated by the <code>replyCode</code> property, and the reply text * is retrieved from the <code>replyText</code> ResourceBundle, using the reply code as the key. * * @param session - the Session * @param replyCode - the reply code * @param args - the optional message arguments; defaults to [] * @throws AssertionError - if session is null * @see MessageFormat */ protected void sendReply(Session session, int replyCode, List args) { sendReply(session, replyCode, Integer.toString(replyCode), args); }
/** * Handle the exception caught during handleCommand() * * @param command - the Command * @param session - the Session * @param exception - the caught exception * @param replyCode - the reply code that should be sent back * @param arg - the arg for the reply (message) */ private void handleFileSystemException(Command command, Session session, FileSystemException exception, int replyCode, Object arg) { LOG.warn("Error handling command: " + command + "; " + exception, exception); sendReply(session, replyCode, exception.getMessageKey(), Collections.singletonList(arg)); }
/** * Log in the specified user for the current session. Send back a reply of 230 with a message indicated * by the replyMessageKey and set the UserAccount and current directory (homeDirectory) in the session. * * @param userAccount - the userAccount for the user to be logged in * @param session - the session * @param replyCode - the reply code to send * @param replyMessageKey - the message key for the reply text */ protected void login(UserAccount userAccount, Session session, int replyCode, String replyMessageKey) { sendReply(session, replyCode, replyMessageKey); session.setAttribute(SessionKeys.USER_ACCOUNT, userAccount); session.setAttribute(SessionKeys.CURRENT_DIRECTORY, userAccount.getHomeDirectory()); }
/** * 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; }