1 |
2094
|
jones
|
/**
|
2 |
|
|
* '$RCSfile$'
|
3 |
|
|
* Copyright: 2004 University of New Mexico and the
|
4 |
|
|
* Regents of the University of California
|
5 |
|
|
*
|
6 |
|
|
* '$Author$'
|
7 |
|
|
* '$Date$'
|
8 |
|
|
* '$Revision$'
|
9 |
|
|
*
|
10 |
|
|
* This program is free software; you can redistribute it and/or modify
|
11 |
|
|
* it under the terms of the GNU General Public License as published by
|
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
13 |
|
|
* (at your option) any later version.
|
14 |
|
|
*
|
15 |
|
|
* This program is distributed in the hope that it will be useful,
|
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
* GNU General Public License for more details.
|
19 |
|
|
*
|
20 |
|
|
* You should have received a copy of the GNU General Public License
|
21 |
|
|
* along with this program; if not, write to the Free Software
|
22 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23 |
|
|
*/
|
24 |
|
|
|
25 |
2063
|
costa
|
package edu.ucsb.nceas.metacat.harvesterClient;
|
26 |
|
|
|
27 |
|
|
import java.io.PrintWriter;
|
28 |
|
|
import javax.servlet.ServletException;
|
29 |
|
|
import javax.servlet.http.HttpServlet;
|
30 |
|
|
import javax.servlet.http.HttpServletRequest;
|
31 |
|
|
import javax.servlet.http.HttpServletResponse;
|
32 |
|
|
import javax.servlet.http.HttpSession;
|
33 |
|
|
import edu.ucsb.nceas.metacat.AuthSession;
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
/**
|
37 |
|
|
* HarvesterRegistrationLogin implements a servlet to login to the Harvester
|
38 |
2367
|
costa
|
* Registration servlet.
|
39 |
2063
|
costa
|
*/
|
40 |
|
|
public class HarvesterRegistrationLogin extends HttpServlet {
|
41 |
|
|
|
42 |
2166
|
costa
|
final String LDAP_DOMAIN = ",dc=ecoinformatics,dc=org";
|
43 |
|
|
|
44 |
2063
|
costa
|
/**
|
45 |
|
|
* Handle "GET" method requests from HTTP clients
|
46 |
|
|
*
|
47 |
|
|
* @param req The request
|
48 |
|
|
* @param res The response
|
49 |
|
|
* @throws ServletException, java.io.IOException
|
50 |
|
|
*/
|
51 |
|
|
public void doGet(HttpServletRequest req, HttpServletResponse res)
|
52 |
|
|
throws ServletException, java.io.IOException {
|
53 |
|
|
handleGetOrPost(req, res);
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
/**
|
58 |
|
|
* Handle "POST" method requests from HTTP clients
|
59 |
|
|
*
|
60 |
|
|
* @param req The request
|
61 |
|
|
* @param res The response
|
62 |
|
|
* @throws ServletException, java.io.IOException
|
63 |
|
|
*/
|
64 |
|
|
public void doPost(HttpServletRequest req, HttpServletResponse res)
|
65 |
|
|
throws ServletException, java.io.IOException {
|
66 |
|
|
handleGetOrPost(req, res);
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
/**
|
71 |
|
|
* Handle "GET" or "POST" method requests from HTTP clients
|
72 |
|
|
*
|
73 |
|
|
* @param req The request
|
74 |
|
|
* @param res The response
|
75 |
|
|
* @throws ServletException, java.io.IOException
|
76 |
|
|
*/
|
77 |
|
|
private void handleGetOrPost(HttpServletRequest req,
|
78 |
|
|
HttpServletResponse res)
|
79 |
|
|
throws ServletException, java.io.IOException {
|
80 |
|
|
AuthSession authSession;
|
81 |
|
|
String authSessionMessage;
|
82 |
|
|
HttpSession httpSession;
|
83 |
|
|
boolean isValid;
|
84 |
2166
|
costa
|
String o = req.getParameter("o");
|
85 |
|
|
String organization;
|
86 |
|
|
String passwd = req.getParameter("passwd");
|
87 |
2063
|
costa
|
PrintWriter out = res.getWriter();
|
88 |
2166
|
costa
|
String uid = req.getParameter("uid");
|
89 |
|
|
String user;
|
90 |
2063
|
costa
|
|
91 |
2166
|
costa
|
if ((uid == null) || (uid.equals(""))) {
|
92 |
|
|
out.println("Invalid login: no Username specified.");
|
93 |
|
|
return;
|
94 |
|
|
}
|
95 |
|
|
else if ((o == null) || (o.equals(""))) {
|
96 |
|
|
out.println("Invalid login: no Organization selected.");
|
97 |
|
|
return;
|
98 |
|
|
}
|
99 |
|
|
else if ((passwd == null) || (passwd.equals(""))) {
|
100 |
|
|
out.println("Invalid login: no Password specified.");
|
101 |
|
|
return;
|
102 |
|
|
}
|
103 |
|
|
else {
|
104 |
|
|
user = "uid=" + uid + ",o=" + o + LDAP_DOMAIN;
|
105 |
|
|
}
|
106 |
|
|
|
107 |
2063
|
costa
|
res.setContentType("text/plain");
|
108 |
|
|
|
109 |
|
|
try {
|
110 |
|
|
authSession = new AuthSession();
|
111 |
|
|
isValid = authSession.authenticate(req, user, passwd);
|
112 |
|
|
authSessionMessage = authSession.getMessage();
|
113 |
|
|
System.out.println("authSession.authenticate(): "+authSessionMessage);
|
114 |
|
|
out.println("authSession.authenticate(): " + authSessionMessage);
|
115 |
|
|
|
116 |
|
|
if (isValid) {
|
117 |
|
|
httpSession = req.getSession(true);
|
118 |
2171
|
costa
|
httpSession.setAttribute("username", user);
|
119 |
|
|
httpSession.setAttribute("password", passwd);
|
120 |
2332
|
costa
|
res.sendRedirect("harvesterRegistration");
|
121 |
2063
|
costa
|
}
|
122 |
|
|
else {
|
123 |
|
|
out.println("Invalid login");
|
124 |
|
|
}
|
125 |
|
|
}
|
126 |
|
|
catch (Exception e) {
|
127 |
|
|
System.out.println("Error in AuthSession()" + e.getMessage());
|
128 |
|
|
}
|
129 |
|
|
}
|
130 |
|
|
}
|