Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2004 University of New Mexico and the 
4
 *                  Regents of the University of California
5
 *
6
 *   '$Author: jones $'
7
 *     '$Date: 2004-04-01 16:41:58 -0800 (Thu, 01 Apr 2004) $'
8
 * '$Revision: 2094 $'
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
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
 *  Registration servlet
39
 */
40
public class HarvesterRegistrationLogin extends HttpServlet {
41

    
42
    /**
43
     *  Handle "GET" method requests from HTTP clients
44
     *
45
     *  @param  req   The request
46
     *  @param  res   The response
47
     *  @throws ServletException, java.io.IOException
48
     */
49
    public void doGet(HttpServletRequest req, HttpServletResponse res)
50
                throws ServletException, java.io.IOException {
51
        handleGetOrPost(req, res);
52
    }
53

    
54

    
55
    /**
56
     *  Handle "POST" method requests from HTTP clients
57
     *
58
     *  @param  req   The request
59
     *  @param  res  The response
60
     *  @throws ServletException, java.io.IOException
61
     */
62
    public void doPost(HttpServletRequest req, HttpServletResponse res)
63
                throws ServletException, java.io.IOException {
64
        handleGetOrPost(req, res);
65
    }
66

    
67

    
68
    /**
69
     *  Handle "GET" or "POST" method requests from HTTP clients
70
     *
71
     *  @param  req   The request
72
     *  @param  res  The response
73
     *  @throws ServletException, java.io.IOException
74
     */
75
    private void handleGetOrPost(HttpServletRequest req,
76
                                 HttpServletResponse res)
77
                 throws ServletException, java.io.IOException {
78
        AuthSession authSession;
79
        String authSessionMessage;
80
        HttpSession httpSession;
81
        boolean isValid;
82
        String passwd = req.getParameter("passwd");;
83
        PrintWriter out = res.getWriter();
84
        String user = req.getParameter("user");
85

    
86
        res.setContentType("text/plain");
87
        
88
        try {
89
          authSession = new AuthSession();
90
          isValid = authSession.authenticate(req, user, passwd);
91
          authSessionMessage = authSession.getMessage();
92
          System.out.println("authSession.authenticate(): "+authSessionMessage);
93
          out.println("authSession.authenticate(): " + authSessionMessage);
94

    
95
          if (isValid) {
96
            httpSession = req.getSession(true);
97
            httpSession.setAttribute("ldapDN", user);
98
            httpSession.setAttribute("ldapPwd", passwd);
99
            res.sendRedirect(
100
             "edu.ucsb.nceas.metacat.harvesterClient.HarvesterRegistration");
101
          }
102
          else {
103
            out.println("Invalid login");
104
          }
105
        } 
106
        catch (Exception e) {
107
          System.out.println("Error in AuthSession()" + e.getMessage());
108
        }
109
    }
110
}
(7-7/9)