KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ftpserver > Authenticator


1 /*
2  * This file is part of the QuickServer library
3  * Copyright (C) 2003-2005 QuickServer.org
4  *
5  * Use, modification, copying and distribution of this software is subject to
6  * the terms and conditions of the GNU Lesser General Public License.
7  * You should have received a copy of the GNU LGP License along with this
8  * library; if not, you can download a copy from <http://www.quickserver.org/>.
9  *
10  * For questions, suggestions, bug-reports, enhancement-requests etc.
11  * visit http://www.quickserver.org
12  *
13  */

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 JavaDoc username = askStringInput(clientHandler, null); //USER <USERNAME>
28
//no need to check for null : done by QuickAuthenticator
29

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 JavaDoc password = askStringInput(clientHandler, null);//PASS <PASSWORD>
42
//no need to check for null : done by QuickAuthenticator
43

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         /*
56         sendString(clientHandler, "332 PASS password okay, need account.");
57         data.account = in.readLine();
58         if( data.account==null ||
59             !data.account.toUpperCase().startsWith("ACCT ") ){
60             sendString(clientHandler, "503 Bad sequence of command, ACCT required.");
61             return false;
62         }
63         */

64         
65         if(username.toLowerCase().equals("user anonymous")) {
66             //data.root = (String)clientHandler.getServer().getStoreObjects()[0];
67
HashMap appConfig =
68                 clientHandler.getServer().getConfig().getApplicationConfiguration();
69             String JavaDoc temp = null;
70             if(appConfig!=null)
71                 temp = (String JavaDoc)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