1 14 15 package ftpserver; 16 17 import org.quickserver.net.server.*; 18 import org.quickserver.net.AppException; 19 import java.io.*; 20 import java.util.*; 21 22 public class Authenticator extends QuickAuthenticator { 23 24 public boolean askAuthorisation(ClientHandler clientHandler) 25 throws IOException, AppException { 26 27 String username = askStringInput(clientHandler, null); 30 if(username.equalsIgnoreCase("QUIT")) { 31 sendString(clientHandler, "221 Logged out."); 32 throw new AppException("Quit"); 33 } 34 if( username.toUpperCase().startsWith("USER ") == false){ 35 sendString(clientHandler, "503 Bad sequence of command, USER required."); 36 return false; 37 } else { 38 sendString(clientHandler, "331 User name okay, need password."); 39 } 40 41 String password = askStringInput(clientHandler, null); 44 if(password.equalsIgnoreCase("QUIT")) { 45 sendString(clientHandler, "221 Logged out."); 46 throw new AppException("Quit"); 47 } 48 if( password.toUpperCase().startsWith("PASS ") == false ){ 49 sendString(clientHandler, "503 Bad sequence of command, PASS required."); 50 return false; 51 } 52 53 Data data = (Data)clientHandler.getClientData(); 54 data.username = username; 55 64 65 if(username.toLowerCase().equals("user anonymous")) { 66 HashMap appConfig = 68 clientHandler.getServer().getConfig().getApplicationConfiguration(); 69 String temp = null; 70 if(appConfig!=null) 71 temp = (String )appConfig.get("FTP_ROOT"); 72 else 73 temp = System.getProperty("user.home"); 74 data.root = temp; 75 sendString(clientHandler, "230 User logged in, proceed."); 76 return true; 77 } else { 78 sendString(clientHandler, "530 Not logged in."); 79 return false; 80 } 81 } 82 } 83
| Popular Tags
|