/** * 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) { String username = command.getRequiredParameter(0); UserAccount userAccount = getServerConfiguration().getUserAccount(username); if (userAccount != null) { if (!validateUserAccount(username, session)) { return; } // If the UserAccount is configured to not require password for login if (!userAccount.isPasswordRequiredForLogin()) { login(userAccount, session, ReplyCodes.USER_LOGGED_IN_OK, "user.loggedIn"); return; } } session.setAttribute(SessionKeys.USERNAME, username); sendReply(session, ReplyCodes.USER_NEED_PASSWORD_OK, "user.needPassword"); }
protected void handle(Command command, Session session) { String password = command.getRequiredParameter(0); String username = (String) getRequiredSessionAttribute(session, SessionKeys.USERNAME); if (validateUserAccount(username, session)) { UserAccount userAccount = getServerConfiguration().getUserAccount(username); if (userAccount.isValidPassword(password)) { int replyCode = (userAccount.isAccountRequiredForLogin()) ? ReplyCodes.PASS_NEED_ACCOUNT : ReplyCodes.PASS_OK; String replyMessageKey = (userAccount.isAccountRequiredForLogin()) ? "pass.needAccount" : "pass"; login(userAccount, session, replyCode, replyMessageKey); } else { sendReply(session, ReplyCodes.PASS_LOG_IN_FAILED, "pass.loginFailed"); } } }