Revision 1949
Added by Duane Costa over 20 years ago
LoginServlet.java | ||
---|---|---|
1 |
package edu.ucsb.nceas.metacat.harvesterClient; |
|
2 |
|
|
1 | 3 |
import java.io.PrintWriter; |
2 |
|
|
3 |
|
|
4 | 4 |
import javax.servlet.ServletConfig; |
5 | 5 |
import javax.servlet.ServletContext; |
6 | 6 |
import javax.servlet.ServletException; |
... | ... | |
11 | 11 |
import javax.servlet.http.HttpSession; |
12 | 12 |
import javax.servlet.http.HttpUtils; |
13 | 13 |
import javax.servlet.ServletOutputStream; |
14 |
|
|
15 | 14 |
import edu.ucsb.nceas.metacat.AuthSession; |
16 | 15 |
|
16 |
/** |
|
17 |
* LoginServlet implements a Harvester servlet to login to Metacat |
|
18 |
*/ |
|
17 | 19 |
public class LoginServlet extends HttpServlet { |
18 | 20 |
|
21 |
public void destroy() { |
|
22 |
// Close all connections |
|
23 |
System.out.println("Destroying LoginServlet"); |
|
24 |
} |
|
19 | 25 |
|
20 |
public void destroy() { |
|
21 |
// Close all connections |
|
22 |
System.out.println("Destroying LoginServlet"); |
|
23 |
} |
|
26 |
/** |
|
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 |
} |
|
24 | 38 |
|
25 |
/** Handle "GET" method requests from HTTP clients */ |
|
26 |
public void doGet (HttpServletRequest request, HttpServletResponse response) |
|
27 |
throws ServletException,java.io.IOException{ |
|
39 |
/** |
|
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 |
} |
|
28 | 51 |
|
29 |
// Process the data and send back the response |
|
30 |
handleGetOrPost(request, response); |
|
31 |
} |
|
32 |
|
|
52 |
/** |
|
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 |
String user = "skr"; |
|
63 |
// String group = "skr"; |
|
64 |
String passwd = "skr"; |
|
65 |
AuthSession sess = null; |
|
66 |
boolean isValid; |
|
67 |
PrintWriter out1; |
|
33 | 68 |
|
34 |
/** Handle "POST" method requests from HTTP clients */
|
|
35 |
public void doPost( HttpServletRequest request, HttpServletResponse response)
|
|
36 |
throws ServletException,java.io.IOException{
|
|
69 |
user = request.getParameter("user");
|
|
70 |
// group = request.getParameter("group");
|
|
71 |
passwd = request.getParameter("passwd");
|
|
37 | 72 |
|
38 |
// Process the data and send back the response |
|
39 |
handleGetOrPost(request, response); |
|
40 |
} |
|
73 |
try { |
|
74 |
sess = new AuthSession(); |
|
75 |
} catch (Exception e) { |
|
76 |
System.out.println( |
|
77 |
"Error in LoginServlet.handleGetOrPost AuthSession" + |
|
78 |
e.getMessage()); |
|
79 |
return; |
|
80 |
} |
|
41 | 81 |
|
42 |
private void handleGetOrPost(HttpServletRequest request,
|
|
43 |
HttpServletResponse response)
|
|
44 |
throws ServletException,java.io.IOException
|
|
45 |
{
|
|
82 |
isValid = sess.authenticate(request, user, passwd);
|
|
83 |
out1 = response.getWriter();
|
|
84 |
System.out.println("Sess.authenticate " + sess.getMessage());
|
|
85 |
out1.println("Sess.authenticate " + sess.getMessage());
|
|
46 | 86 |
|
47 |
String user="skr"; |
|
48 |
// String group="skr"; |
|
49 |
String passwd="skr"; |
|
50 |
AuthSession sess =null; |
|
87 |
/*****************************************************/ |
|
88 |
HttpSession sess1 = request.getSession(true); |
|
51 | 89 |
|
52 |
user = request.getParameter("user"); |
|
53 |
// group = request.getParameter("group"); |
|
54 |
passwd = request.getParameter("passwd"); |
|
55 |
|
|
56 |
try{ |
|
57 |
sess = new AuthSession(); |
|
58 |
} catch (Exception e) { |
|
59 |
System.out.println("Error in LoginServlet.handleGetorPost Authsession" + |
|
60 |
e.getMessage()); |
|
61 |
return; |
|
62 |
} |
|
90 |
// if (sess.isNew()) { |
|
91 |
sess1.putValue("Musername", user); |
|
92 |
sess1.putValue("Mpassword", passwd); |
|
93 |
// sess.putValue("groupnames", group); |
|
94 |
// } |
|
63 | 95 |
|
96 |
// PrintWriter out = response.getWriter(); |
|
97 |
// out.println(sess.getValue("username")); |
|
98 |
/*****************************************************/ |
|
64 | 99 |
|
65 |
boolean isValid = sess.authenticate(request, user,passwd); |
|
66 |
PrintWriter out1 = response.getWriter(); |
|
67 |
System.out.println("Sess.authenticate "+sess.getMessage()); |
|
68 |
out1.println("Sess.authenticate "+sess.getMessage()); |
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
/*****************************************************/ |
|
73 |
HttpSession sess1 = request.getSession(true); |
|
74 |
|
|
75 |
/*if (sess.isNew()) {*/ |
|
76 |
sess1.putValue("Musername",user); |
|
77 |
sess1.putValue("Mpassword",passwd); |
|
78 |
// sess.putValue("groupnames", group); |
|
79 |
|
|
80 |
//} |
|
81 |
|
|
82 |
|
|
83 |
// PrintWriter out = response.getWriter(); |
|
84 |
// out.println(sess.getValue("username")); |
|
85 |
/*****************************************************/ |
|
86 |
response.sendRedirect("../uploademl.html"); |
|
87 |
|
|
88 |
|
|
89 |
|
|
100 |
response.sendRedirect("../harvesterUpload.html"); |
|
101 |
} |
|
90 | 102 |
} |
91 |
} |
Also available in: Unified diff
Improvements to Harvester single file upload servlets