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 |
1949
|
costa
|
package edu.ucsb.nceas.metacat.harvesterClient;
|
26 |
|
|
|
27 |
1738
|
skrish
|
import java.io.PrintWriter;
|
28 |
|
|
import javax.servlet.ServletConfig;
|
29 |
|
|
import javax.servlet.ServletContext;
|
30 |
|
|
import javax.servlet.ServletException;
|
31 |
|
|
import javax.servlet.ServletInputStream;
|
32 |
|
|
import javax.servlet.http.HttpServlet;
|
33 |
|
|
import javax.servlet.http.HttpServletRequest;
|
34 |
|
|
import javax.servlet.http.HttpServletResponse;
|
35 |
|
|
import javax.servlet.http.HttpSession;
|
36 |
|
|
import javax.servlet.http.HttpUtils;
|
37 |
|
|
import javax.servlet.ServletOutputStream;
|
38 |
1830
|
skrish
|
import edu.ucsb.nceas.metacat.AuthSession;
|
39 |
|
|
|
40 |
1949
|
costa
|
/**
|
41 |
|
|
* LoginServlet implements a Harvester servlet to login to Metacat
|
42 |
|
|
*/
|
43 |
1738
|
skrish
|
public class LoginServlet extends HttpServlet {
|
44 |
|
|
|
45 |
2084
|
costa
|
public void destroy() {
|
46 |
|
|
// Close all connections
|
47 |
|
|
System.out.println("Destroying LoginServlet");
|
48 |
|
|
}
|
49 |
1738
|
skrish
|
|
50 |
2084
|
costa
|
/**
|
51 |
|
|
* Handle "GET" method requests from HTTP clients
|
52 |
|
|
*
|
53 |
|
|
* @param request The request
|
54 |
|
|
* @param response The response
|
55 |
|
|
* @throws ServletException, java.io.IOException
|
56 |
|
|
*/
|
57 |
|
|
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
58 |
|
|
throws ServletException, java.io.IOException {
|
59 |
|
|
// Process the data and send back the response
|
60 |
|
|
handleGetOrPost(request, response);
|
61 |
|
|
}
|
62 |
1738
|
skrish
|
|
63 |
2084
|
costa
|
/**
|
64 |
|
|
* Handle "POST" method requests from HTTP clients
|
65 |
|
|
*
|
66 |
|
|
* @param request The request
|
67 |
|
|
* @param response The response
|
68 |
|
|
* @throws ServletException, java.io.IOException
|
69 |
|
|
*/
|
70 |
|
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
71 |
|
|
throws ServletException, java.io.IOException {
|
72 |
|
|
// Process the data and send back the response
|
73 |
|
|
handleGetOrPost(request, response);
|
74 |
|
|
}
|
75 |
1738
|
skrish
|
|
76 |
2084
|
costa
|
/**
|
77 |
|
|
* Handle "GET" or "POST" method requests from HTTP clients
|
78 |
|
|
*
|
79 |
|
|
* @param request The request
|
80 |
|
|
* @param response The response
|
81 |
|
|
* @throws ServletException, java.io.IOException
|
82 |
|
|
*/
|
83 |
|
|
private void handleGetOrPost(HttpServletRequest request,
|
84 |
|
|
HttpServletResponse response)
|
85 |
|
|
throws ServletException, java.io.IOException {
|
86 |
|
|
AuthSession authSession = null;
|
87 |
|
|
HttpSession httpSession;
|
88 |
|
|
boolean isValid;
|
89 |
|
|
PrintWriter out = response.getWriter();
|
90 |
|
|
String passwd = request.getParameter("passwd");
|
91 |
|
|
String user = request.getParameter("user");
|
92 |
1738
|
skrish
|
|
93 |
2084
|
costa
|
response.setContentType("text/plain");
|
94 |
1738
|
skrish
|
|
95 |
2084
|
costa
|
try {
|
96 |
|
|
authSession = new AuthSession();
|
97 |
|
|
}
|
98 |
|
|
catch (Exception e) {
|
99 |
|
|
out.println("Error creating AuthSession: " + e.getMessage());
|
100 |
|
|
return;
|
101 |
|
|
}
|
102 |
1738
|
skrish
|
|
103 |
2084
|
costa
|
isValid = authSession.authenticate(request, user, passwd);
|
104 |
|
|
|
105 |
|
|
if (isValid) {
|
106 |
|
|
System.out.println(authSession.getMessage());
|
107 |
|
|
httpSession = request.getSession(true);
|
108 |
2171
|
costa
|
httpSession.setAttribute("username", user);
|
109 |
|
|
httpSession.setAttribute("password", passwd);
|
110 |
2084
|
costa
|
response.sendRedirect("../style/skins/dev/harvesterUpload.html");
|
111 |
1949
|
costa
|
}
|
112 |
2084
|
costa
|
else {
|
113 |
|
|
out.println("Error authenticating Metacat login: " +
|
114 |
|
|
authSession.getMessage());
|
115 |
|
|
}
|
116 |
|
|
}
|
117 |
1738
|
skrish
|
}
|