Coverage Report - org.mockftpserver.fake.command.PassCommandHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
PassCommandHandler
100%
12/12
100%
8/8
5
 
 1  
 /*
 2  
  * Copyright 2008 the original author or authors.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.mockftpserver.fake.command;
 17  
 
 18  
 import org.mockftpserver.core.command.Command;
 19  
 import org.mockftpserver.core.command.ReplyCodes;
 20  
 import org.mockftpserver.core.session.Session;
 21  
 import org.mockftpserver.core.session.SessionKeys;
 22  
 import org.mockftpserver.fake.UserAccount;
 23  
 
 24  
 /**
 25  
  * CommandHandler for the PASS command. Handler logic:
 26  
  * <ol>
 27  
  * <li>If the required password parameter is missing, then reply with 501</li>
 28  
  * <li>If this command was not preceded by a valid USER command, then reply with 503</li>
 29  
  * <li>If the user account configured for the named user does not exist or is not valid, then reply with 530</li>
 30  
  * <li>If the specified password is not correct, then reply with 530</li>
 31  
  * <li>Otherwise, reply with 230</li>
 32  
  * </ol>
 33  
  *
 34  
  * @author Chris Mair
 35  
  * @version $Revision: 182 $ - $Date: 2008-11-30 21:37:49 -0500 (Sun, 30 Nov 2008) $
 36  
  */
 37  83
 public class PassCommandHandler extends AbstractFakeCommandHandler {
 38  
 
 39  
     protected void handle(Command command, Session session) {
 40  50
         String password = command.getRequiredParameter(0);
 41  49
         String username = (String) getRequiredSessionAttribute(session, SessionKeys.USERNAME);
 42  
 
 43  48
         if (validateUserAccount(username, session)) {
 44  45
             UserAccount userAccount = getServerConfiguration().getUserAccount(username);
 45  45
             if (userAccount.isValidPassword(password)) {
 46  44
                 int replyCode = (userAccount.isAccountRequiredForLogin()) ? ReplyCodes.PASS_NEED_ACCOUNT : ReplyCodes.PASS_OK;
 47  44
                 String replyMessageKey = (userAccount.isAccountRequiredForLogin()) ? "pass.needAccount" : "pass";
 48  44
                 login(userAccount, session, replyCode, replyMessageKey);
 49  44
             } else {
 50  1
                 sendReply(session, ReplyCodes.PASS_LOG_IN_FAILED, "pass.loginFailed");
 51  
             }
 52  
         }
 53  48
     }
 54  
 
 55  
 }