diff options
author | chrismair <chrismair@531de8e6-9941-0410-b38b-9a92acbe0330> | 2008-07-17 00:32:04 +0000 |
---|---|---|
committer | chrismair <chrismair@531de8e6-9941-0410-b38b-9a92acbe0330> | 2008-07-17 00:32:04 +0000 |
commit | fa3e4a9d121b1ad40a6d418b925afda82d3567ba (patch) | |
tree | 451cd528394141d5d2a3d1c088a2acfce8d1cf08 /MockFtpServer/src/main/groovy/org/mockftpserver | |
parent | c548d7a6b7cbef8732c090bc1ff5c4f7f29e2575 (diff) | |
download | mockftpserver-fa3e4a9d121b1ad40a6d418b925afda82d3567ba.tar.gz |
Fake ACCT CommandHandler
git-svn-id: svn://svn.code.sf.net/p/mockftpserver/code@83 531de8e6-9941-0410-b38b-9a92acbe0330
Diffstat (limited to 'MockFtpServer/src/main/groovy/org/mockftpserver')
7 files changed, 72 insertions, 20 deletions
diff --git a/MockFtpServer/src/main/groovy/org/mockftpserver/core/session/SessionKeys.groovy b/MockFtpServer/src/main/groovy/org/mockftpserver/core/session/SessionKeys.groovy index 9aec814..9afe8ec 100644 --- a/MockFtpServer/src/main/groovy/org/mockftpserver/core/session/SessionKeys.groovy +++ b/MockFtpServer/src/main/groovy/org/mockftpserver/core/session/SessionKeys.groovy @@ -13,16 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.mockftpserver.core.session +package org.mockftpserver.core.session /** * Constants for names of properties (attributes) stored in the session. */ - class SessionKeys { +class SessionKeys { + + static final USERNAME = "username" + static final USER_ACCOUNT = "userAccount" + static final CURRENT_DIRECTORY = "currentDirectory" + static final RENAME_FROM = "renameFrom" + static final ACCOUNT_NAME = "accountName" - static final USERNAME = "username" - static final USER_ACCOUNT = "userAccount" - static final CURRENT_DIRECTORY = "currentDirectory" - static final RENAME_FROM = "renameFrom" - }
\ No newline at end of file diff --git a/MockFtpServer/src/main/groovy/org/mockftpserver/fake/command/AbstractFakeCommandHandler.groovy b/MockFtpServer/src/main/groovy/org/mockftpserver/fake/command/AbstractFakeCommandHandler.groovy index 6928dde..be2929d 100644 --- a/MockFtpServer/src/main/groovy/org/mockftpserver/fake/command/AbstractFakeCommandHandler.groovy +++ b/MockFtpServer/src/main/groovy/org/mockftpserver/fake/command/AbstractFakeCommandHandler.groovy @@ -47,7 +47,7 @@ abstract class AbstractFakeCommandHandler implements CommandHandler, ServerConfi ServerConfiguration serverConfiguration /** - * Reply code sent back when a FileSystemException is caught by the {@link #handleCommand(Command, Session)} + * Reply code sent back when a FileSystemException is caught by the {@link #handleCommand(Command, Session)} * This defaults to ReplyCodes.EXISTING_FILE_ERROR (550). */ int replyCodeForFileSystemException = ReplyCodes.EXISTING_FILE_ERROR @@ -288,9 +288,10 @@ abstract class AbstractFakeCommandHandler implements CommandHandler, ServerConfi * 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 */ - protected void login(UserAccount userAccount, Session session) { - sendReply(session, ReplyCodes.PASS_OK) + protected void login(UserAccount userAccount, Session session, int replyCode) { + sendReply(session, replyCode) session.setAttribute(SessionKeys.USER_ACCOUNT, userAccount) session.setAttribute(SessionKeys.CURRENT_DIRECTORY, userAccount.homeDirectory) } diff --git a/MockFtpServer/src/main/groovy/org/mockftpserver/fake/command/AcctCommandHandler.groovy b/MockFtpServer/src/main/groovy/org/mockftpserver/fake/command/AcctCommandHandler.groovy new file mode 100644 index 0000000..90d5acc --- /dev/null +++ b/MockFtpServer/src/main/groovy/org/mockftpserver/fake/command/AcctCommandHandler.groovy @@ -0,0 +1,46 @@ +/* + * Copyright 2008 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mockftpserver.fake.command + +import org.mockftpserver.core.command.Command +import org.mockftpserver.core.command.ReplyCodes +import org.mockftpserver.core.session.Session +import org.mockftpserver.core.session.SessionKeys +import org.mockftpserver.fake.command.AbstractFakeCommandHandler + +/** + * CommandHandler for the ACCT command. Handler logic: + * <ol> + * <li>If the required account parameter is missing, then reply with 501</li> + * <li>If this command was not preceded by a valid USER command, then reply with 503</li> + * <li>Store the account name in the session and reply with 230</li> + * </ol> + * + * @version $Revision$ - $Date$ + * + * @author Chris Mair + */ +class AcctCommandHandler extends AbstractFakeCommandHandler { + + protected void handle(Command command, Session session) { + def accountName = command.getRequiredParameter(0) + def username = getRequiredSessionAttribute(session, SessionKeys.USERNAME) + + session.setAttribute(SessionKeys.ACCOUNT_NAME, accountName) + sendReply(session, ReplyCodes.ACCT_OK, 'acct', [username]) + } + +}
\ No newline at end of file diff --git a/MockFtpServer/src/main/groovy/org/mockftpserver/fake/command/PassCommandHandler.groovy b/MockFtpServer/src/main/groovy/org/mockftpserver/fake/command/PassCommandHandler.groovy index a87adc3..020555f 100644 --- a/MockFtpServer/src/main/groovy/org/mockftpserver/fake/command/PassCommandHandler.groovy +++ b/MockFtpServer/src/main/groovy/org/mockftpserver/fake/command/PassCommandHandler.groovy @@ -21,8 +21,6 @@ import org.mockftpserver.core.session.Session import org.mockftpserver.core.session.SessionKeys import org.mockftpserver.fake.command.AbstractFakeCommandHandler - - /** * CommandHandler for the PASS command. Handler logic: * <ol> @@ -30,7 +28,7 @@ import org.mockftpserver.fake.command.AbstractFakeCommandHandler * <li>If this command was not preceded by a valid USER command, then reply with 503</li> * <li>If the user account configured for the named user does not exist or is not valid, then reply with 530</li> * <li>If the specified password is not correct, then reply with 530</li> - * <li>Otherwise, reply with 250</li> + * <li>Otherwise, reply with 230</li> * </ol> * * @version $Revision$ - $Date$ @@ -46,7 +44,8 @@ class PassCommandHandler extends AbstractFakeCommandHandler { if (validateUserAccount(username, session)) { def userAccount = serverConfiguration.getUserAccount(username) if (userAccount.isValidPassword(password)) { - login(userAccount, session) + int replyCode = (userAccount.accountRequiredForLogin) ? ReplyCodes.PASS_NEED_ACCOUNT : ReplyCodes.PASS_OK + login(userAccount, session, replyCode) } else { sendReply(session, ReplyCodes.PASS_LOG_IN_FAILED) diff --git a/MockFtpServer/src/main/groovy/org/mockftpserver/fake/command/UserCommandHandler.groovy b/MockFtpServer/src/main/groovy/org/mockftpserver/fake/command/UserCommandHandler.groovy index 784d9b5..0813891 100644 --- a/MockFtpServer/src/main/groovy/org/mockftpserver/fake/command/UserCommandHandler.groovy +++ b/MockFtpServer/src/main/groovy/org/mockftpserver/fake/command/UserCommandHandler.groovy @@ -21,8 +21,6 @@ import org.mockftpserver.core.session.Session import org.mockftpserver.core.session.SessionKeys import org.mockftpserver.fake.command.AbstractFakeCommandHandler - - /** * CommandHandler for the USER command. Handler logic: * <ol> @@ -49,7 +47,7 @@ class UserCommandHandler extends AbstractFakeCommandHandler { // If the UserAccount is configured to not require password for login if (!userAccount.passwordRequiredForLogin) { - login(userAccount, session) + login(userAccount, session, ReplyCodes.USER_LOGGED_IN_OK) return } } diff --git a/MockFtpServer/src/main/groovy/org/mockftpserver/fake/server/FakeFtpServer.groovy b/MockFtpServer/src/main/groovy/org/mockftpserver/fake/server/FakeFtpServer.groovy index 68e5403..e0c88cc 100644 --- a/MockFtpServer/src/main/groovy/org/mockftpserver/fake/server/FakeFtpServer.groovy +++ b/MockFtpServer/src/main/groovy/org/mockftpserver/fake/server/FakeFtpServer.groovy @@ -41,6 +41,7 @@ class FakeFtpServer extends AbstractFtpServer implements ServerConfiguration { Map helpText = [:] FakeFtpServer() { + setCommandHandler(CommandNames.ACCT, new AcctCommandHandler()) setCommandHandler(CommandNames.ABOR, new AborCommandHandler()) setCommandHandler(CommandNames.ALLO, new AlloCommandHandler()) setCommandHandler(CommandNames.APPE, new AppeCommandHandler()) @@ -87,7 +88,7 @@ class FakeFtpServer extends AbstractFtpServer implements ServerConfiguration { } /** - * @return the {@link UserAccount} configured for this server for the specified user name + * @return the {@link UserAccount} configured for this server for the specified user name */ public UserAccount getUserAccount(String username) { userAccounts[username] diff --git a/MockFtpServer/src/main/groovy/org/mockftpserver/fake/user/UserAccount.groovy b/MockFtpServer/src/main/groovy/org/mockftpserver/fake/user/UserAccount.groovy index 625a9cd..81ffad0 100644 --- a/MockFtpServer/src/main/groovy/org/mockftpserver/fake/user/UserAccount.groovy +++ b/MockFtpServer/src/main/groovy/org/mockftpserver/fake/user/UserAccount.groovy @@ -17,17 +17,22 @@ package org.mockftpserver.fake.user /** * Represents a single user account on the server, including the username, password and home - * directory. + * directory. It also includes several configuration flags, described below. * <p> * The <code>isValidPassword()</code> method returns true if the specified password matches * the password value configured for this user account. This implementation uses the * <code>isEquals()</code> method to compare passwords. * <p> * If you want to provide a custom comparison, for instance using encrypted passwords, you can - * override the <code>comparePassword()</code> method to provide your own custom implementation. + * subclass this class and override the <code>comparePassword()</code> method to provide your own + * custom implementation. * <p> * If the <code>passwordCheckedDuringValidation</code> property is set to false, then the password * value is ignored, and the <code>isValidPassword()</code> method just returns <code<true</code>. + * <p> + * The <code>accountRequiredForLogin</code> property defaults to false. If it is set to true, then + * it is expected that the login for this account will require an ACCOUNT (ACCT) command after the + * PASSWORD (PASS) command is completed. */ class UserAccount { @@ -36,6 +41,7 @@ class UserAccount { String homeDirectory boolean passwordRequiredForLogin = true boolean passwordCheckedDuringValidation = true + boolean accountRequiredForLogin = false /** * Return true if the specified password is the correct, valid password for this user account. |