Coverage Report - org.mockftpserver.fake.command.UserCommandHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
UserCommandHandler
100%
12/12
100%
6/6
6
 
 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 USER command. Handler logic:
 26  
  * <ol>
 27  
  * <li>If the required pathname parameter is missing, then reply with 501</li>
 28  
  * <li>If the user account configured for the named user is not valid, then reply with 530</li>
 29  
  * <li>If the named user does not need a password for login, then set the UserAccount and
 30  
  * current directory in the session, and reply with 230</li>
 31  
  * <li>Otherwise, set the username in the session and reply with 331</li>
 32  
  * </ol>
 33  
  *
 34  
  * @author Chris Mair
 35  
  * @version $Revision: 198 $ - $Date: 2008-12-10 21:47:32 -0500 (Wed, 10 Dec 2008) $
 36  
  */
 37  80
 public class UserCommandHandler extends AbstractFakeCommandHandler {
 38  
 
 39  
     protected void handle(Command command, Session session) {
 40  47
         String username = command.getRequiredParameter(0);
 41  46
         UserAccount userAccount = getServerConfiguration().getUserAccount(username);
 42  
 
 43  46
         if (userAccount != null) {
 44  45
             if (!validateUserAccount(username, session)) {
 45  2
                 return;
 46  
             }
 47  
 
 48  
             // If the UserAccount is configured to not require password for login
 49  43
             if (!userAccount.isPasswordRequiredForLogin()) {
 50  1
                 login(userAccount, session, ReplyCodes.USER_LOGGED_IN_OK, "user.loggedIn");
 51  1
                 return;
 52  
             }
 53  
         }
 54  43
         session.setAttribute(SessionKeys.USERNAME, username);
 55  43
         sendReply(session, ReplyCodes.USER_NEED_PASSWORD_OK, "user.needPassword");
 56  43
     }
 57  
 
 58  
 }