/** * 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; }