1
|
package edu.ucsb.nceas.metacat.harvesterClient;
|
2
|
|
3
|
import java.io.PrintWriter;
|
4
|
import javax.servlet.ServletException;
|
5
|
import javax.servlet.http.HttpServlet;
|
6
|
import javax.servlet.http.HttpServletRequest;
|
7
|
import javax.servlet.http.HttpServletResponse;
|
8
|
import javax.servlet.http.HttpSession;
|
9
|
import edu.ucsb.nceas.metacat.AuthSession;
|
10
|
|
11
|
|
12
|
/**
|
13
|
* HarvesterRegistrationLogin implements a servlet to login to the Harvester
|
14
|
* Registration servlet
|
15
|
*/
|
16
|
public class HarvesterRegistrationLogin extends HttpServlet {
|
17
|
|
18
|
/**
|
19
|
* Handle "GET" method requests from HTTP clients
|
20
|
*
|
21
|
* @param req The request
|
22
|
* @param res The response
|
23
|
* @throws ServletException, java.io.IOException
|
24
|
*/
|
25
|
public void doGet(HttpServletRequest req, HttpServletResponse res)
|
26
|
throws ServletException, java.io.IOException {
|
27
|
handleGetOrPost(req, res);
|
28
|
}
|
29
|
|
30
|
|
31
|
/**
|
32
|
* Handle "POST" method requests from HTTP clients
|
33
|
*
|
34
|
* @param req The request
|
35
|
* @param res The response
|
36
|
* @throws ServletException, java.io.IOException
|
37
|
*/
|
38
|
public void doPost(HttpServletRequest req, HttpServletResponse res)
|
39
|
throws ServletException, java.io.IOException {
|
40
|
handleGetOrPost(req, res);
|
41
|
}
|
42
|
|
43
|
|
44
|
/**
|
45
|
* Handle "GET" or "POST" method requests from HTTP clients
|
46
|
*
|
47
|
* @param req The request
|
48
|
* @param res The response
|
49
|
* @throws ServletException, java.io.IOException
|
50
|
*/
|
51
|
private void handleGetOrPost(HttpServletRequest req,
|
52
|
HttpServletResponse res)
|
53
|
throws ServletException, java.io.IOException {
|
54
|
AuthSession authSession;
|
55
|
String authSessionMessage;
|
56
|
HttpSession httpSession;
|
57
|
boolean isValid;
|
58
|
String passwd = req.getParameter("passwd");;
|
59
|
PrintWriter out = res.getWriter();
|
60
|
String user = req.getParameter("user");
|
61
|
|
62
|
res.setContentType("text/plain");
|
63
|
|
64
|
try {
|
65
|
authSession = new AuthSession();
|
66
|
isValid = authSession.authenticate(req, user, passwd);
|
67
|
authSessionMessage = authSession.getMessage();
|
68
|
System.out.println("authSession.authenticate(): "+authSessionMessage);
|
69
|
out.println("authSession.authenticate(): " + authSessionMessage);
|
70
|
|
71
|
if (isValid) {
|
72
|
httpSession = req.getSession(true);
|
73
|
httpSession.setAttribute("ldapDN", user);
|
74
|
httpSession.setAttribute("ldapPwd", passwd);
|
75
|
res.sendRedirect(
|
76
|
"edu.ucsb.nceas.metacat.harvesterClient.HarvesterRegistration");
|
77
|
}
|
78
|
else {
|
79
|
out.println("Invalid login");
|
80
|
}
|
81
|
}
|
82
|
catch (Exception e) {
|
83
|
System.out.println("Error in AuthSession()" + e.getMessage());
|
84
|
}
|
85
|
}
|
86
|
}
|