1 |
1949
|
costa
|
package edu.ucsb.nceas.metacat.harvesterClient;
|
2 |
|
|
|
3 |
1738
|
skrish
|
import java.io.PrintWriter;
|
4 |
|
|
import javax.servlet.ServletConfig;
|
5 |
|
|
import javax.servlet.ServletContext;
|
6 |
|
|
import javax.servlet.ServletException;
|
7 |
|
|
import javax.servlet.ServletInputStream;
|
8 |
|
|
import javax.servlet.http.HttpServlet;
|
9 |
|
|
import javax.servlet.http.HttpServletRequest;
|
10 |
|
|
import javax.servlet.http.HttpServletResponse;
|
11 |
|
|
import javax.servlet.http.HttpSession;
|
12 |
|
|
import javax.servlet.http.HttpUtils;
|
13 |
|
|
import javax.servlet.ServletOutputStream;
|
14 |
1830
|
skrish
|
import edu.ucsb.nceas.metacat.AuthSession;
|
15 |
|
|
|
16 |
1949
|
costa
|
/**
|
17 |
|
|
* LoginServlet implements a Harvester servlet to login to Metacat
|
18 |
|
|
*/
|
19 |
1738
|
skrish
|
public class LoginServlet extends HttpServlet {
|
20 |
|
|
|
21 |
2084
|
costa
|
public void destroy() {
|
22 |
|
|
// Close all connections
|
23 |
|
|
System.out.println("Destroying LoginServlet");
|
24 |
|
|
}
|
25 |
1738
|
skrish
|
|
26 |
2084
|
costa
|
/**
|
27 |
|
|
* Handle "GET" method requests from HTTP clients
|
28 |
|
|
*
|
29 |
|
|
* @param request The request
|
30 |
|
|
* @param response The response
|
31 |
|
|
* @throws ServletException, java.io.IOException
|
32 |
|
|
*/
|
33 |
|
|
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
34 |
|
|
throws ServletException, java.io.IOException {
|
35 |
|
|
// Process the data and send back the response
|
36 |
|
|
handleGetOrPost(request, response);
|
37 |
|
|
}
|
38 |
1738
|
skrish
|
|
39 |
2084
|
costa
|
/**
|
40 |
|
|
* Handle "POST" method requests from HTTP clients
|
41 |
|
|
*
|
42 |
|
|
* @param request The request
|
43 |
|
|
* @param response The response
|
44 |
|
|
* @throws ServletException, java.io.IOException
|
45 |
|
|
*/
|
46 |
|
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
47 |
|
|
throws ServletException, java.io.IOException {
|
48 |
|
|
// Process the data and send back the response
|
49 |
|
|
handleGetOrPost(request, response);
|
50 |
|
|
}
|
51 |
1738
|
skrish
|
|
52 |
2084
|
costa
|
/**
|
53 |
|
|
* Handle "GET" or "POST" method requests from HTTP clients
|
54 |
|
|
*
|
55 |
|
|
* @param request The request
|
56 |
|
|
* @param response The response
|
57 |
|
|
* @throws ServletException, java.io.IOException
|
58 |
|
|
*/
|
59 |
|
|
private void handleGetOrPost(HttpServletRequest request,
|
60 |
|
|
HttpServletResponse response)
|
61 |
|
|
throws ServletException, java.io.IOException {
|
62 |
|
|
AuthSession authSession = null;
|
63 |
|
|
HttpSession httpSession;
|
64 |
|
|
boolean isValid;
|
65 |
|
|
PrintWriter out = response.getWriter();
|
66 |
|
|
String passwd = request.getParameter("passwd");
|
67 |
|
|
String user = request.getParameter("user");
|
68 |
1738
|
skrish
|
|
69 |
2084
|
costa
|
response.setContentType("text/plain");
|
70 |
1738
|
skrish
|
|
71 |
2084
|
costa
|
try {
|
72 |
|
|
authSession = new AuthSession();
|
73 |
|
|
}
|
74 |
|
|
catch (Exception e) {
|
75 |
|
|
out.println("Error creating AuthSession: " + e.getMessage());
|
76 |
|
|
return;
|
77 |
|
|
}
|
78 |
1738
|
skrish
|
|
79 |
2084
|
costa
|
isValid = authSession.authenticate(request, user, passwd);
|
80 |
|
|
|
81 |
|
|
if (isValid) {
|
82 |
|
|
System.out.println(authSession.getMessage());
|
83 |
|
|
httpSession = request.getSession(true);
|
84 |
|
|
httpSession.putValue("Musername", user);
|
85 |
|
|
httpSession.putValue("Mpassword", passwd);
|
86 |
|
|
response.sendRedirect("../style/skins/dev/harvesterUpload.html");
|
87 |
1949
|
costa
|
}
|
88 |
2084
|
costa
|
else {
|
89 |
|
|
out.println("Error authenticating Metacat login: " +
|
90 |
|
|
authSession.getMessage());
|
91 |
|
|
}
|
92 |
|
|
}
|
93 |
1738
|
skrish
|
}
|