01: /*
02: * This file is part of the QuickServer library
03: * Copyright (C) 2003-2005 QuickServer.org
04: *
05: * Use, modification, copying and distribution of this software is subject to
06: * the terms and conditions of the GNU Lesser General Public License.
07: * You should have received a copy of the GNU LGP License along with this
08: * library; if not, you can download a copy from <http://www.quickserver.org/>.
09: *
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 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,
36: "503 Bad sequence of command, USER required.");
37: return false;
38: } else {
39: sendString(clientHandler,
40: "331 User name okay, need password.");
41: }
42:
43: String password = askStringInput(clientHandler, null);//PASS <PASSWORD>
44: //no need to check for null : done by QuickAuthenticator
45:
46: if (password.equalsIgnoreCase("QUIT")) {
47: sendString(clientHandler, "221 Logged out.");
48: throw new AppException("Quit");
49: }
50: if (password.toUpperCase().startsWith("PASS ") == false) {
51: sendString(clientHandler,
52: "503 Bad sequence of command, PASS required.");
53: return false;
54: }
55:
56: Data data = (Data) clientHandler.getClientData();
57: data.username = username;
58: /*
59: sendString(clientHandler, "332 PASS password okay, need account.");
60: data.account = in.readLine();
61: if( data.account==null ||
62: !data.account.toUpperCase().startsWith("ACCT ") ){
63: sendString(clientHandler, "503 Bad sequence of command, ACCT required.");
64: return false;
65: }
66: */
67:
68: if (username.toLowerCase().equals("user anonymous")) {
69: //data.root = (String)clientHandler.getServer().getStoreObjects()[0];
70: HashMap appConfig = clientHandler.getServer().getConfig()
71: .getApplicationConfiguration();
72: String temp = null;
73: if (appConfig != null)
74: temp = (String) appConfig.get("FTP_ROOT");
75: else
76: temp = System.getProperty("user.home");
77: data.root = temp;
78: sendString(clientHandler, "230 User logged in, proceed.");
79: return true;
80: } else {
81: sendString(clientHandler, "530 Not logged in.");
82: return false;
83: }
84: }
85: }
|